estiedi
August 7th, 2010, 07:44 PM
Hi,
I'm working on a program using Quickly, Python & Glade.
I made a Master/Detail window:
The master part is a TreeView with a list of persons (ID, firstname, name).
The detail part a frame with several widgets (mostly entry, combobox).
When the user selects a person in the master list, I display the persons details in the details frame to view and/or edit.
In the details frame I have a combo box with zip codes.
I need to set the zip code of the selected person programmatically, but couldn't find a function in gtk.ComboBox or gtk.TreeModel that lets me do this easily.
My solution is to keep a separate list of zip codes through which I loop to find the index of the zip code I need and then use the combobox's set_active(index) function.
This is the treeview event handler when the user selects another person:
def on_treeview1_cursor_changed(self, widget):
model, it, = widget.get_selection().get_selected()
val = model.get_value(it, 0)
self.show_member_detail(val)
The function that fills the detail frame with the selected person's details:
def show_member_detail(self, member_nr):
mbr = get_store().find(Member, Member.member_nr == member_nr).one()
self.builder.get_object('entry_firstname').set_tex t(mbr.firstname)
self.builder.get_object('entry_name').set_text(mbr .name)
combo_pc = self.builder.get_object('combobox_zipcode')
combo_pc.set_active(get_zipcode_index(mbr.place.zi pcode))
self.builder.get_object('entry_address').set_text( mbr.address)
self.builder.get_object('entry_email').set_text(li d.email)
self.builder.get_object('entry_tel1').set_text(lid .tel1)
self.builder.get_object('entry_tel2').set_text(lid .tel2)
This is the function that tries to find the index of the zip code
def get_zipcode_index(zipcode):
places = get_store().find(Places)
for zc in places:
idx = idx + 1
if zc.zipcode == zipcode
return idx
Is there any better way to do this? I could not find any hint on Google about this, so maybe I heading in the complete wrong direction.
Thx.
I'm working on a program using Quickly, Python & Glade.
I made a Master/Detail window:
The master part is a TreeView with a list of persons (ID, firstname, name).
The detail part a frame with several widgets (mostly entry, combobox).
When the user selects a person in the master list, I display the persons details in the details frame to view and/or edit.
In the details frame I have a combo box with zip codes.
I need to set the zip code of the selected person programmatically, but couldn't find a function in gtk.ComboBox or gtk.TreeModel that lets me do this easily.
My solution is to keep a separate list of zip codes through which I loop to find the index of the zip code I need and then use the combobox's set_active(index) function.
This is the treeview event handler when the user selects another person:
def on_treeview1_cursor_changed(self, widget):
model, it, = widget.get_selection().get_selected()
val = model.get_value(it, 0)
self.show_member_detail(val)
The function that fills the detail frame with the selected person's details:
def show_member_detail(self, member_nr):
mbr = get_store().find(Member, Member.member_nr == member_nr).one()
self.builder.get_object('entry_firstname').set_tex t(mbr.firstname)
self.builder.get_object('entry_name').set_text(mbr .name)
combo_pc = self.builder.get_object('combobox_zipcode')
combo_pc.set_active(get_zipcode_index(mbr.place.zi pcode))
self.builder.get_object('entry_address').set_text( mbr.address)
self.builder.get_object('entry_email').set_text(li d.email)
self.builder.get_object('entry_tel1').set_text(lid .tel1)
self.builder.get_object('entry_tel2').set_text(lid .tel2)
This is the function that tries to find the index of the zip code
def get_zipcode_index(zipcode):
places = get_store().find(Places)
for zc in places:
idx = idx + 1
if zc.zipcode == zipcode
return idx
Is there any better way to do this? I could not find any hint on Google about this, so maybe I heading in the complete wrong direction.
Thx.