I'm using PyGtk to display some string information in a treeview.
Here goes my code:
def create_table(self):
self.mainbox = gtk.ScrolledWindow()
self.mainbox.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.window.add( self.mainbox)
model = gtk.ListStore( str, str, str)
self.treeview = gtk.TreeView(model=None)
col = gtk.TreeViewColumn( "Element")
self.treeview.append_column( col)
cell = gtk.CellRendererText()
col.pack_start( cell, expand=False)
col.set_attributes( cell, text=0)
col = gtk.TreeViewColumn( "Test")
self.treeview.append_column( col)
cell = gtk.CellRendererSpin()
col.pack_start( cell, expand=False)
col.set_attributes( cell, text=1)
col = gtk.TreeViewColumn( "Command")
self.treeview.append_column( col)
cell = gtk.CellRendererSpin()
col.pack_start( cell, expand=False)
col.set_attributes( cell, text=0)
cell = gtk.CellRendererCombo()
self.mainbox.add( self.treeview)
self.mainbox.set_size_request( 500, 260)
self.mainbox.show()
self.vbox.pack_start(self.mainbox, expand=False, fill=True, padding=0)
Then, I created a method to fill the treeview after an event button. The call:
def populate_treeview_button(self):
button = gtk.Button(label='Populate Table')
button.connect("clicked", self.create_model)
self.vbox.pack_start(button, expand=False, fill=True, padding=0)
And the method (I receive a list of dicts at table_information attribute where the key is an element(string) and the value a list with 2 strings):
def create_model(self, beats_me_param):
model = gtk.ListStore( str, str, str)
elements = []
tests = []
commands = []
table_information = self.get_organized_table()
for i in table_information:
for dicts in i:
for element in dicts.keys():
elements.append(element)
for i in table_information:
for dicts in i:
for value in dicts.values():
tests.append(value[0])
commands.append(value[1])
for i in range(len(elements)):
model.append([elements[i], tests[i], commands[i]])
self.treeview.set_model(model)
When I saw the result at my treeview, I got at third column the same value of the first column and of course they are different. Image bellow:
I changed the order of elements in the "append" moment and same occurs, the value changes but the changed value is repeated at the third column. What's going wrong?