Returned Values from Multi-Entry Dialog Box

I have derived a class from wx.Dialog that allows the user to enter text
strings for each of four variables. The dialog box examples I've found all
print a message that "OK" was selected, but I want the values of each of
these four variables.

   Are all the variables available for use when the "OK" button is selected?
Do I declare them global so I can use them in a different class in the same
module? Is there an example I can see that shows how this is correctly done?

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

Rich Shepard wrote:

  I have derived a class from wx.Dialog that allows the user to enter text
strings for each of four variables. The dialog box examples I've found all
print a message that "OK" was selected, but I want the values of each of
these four variables.

  Are all the variables available for use when the "OK" button is selected?

As long as you have the instance around, you should be able to access its attributes and methods.

Do I declare them global so I can use them in a different class in the same
module?

ouch! no.

Is there an example I can see that shows how this is correctly done?

Here is a simple one that should make it clear:

class MyCheckDialog(wx.Dialog):
     def __init__(self, Choices):
         wx.Dialog.__init__(self, None, -1, 'wxDialog')
         self.Choices = Choices

         self.clb = wx.CheckListBox(self, -1, wx.DefaultPosition, wx.DefaultSize, self.Choices)

         ok = wx.Button(self, wx.ID_OK, 'Ok')

         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.clb, 1, wx.EXPAND|wx.ALL, 5)
         sizer.Add(ok, 0, wx.ALIGN_RIGHT|wx.ALL^wx.TOP, 5)
         self.SetSizer(sizer)
         #self.Fit()

         self.Center() # make it come up on the center of the screen

     def GetChecked(self):
         Checked =
         for (index, item) in enumerate(self.Choices):
             if self.clb.IsChecked(index):
                 Checked.append(item)
         return Checked

## And to use it:

a = wx.App()

myd = MyCheckDialog(['check', 'list', 'box', 'another'])
if myd.ShowModal() != wx.ID_OK:
     exit(1)
else:
     print "You checked:", myd.GetChecked()

If you put all that in a file and run it, you'll see how it works

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Rich Shepard wrote:

  I have derived a class from wx.Dialog that allows the user to enter text
strings for each of four variables. The dialog box examples I've found all
print a message that "OK" was selected, but I want the values of each of
these four variables.

  Are all the variables available for use when the "OK" button is selected?
Do I declare them global so I can use them in a different class in the same
module? Is there an example I can see that shows how this is correctly done?

Give your dialog class a method or methods like GetValues, and then after the ShowModal, (and if it returns wx.ID_OK) you can call theDialog.GetValues() to fetch them.

···

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

As long as you have the instance around, you should be able to access its attributes and methods.

Chris,

   Ah ... sure.

Do I declare them global so I can use them in a different class in the same
module?

ouch! no.

   Right.

Here is a simple one that should make it clear:
If you put all that in a file and run it, you'll see how it works

   Thanks. I'll compare my not-yet-working code to this and learn what I've
done incorrectly.

Many thanks,

Rich (Don't forget to vote early and vote often!)

···

On Tue, 7 Nov 2006, Christopher Barker wrote:

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

Thanks for the pointer, Robin. I think this is exactly what I need since
those values will need to be inserted in an embedded database table.

Rich

···

On Tue, 7 Nov 2006, Robin Dunn wrote:

Give your dialog class a method or methods like GetValues, and then after
the ShowModal, (and if it returns wx.ID_OK) you can call
theDialog.GetValues() to fetch them.

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

The wxpython.org web site is not reachable, and I no longer have the
source code available. In what widget(s) can I find a GetValue() method I
could use as a template?

Thanks,

Rich

···

On Tue, 7 Nov 2006, Robin Dunn wrote:

Give your dialog class a method or methods like GetValues, and then after
the ShowModal, (and if it returns wx.ID_OK) you can call
theDialog.GetValues() to fetch them.

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

Rich Shepard <rshepard <at> appl-ecosys.com> writes:

> Give your dialog class a method or methods like GetValues, and then after
> the ShowModal, (and if it returns wx.ID_OK) you can call
> theDialog.GetValues() to fetch them.

   The wxpython.org web site is not reachable, and I no longer have the
source code available. In what widget(s) can I find a GetValue() method I
could use as a template?

I doubt he was referring to some special method rather than exactly to the
method that Christopher named 'GetChecked' in his example.

Christian