Newbie: saving dialog variables
jeff elkins
jeffelkins at earthlink.net
Sat May 7 11:43:08 EDT 2005
On Saturday 07 May 2005 02:34 pm, Jeremy Bowers wrote:
> On Sat, 07 May 2005 13:24:34 +0000, jeff elkins wrote:
> > Howdy,
> >
> > I've written a program that calls an imported dialog to gather some
> > needed input. What's the common method for passing that data back to the
> > caller? I've tried a 'return data' prior to self.Close() ... all that
> > happens then is the dialog won't close. I'm sure this is obvious, but
> > this newbie's stuck!
> >
> > Thanks,
> >
> > Jeff
>
> In general, the dialog is an instance of a class. Once the dialog closes,
> the window should be gone but the instance variable should still be around.
> Common practice is to put the relevant data in the dialog instance member
> for retrieval after closing. In certain cases, the method used to invoke
> the dialog will return the relevant value, but this is somewhat limiting.
> In even more rare cases, the dialog will be popped up by a function,
> giving no direct reference to the dialog at any point, and the value is
> returned by the function; this is generally limited to the "Yes/No/Cancel"
> style dialog or its simpler bretheren ("OK/Cancel" and "OK").
>
> I'm assuming that last one is not the case.
>
> To be more directly helpful, we'd need more data, ideally a code snippet
> fully demonstrating the problem (i.e., a runnable program). But at a bare
> minimum, we'd need to know where this dialog came from. Tk? PyGTK?
> wxPython? Some curses library? MFC?
Jeremy,
The dialog is from wxPython, generated using Boa Constructor. I'm cutting out
hunks to try to be concise...
===============
import wx
def create(parent):
return vents(parent)
[wxID_VENTS, wxID_VENTSEXITBUTTON,
wxID_VENTSVENTTYPETEXT,
[snip]
] = [wx.NewId() for _init_ctrls in range(14) ]
class vents(wx.Dialog):
def _init_ctrls(self, prnt):
wx.Dialog.__init__(self, id=wxID_VENTS, name=u'prefs', parent=prnt,
pos=wx.Point(418, 320), size=wx.Size(321, 285),
style=wx.DEFAULT_DIALOG_STYLE, title=u'Ventilator Settings')
self.SetClientSize(wx.Size(321, 285))
self.exitButton = wx.Button(id=wxID_VENTSEXITBUTTON, label=u'OK',
name=u'exitButton', parent=self, pos=wx.Point(60, 250),
size=wx.Size(85, 30), style=0)
self.exitButton.Bind(wx.EVT_BUTTON, self.OnExitButtonButton,
id=wxID_VENTSEXITBUTTON)
self.venttypeText = wx.TextCtrl(id=wxID_VENTSVENTTYPETEXT,
name=u'venttypeText', parent=self, pos=wx.Point(64, 24),
size=wx.Size(144, 25), style=0, value=u'')
[snip]
def __init__(self, parent):
self._init_ctrls(parent)
# build an array of values entered in the dialog
# return array to calling program
def OnExitButtonButton(self, event):
self.Close()
==================
The dialog above is called by:
def OnVentButtonButton(self, event):
dlg = vents.vents(self)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
Thanks again,
Jeff
More information about the Python-list
mailing list