How to delete PyGTK ComboBox entries?

  • Thread starter =?ISO-8859-15?Q?Ma=EBl_Benjamin_Mettler?=
  • Start date
?

=?ISO-8859-15?Q?Ma=EBl_Benjamin_Mettler?=

Hello list!

I need to repopulate PyGTK ComboBox on a regular basis. In order to do
so I have to remove all the entries and then add the new ones. I tried
to remove all entries like that:

def clear_comboboxes(boxreference):
try:
while True:
boxreference.remove_text(0)
except:
pass

And then repopulate by iterating through the list of desired entries and
calling ComboBox.append_text(text). It works, but is painfully
sloooooooow! Is there a faster way to completely change the entries in a
ComboBox, by using an all erase method or overwriting the container
object? I haven't found anything with google, as the searches are too
ambiguous to yield usable results.

Thanks,

Maël
 
O

Osmo Salomaa

ma, 2007-02-26 kello 16:08 +0100, Maël Benjamin Mettler kirjoitti:
I need to repopulate PyGTK ComboBox on a regular basis. In order to do
so I have to remove all the entries and then add the new ones.
And then repopulate by iterating through the list of desired entries and
calling ComboBox.append_text(text). It works, but is painfully
sloooooooow!

model = combo_box.get_model()
combo_box.set_model(None)
model.clear()
for entry in desired_entries:
model.append([entry])
combo_box.set_model(model)

model.append is essentially the same as combo_box.append_text. Setting
the model to None before making changes to it speeds things at least in
the case of tree views. I'm not sure if it does much with combo boxes.
If you experince speed issues with combo boxes you're either doing
something very wrong or you have so many entries that you ought to be
using a tree view instead.
 
G

Guest

Hej!
model = combo_box.get_model()
combo_box.set_model(None)
model.clear()
for entry in desired_entries:
model.append([entry])
combo_box.set_model(model)

model.append is essentially the same as combo_box.append_text. Setting
the model to None before making changes to it speeds things at least in
the case of tree views. I'm not sure if it does much with combo boxes.
If you experince speed issues with combo boxes you're either doing
something very wrong or you have so many entries that you ought to be
using a tree view instead.

Works like a charm. Thanks a lot!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,096
Members
48,773
Latest member
Kaybee

Latest Threads

Top