Getting Selected String from wx.RadioBox()

Rich Shepard wrote:

  This is the definition of a wx.RadioBox() on a notebook page (using
2.6.3.2):

    self.valphaType = wx.RadioBox(self, wx.ID_ANY, choices=['Strong', 'Weak'],
                             label=' Alpha-cut ', majorDimension=2,
                             style=wx.RA_SPECIFY_COLS|wx.RAISED_BORDER)
    # self.valphaType.SetSelection(0)
    self.varAlphaType = self.valphaType.GetStringSelection()

  Regardless of whether that second line is evaluated or commented out, I
cannot get the second string, 'Weak,' to be assigned to self.varAlphaType.
It's always 'Strong.' I don't see what I've written incorrectly, and would
appreciate a clue.

The SetSelection, and the default selection are selecting the first radio item, which is of course 'Strong'. If you want the 'Weak' item selected then use SetSelection(1). For example, in a PyShell:

  PyShell 0.9.5 - The Flakiest Python Shell
  Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
  [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  Startup script executed: /home/robind/bin/pythonstartup.py
  >>> import wx
  >>> rb = wx.RadioBox(shell, choices=['Strong', 'Weak'], label = 'Alpha-cut',
  ... majorDimension=2, style=wx.RA_SPECIFY_COLS|wx.RAISED_BORDER)
  >>> rb.SetSelection(1)
  >>> rb.GetStringSelection()
  u'Weak'
  >>> rb.SetSelection(0)
  >>> rb.GetStringSelection()
  u'Strong'

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin,

   That's all true. I accidently left off the last line:

     self.valphaType = wx.RadioBox(self, wx.ID_ANY, choices=['Strong', 'Weak'],
                              label=' Alpha-cut ', majorDimension=2,
                              style=wx.RA_SPECIFY_COLS|wx.RAISED_BORDER)
     self.valphaType.SetSelection(0)
     self.varAlphaType = self.valphaType.GetStringSelection()
     self.Bind(wx.EVT_SET_FOCUS, self.OnAlphaType, self.valphaType)

and the bound method is:

   def OnAlphaType(self, event):
     self.vt = self.valphaType.GetStringSelection()
     print "In OnAlphaType: ", self.vt, '\n'

   Since nothing is printed as I select 'Weak' (or back to 'Strong') I must
not be picking up the correct method.

Thanks,

Rich

···

On Tue, 26 Dec 2006, Robin Dunn wrote:

The SetSelection, and the default selection are selecting the first radio
item, which is of course 'Strong'. If you want the 'Weak' item selected
then use SetSelection(1). For example, in a PyShell:

--
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

Oh, my! Wonder how I blew that one? Didn't see it at all.

Many thanks, Robin,

Rich

···

On Tue, 26 Dec 2006, Robin Dunn wrote:

Try wx.EVT_RADIOBOX instead of wx.EVT_SET_FOCUS.

--
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