What is the recommended way to assign the displayed values of wx.Choice()
widgets to variables without explicitly clicking on each one?
If the user clicks on the default value, or selects another one, then
EVT_CHOICE is generated and the bound method can change the value of the
variable. Do I need to assign the default to that value when the widget is
constructed?
Rich
···
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc.(TM) | Accelerator
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
On the newAPI page I see only GetSelection() and GetCurrentSelection().
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.
Thanks -- and happy holidays,
Rich
···
On Thu, 21 Dec 2006, Christopher Barker wrote:
yes:
see: wx.Choice.SetSelection and wx.Choice.SetStringSelection
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc.(TM) | Accelerator
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
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!
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.
Ditto.
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.
I've set the default manually, not using SetStringSelection. Please
provide an example of how you do this. (Your #2)
self.vsource.SetStringSelection('External')
or
self.vsource.SetSelection(0)
Either of these will set the control itself to display the first item, but no events will be sent so if you also need to maintain the self.varSource variable then setting it explicitly like you do is the right thing to do. If you don't need to use self.varSource for anything than getting the current value later then you can just use self.vsource.GetStringSelection() and not worry about keeping the value in sync.
···
On Thu, 21 Dec 2006, Christopher Barker wrote:
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
All manipulations using these data are performed by middleware functions
on records retrieved from the database. Getting the current value when a new
model variable is entered, or an existing one modified, is the sole purpose
of self.varSource.
Happy holidays,
Rich
···
On Thu, 21 Dec 2006, Robin Dunn wrote:
self.vsource.SetStringSelection('External')
or
self.vsource.SetSelection(0)
Either of these will set the control itself to display the first item, but
no events will be sent so if you also need to maintain the self.varSource
variable then setting it explicitly like you do is the right thing to do. If you don't need to use self.varSource for anything than getting the
current value later then you can just use
self.vsource.GetStringSelection() and not worry about keeping the value in
sync.
--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc.(TM) | Accelerator
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
All manipulations using these data are performed by middleware functions
on records retrieved from the database. Getting the current value when a new
model variable is entered, or an existing one modified, is the sole purpose
of self.varSource.
If I understand that right, then you may not want self.varSource at all, you could just call self.vsource.GetStringSelection() directly. That kind of violates the "Law of Demeter", so an alternative is to make self.varSource a property, that gets and sets the Choice selection, that way the same data is only stored in one place.
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
I need to ponder this for a while to ensure that I understand.
This module was originally written last summer when I was just starting on
this application and python/wxPython. Now I'm revising it so it works. There
are 15 widgets on this notebook page: wx.TextCtrl(), wx.Choice, wx.SpinCtrl,
and a wx.RadioBox. Most of the time the default values of the latter three
types are what are needed. But, if different values are selected then they
need to be displayed and written to the database when the Save button is
pressed.
Rich
···
On Thu, 21 Dec 2006, Christopher Barker wrote:
If I understand that right, then you may not want self.varSource at all,
you could just call self.vsource.GetStringSelection() directly. That kind
of violates the "Law of Demeter", so an alternative is to make
self.varSource a property, that gets and sets the Choice selection, that
way the same data is only stored in one place.
OK. I read his blog entry. AFAIK, I'm not writing 'getters and setters,'
but using those built into wxPython. Of course, I may be completely unaware
of what 'getters and setters' refer to.
OK. I read his blog entry. AFAIK, I'm not writing 'getters and setters,'
but using those built into wxPython. Of course, I may be completely unaware
of what 'getters and setters' refer to.
Setters and Getters instead of Properties is just a matter of taste.
wxPython now comes with a full (? not sure) set of properties tha
"maps" the setters and getters (sorry, I might have said it in an
horrible english), i.e.:
Personally, I find the "property" approach fantastically confusing,
but you should maybe follow the opinion of more experienced users who
consider this as a life saver approach.
Maybe because of the fact that I worked so much with wxWidgets
controls (converting them to Python) my way of programming is heavily
biased over Getters and Setters. In any case, I prefer to leave
properties as something that I assign, i.e.:
MainFrame.installDir = os.getcwd()
and using wxPython setters and getters to assign/retrieve wxPython things.
To avoid disinformation I thought I should mention that you probably meant to say:
Object.SetValue(5)
Yes, yes, I did. When am I going to learn to proofread my emails?
thanks,
-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