I'm having a problem with a ComboBoxEntry
and the function that populates it.
This is the __init__
code on the GUI.
self.combobox_category = self.builder.get_object("combobox_category")
self.combobox_category.set_entry_text_column(1)
INIT_COMBOBOX_category(self)
And this is the function that populates the ComboBoxEntry
.
def INIT_COMBOBOX_category(self):
self.list_category = Gtk.ListStore(int,str)
self.list_category.clear()
self.list_category.append([0,"< List all the categories >"])
self.list_category.append([1,"No specified"])
#...No relevant code...
self.combobox_category.set_model(self.list_category)
self.cell = Gtk.CellRendererText()
self.combobox_category.pack_start(self.cell, True)
self.combobox_category.add_attribute(self.cell, 'text', 1)
self.combobox_category.set_active(1)
The problem is that when I start the GUI, the combobox_category
has "duplicated values"
(only when selecting values, not in the ComboBoxEntry
):
< List all the categories > < List all the categories >
No specified No specified
And then, when I need to use the function INIT_COMBOBOX_category(self)
again the values are tripled, etc.
I think that
self.list_category.clear()
is not working.
It is also strange that in Glade, I selected the ComboBoxEntry
as "editable" and I cannot write on it. I also tried as "Overwrite Mode" and it's still not working!
I found a solution, It consists in making the ComboBoxEntry in python instead of glade, in the init function the ComboBoxEntry is created, and in the INIT_COMBOBOX_category the ListStore is modified.
the init code is the folowing:
self.list_category=Gtk.ListStore(int,str)
self.category_combo=Gtk.ComboBox.new_with_model_and_entry(self.list_category)
self.category_combo.show()
self.box_category_to_install.add(self.category_combo)
self.category_combo.set_entry_text_column(1)
INIT_COMBOBOX_category(self)
( i added a box in glade, called box_category_to_install to place the ComboBoxEntry )
and
def INIT_COMBOBOX_category(self):
self.list_category.clear()
self.list_category.append([0,"< List all the categories >"])
self.list_category.append([1,"No specified"])
etc...