How to delete PyGTK ComboBox entries?

Osmo Salomaa otsaloma at cc.hut.fi
Mon Feb 26 10:33:20 EST 2007


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.

-- 
Osmo Salomaa




More information about the Python-list mailing list