Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

How to delete PyGTK ComboBox entries?


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,

Mal

ma, 2007-02-26 kello 16:08 +0100, Mal 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

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!
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc