I've seen plenty if info everywhere on how to MAKE custom dialogs, but
I can't find anything on how to make USEFUL custom dialogs; that is,
custom dialogs that can send the information inputted by the user to
the main form.
What I actually need is a dialog with two spin controls that can then
be used to adjust something on the main form. I have the dialog
created, but I don't know how to grab the number in the spin controls
and send them to the main form.
I may be misunderstanding, but can’t you just make the spin controls attributes of the dialog?
dlg = SpinControlDialog(None, -1, “My dialog”)
if dlg.ShowModal() == wx.ID_OK :
val1 = dlg.spin_ctrl1.GetValue() # (or whatever the appropriate method is)
val2 = dlg.spin_ctrl2.GetValue()
or if you prefer, make a custom method in the dialog to fetch both values at once. I’m assuming that the dialog is being written as a subclass of wx.Dialog, which is how I always do this, but even if you’re using wx.Dialog directly, you can still save the spin control references as attributes wherever you want. (One of the grosser but very convenient “features” of Python is the ability to add object attributes from any part of the code.)
-Nat
···
On Thu, Jul 8, 2010 at 1:03 PM, onpon4 onpon4@gmail.com wrote:
What I actually need is a dialog with two spin controls that can then
be used to adjust something on the main form. I have the dialog
created, but I don’t know how to grab the number in the spin controls
and send them to the main form.
You are correct Nay...that's the usual way to do it. In the custom
dialog, the programmer would usually have
self.spin_ctrl1 = wx.SpinCtrl()
Then your example would work. Another way to do it would be to use
pubsub, but for this case, I think the way you indicated makes the
most sense.
···
On Jul 8, 3:47 pm, Nat Echols <nathaniel.ech...@gmail.com> wrote:
On Thu, Jul 8, 2010 at 1:03 PM, onpon4 <onp...@gmail.com> wrote:
> What I actually need is a dialog with two spin controls that can then
> be used to adjust something on the main form. I have the dialog
> created, but I don't know how to grab the number in the spin controls
> and send them to the main form.
I may be misunderstanding, but can't you just make the spin controls
attributes of the dialog?
dlg = SpinControlDialog(None, -1, "My dialog")
if dlg.ShowModal() == wx.ID_OK :
val1 = dlg.spin_ctrl1.GetValue() # (or whatever the appropriate method
is)
val2 = dlg.spin_ctrl2.GetValue()
or if you prefer, make a custom method in the dialog to fetch both values at
once. I'm assuming that the dialog is being written as a subclass of
wx.Dialog, which is how I always do this, but even if you're using wx.Dialog
directly, you can still save the spin control references as attributes
wherever you want. (One of the grosser but very convenient "features" of
Python is the ability to add object attributes from any part of the code.)
-Nat
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org