[wxPython-users] Default wx.Choice() Value?

Christopher Barker Chris.Barker at noaa.gov
Thu Dec 21 14:43:01 PST 2006


Rich Shepard wrote:
>> see: wx.Choice.SetSelection and wx.Choice.SetStringSelection

>   On the newAPI page I see only GetSelection() and GetCurrentSelection().

Are you using 2.8? if so then there is a CurrentSelection Property -- I 
don't know if it can take a string, or just an index. Otherwise,

wx.Choice.SetSelection and wx.Choice.SetStringSelection

are derived from ItemContainer -- all these nested classes so make it 
hard to find things!

> What I've done is explicitly assign the string to the variable that is set
> by the event.GetSelection() method if the value is changed from the 
> default.
> 
>   I can see the value of the above when retrieving values from the database
> and displaying them in the widgets, but that's separate from getting an
> initial, default, value.

I'm not sure I follow, but:

A) you can either get and set selections by index number or string -- I 
like to use strings, otherwise I need to keep a separate list or dict to 
map strings to indices.

B) This is what I do when using a wx.Choice:

1- populate the Choice on construction:
2- Set a default Choice on construction -- this may well be just index0, 
but sometimes there is a reason to have a particular default.
3- bind  EVT_CHOICE to a method that does somethign with the choice
4- Usually have a method to set the choice, if it is set somewhere else 
in the program.

2 and 4 require SetStringSelection.

-Chris




-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list