Populating ComboBox

Hello users,

I am writing a GUI with XRCed and it includes a ComboBox. I do not want to populate the ComboBox in XRCed but in my code. However, it seems that I can only do this during creation of the combobox. Is there a way to populate the combobox (or change the items in it) after it has been created. I do not find any method for this. Please help.

Rgrds, Frans

···

Get news, entertainment and everything you care about at Live.com. Check it out!

Frans,

Hello users,
I am writing a GUI with XRCed and it includes a ComboBox. I do not want to populate the ComboBox in XRCed but in my code. However, it seems that I can only do this during creation of the combobox. Is there a way to populate the combobox (or change the items in it) after it has been created. I do not find any method for this. Please help.
Rgrds, Frans

You can use SetItems() to populate it or change it. That works quite well for me.

Mike

Frans,

Mike's suggestion is the way to go. But how did he know of this method?
The trickis, when you think there should be a method but don't find it
listed under
the methods, try to *look at the methods of the class the widget is
derived from*.
So in the case of ComboBox, if you go the wxPython API page for that widget:

http://wxpython.org/docs/api/wx.ComboBox-class.html

You *don't* find .SetItems(). But that's when you should look and see on that
page a little family tree of the ComboBox widget, and see it is derived from a
class called ItemContainer. If you click on that, here:

http://wxpython.org/docs/api/wx.ItemContainer-class.html

You see it has methods which apply to ComboBox as well as a "sibling" class
called ControlWithItems (such as a Listbox of Choice widget). So, in
this ItemContainer
set of methods, you find sort of "more general" methods that apply to
anything with
a list of items; scrolling down the list you find SetItems(). Hooray.
(Of course, always
look for "Set" methods when you want to change something in the widget).

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don't find (or at least I
can't find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the wxWidgets
webpage easier to read somehow)

I just taught and so am in a pedagogical mood, but I hope this was
helpful to just
have somewhere, since it is a point that was very frustrating for me
until I began to
catch on that this is where to find "obvious" methods that weren't
found listed under
a widget's methods.

Che

···

On Wed, Nov 5, 2008 at 11:24 AM, Mike Driscoll <mike@pythonlibrary.org> wrote:

Frans,

Hello users,
I am writing a GUI with XRCed and it includes a ComboBox. I do not want
to populate the ComboBox in XRCed but in my code. However, it seems that I
can only do this during creation of the combobox. Is there a way to populate
the combobox (or change the items in it) after it has been created. I do not
find any method for this. Please help.
Rgrds, Frans

You can use SetItems() to populate it or change it. That works quite well
for me.

Mike

(my apologies for awful line formatting above... I'm using Gmail
and not sure why that is happening)

Che

···

On Wed, Nov 5, 2008 at 2:22 PM, C M <cmpython@gmail.com> wrote:

On Wed, Nov 5, 2008 at 11:24 AM, Mike Driscoll <mike@pythonlibrary.org> wrote:

Frans,

Hello users,
I am writing a GUI with XRCed and it includes a ComboBox. I do not want
to populate the ComboBox in XRCed but in my code. However, it seems that I
can only do this during creation of the combobox. Is there a way to populate
the combobox (or change the items in it) after it has been created. I do not
find any method for this. Please help.
Rgrds, Frans

You can use SetItems() to populate it or change it. That works quite well
for me.

Mike

Frans,

Mike's suggestion is the way to go. But how did he know of this method?
The trickis, when you think there should be a method but don't find it
listed under
the methods, try to *look at the methods of the class the widget is
derived from*.
So in the case of ComboBox, if you go the wxPython API page for that widget:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You *don't* find .SetItems(). But that's when you should look and see on that
page a little family tree of the ComboBox widget, and see it is derived from a
class called ItemContainer. If you click on that, here:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You see it has methods which apply to ComboBox as well as a "sibling" class
called ControlWithItems (such as a Listbox of Choice widget). So, in
this ItemContainer
set of methods, you find sort of "more general" methods that apply to
anything with
a list of items; scrolling down the list you find SetItems(). Hooray.
(Of course, always
look for "Set" methods when you want to change something in the widget).

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don't find (or at least I
can't find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the wxWidgets
webpage easier to read somehow)

I just taught and so am in a pedagogical mood, but I hope this was
helpful to just
have somewhere, since it is a point that was very frustrating for me
until I began to
catch on that this is where to find "obvious" methods that weren't
found listed under
a widget's methods.

Che

C M wrote:

  

Frans,

Hello users,
I am writing a GUI with XRCed and it includes a ComboBox. I do not want
to populate the ComboBox in XRCed but in my code. However, it seems that I
can only do this during creation of the combobox. Is there a way to populate
the combobox (or change the items in it) after it has been created. I do not
find any method for this. Please help.
Rgrds, Frans
      

You can use SetItems() to populate it or change it. That works quite well
for me.

Mike
    
Frans,

Mike's suggestion is the way to go. But how did he know of this method?
The trickis, when you think there should be a method but don't find it
listed under
the methods, try to *look at the methods of the class the widget is
derived from*.
So in the case of ComboBox, if you go the wxPython API page for that widget:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You *don't* find .SetItems(). But that's when you should look and see on that
page a little family tree of the ComboBox widget, and see it is derived from a
class called ItemContainer. If you click on that, here:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You see it has methods which apply to ComboBox as well as a "sibling" class
called ControlWithItems (such as a Listbox of Choice widget). So, in
this ItemContainer
set of methods, you find sort of "more general" methods that apply to
anything with
a list of items; scrolling down the list you find SetItems(). Hooray.
(Of course, always
look for "Set" methods when you want to change something in the widget).

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don't find (or at least I
can't find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the wxWidgets
webpage easier to read somehow)

I just taught and so am in a pedagogical mood, but I hope this was
helpful to just
have somewhere, since it is a point that was very frustrating for me
until I began to
catch on that this is where to find "obvious" methods that weren't
found listed under
a widget's methods.

Che

Another way to find the methods is to use Python's builtin introspection tool:s. I use dir and help in the python shell quite a bit. Here's what you'll get if you use them on ComboBox:

>>> import wx
>>> dir(wx.ComboBox)
# This will print a long list of methods and/or attributes
# cut for brevity
...
>>> help(wx.ComboBox.SetItems)
Help on method SetItems in module wx._core:

SetItems(self, items) unbound wx._controls.ComboBox method
    Clear and set the strings in the control from a list

I apologize for not mentioning how I found that. It was recently added (I think) and I only learned about it by reading the archives. But Che is correct; you can find it in the way he described.

···

On Wed, Nov 5, 2008 at 11:24 AM, Mike Driscoll <mike@pythonlibrary.org> wrote:

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Hi Mike,

Yes, this works. Thanks.

The reason I didn’t find it is because it’s not in the manual which I am using (wxWidgets 2.8.8: A portable C++ and Python GUI toolkit).

Is there a newer version somewhere?

Frans

···

Date: Wed, 5 Nov 2008 10:24:00 -0600
From: mike@pythonlibrary.org
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Populating ComboBox

Frans,

Hello users,

I am writing a GUI with XRCed and it includes a ComboBox. I do not
want to populate the ComboBox in XRCed but in my code. However, it
seems that I can only do this during creation of the combobox. Is
there a way to populate the combobox (or change the items in it) after
it has been created. I do not find any method for this. Please help.

Rgrds, Frans

You can use SetItems() to populate it or change it. That works quite
well for me.

Mike


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Connect to the next generation of MSN Messenger Get it now!

Hi Che,

Thanks! This was VERY helpful.

Frans

···

Date: Wed, 5 Nov 2008 14:22:12 -0500
From: cmpython@gmail.com
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Populating ComboBox

On Wed, Nov 5, 2008 at 11:24 AM, Mike Driscoll mike@pythonlibrary.org wrote:

Frans,

Hello users,
I am writing a GUI with XRCed and it includes a ComboBox. I do not want
to populate the ComboBox in XRCed but in my code. However, it seems that I
can only do this during creation of the combobox. Is there a way to populate
the combobox (or change the items in it) after it has been created. I do not
find any method for this. Please help.
Rgrds, Frans

You can use SetItems() to populate it or change it. That works quite well
for me.

Mike

Frans,

Mike’s suggestion is the way to go. But how did he know of this method?
The trickis, when you think there should be a method but don’t find it
listed under
the methods, try to look at the methods of the class the widget is
derived from
.
So in the case of ComboBox, if you go the wxPython API page for that widget:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You don’t find .SetItems(). But that’s when you should look and see on that
page a little family tree of the ComboBox widget, and see it is derived from a
class called ItemContainer. If you click on that, here:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You see it has methods which apply to ComboBox as well as a “sibling” class
called ControlWithItems (such as a Listbox of Choice widget). So, in
this ItemContainer
set of methods, you find sort of “more general” methods that apply to
anything with
a list of items; scrolling down the list you find SetItems(). Hooray.
(Of course, always
look for “Set” methods when you want to change something in the widget).

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don’t find (or at least I
can’t find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the wxWidgets
webpage easier to read somehow)

I just taught and so am in a pedagogical mood, but I hope this was
helpful to just
have somewhere, since it is a point that was very frustrating for me
until I began to
catch on that this is where to find “obvious” methods that weren’t
found listed under
a widget’s methods.

Che


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


Discover the new Windows Vista Learn more!

That's because SetItems and GetItems were implemented as part of the Items property in wxPython as a convenient way to populate the ComboBox.

If you look at the source wxPython/wx/_core.py, you can see that SetItems was implemented using the Clear and Append methods.

-Selim

C M wrote:

···

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don't find (or at least I
can't find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the wxWidgets
webpage easier to read somehow)

That's because SetItems and GetItems were implemented as part of the Items
property in wxPython as a convenient way to populate the ComboBox.

If you look at the source wxPython/wx/_core.py, you can see that SetItems
was implemented using the Clear and Append methods.

-Selim

Thank you, Selim. Actually, now that you mention this,
I seem to recall a discussion about this maybe last
year, and, yes, prior to that one had to Clear the
items first, then use Append in a loop to add them again.
Thanks for clearing this up/refreshing my memory!

Che

···

On Wed, Nov 5, 2008 at 2:40 PM, Selim Tuvi <Selim.Tuvi@pdi.dreamworks.com> wrote:

C M wrote:

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don't find (or at least I
can't find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the
wxWidgets
webpage easier to read somehow)

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Che,

Thanks! This was VERY helpful.

Frans

You're very welcome, and I'm glad it
was helpful!

Does anyone know whether all the various
points discussed here are found in one
place somewhere on the wiki? I think it
would be a great addition helping people
orient to what methods are available to them.

Che

···

On Wed, Nov 5, 2008 at 2:40 PM, Frans Stronkman <frans.stronkman@hotmail.com> wrote:

Date: Wed, 5 Nov 2008 14:22:12 -0500
From: cmpython@gmail.com
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Populating ComboBox

On Wed, Nov 5, 2008 at 11:24 AM, Mike Driscoll <mike@pythonlibrary.org> >> wrote:
> Frans,
>
>> Hello users,
>> I am writing a GUI with XRCed and it includes a ComboBox. I do not want
>> to populate the ComboBox in XRCed but in my code. However, it seems
>> that I
>> can only do this during creation of the combobox. Is there a way to
>> populate
>> the combobox (or change the items in it) after it has been created. I
>> do not
>> find any method for this. Please help.
>> Rgrds, Frans
>
> You can use SetItems() to populate it or change it. That works quite
> well
> for me.
>
> Mike

Frans,

Mike's suggestion is the way to go. But how did he know of this method?
The trickis, when you think there should be a method but don't find it
listed under
the methods, try to *look at the methods of the class the widget is
derived from*.
So in the case of ComboBox, if you go the wxPython API page for that
widget:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You *don't* find .SetItems(). But that's when you should look and see on
that
page a little family tree of the ComboBox widget, and see it is derived
from a
class called ItemContainer. If you click on that, here:

wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

You see it has methods which apply to ComboBox as well as a "sibling"
class
called ControlWithItems (such as a Listbox of Choice widget). So, in
this ItemContainer
set of methods, you find sort of "more general" methods that apply to
anything with
a list of items; scrolling down the list you find SetItems(). Hooray.
(Of course, always
look for "Set" methods when you want to change something in the widget).

One caveat: If you do this same search job but look in the wxWidgets API
instead of the wxPython one, you actually don't find (or at least I
can't find) the
.SetItem() method. Can someone explain to me why this is? Where is it?
And so, it is useful to look in the wxPython API (though I find the
wxWidgets
webpage easier to read somehow)

I just taught and so am in a pedagogical mood, but I hope this was
helpful to just
have somewhere, since it is a point that was very frustrating for me
until I began to
catch on that this is where to find "obvious" methods that weren't
found listed under
a widget's methods.

Che
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

________________________________
Discover the new Windows Vista Learn more!
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users