Fwd: Re: [Tutor] global variables and getting/setting controlvalues/variables between frames??

Jeff Peery jeffpeery at yahoo.com
Fri Jul 9 01:20:52 CEST 2004


ok, thanks that makes some sense. I am still confused about one thing.  
 
if I pass a reference to the parent frame into the child dialog, what does the reference look like? I am using the below line for example. this is a definition of a button from by main frame. when I hit the button I want the dialog to appear. I am confused is to what actually calls the dialog, I assume its: wxDialog1.wxDialog1(self), because that assigns the handle.  would I then replace the arguement "self" with my reference to the parent frame?
 
def OnButton1Button(self, event):
        dlg = wxDialog1.wxDialog1(self)
        try: 
            dlg.ShowModal()
        finally:
            dlg.Destroy()

 
Is this stuff discussed in a good book? thanks.
 
thanks.
 
Jeff



 
 

Alan Gauld <alan.gauld at blueyonder.co.uk> wrote:


> Hello, I have an application I am writing with wxpython and the
> boa constructor.

Dunno anything about Boa so that might invalidate my reply...

> I am unsure how to "talk between frames and dialogs".
> Global variables don't seem to be passed into child dialog
> and other frames from the parent frame,

Global variables exist at the file level and should be visible within
any function within that file. However global variables are almnost
certainly the wrong answer! :-)

> I am unsure as to how to get a value from a control in the parent
> dialog from the child dialog.

Just to be clear, we are talking about GUI control here not
class inheritance or widget containment?
ie You have a dialog whereby you hit a button and a new "child"
dialog opens?

>
> myValue = self.textCtrl2.GetValue()
>
> but what if the above line is in a different dialog or frame
> than the text field?

If its in a different object then one of two situations arises:

1) If you know the new dialog needs to know it you pass a refernce
to the parent dialog into the child dialog constructor when you
call it. The child dialog can then call

parent.textCtrl2.GetValue()

OR

2) If the parent needs to know the value from the child dialog you
return it as a result. Without knowing more about the design of your
application its hard to be definite.

But one thing you should never be doing is mixing up GUI widget
code and application logic... So if its an application object that
needs to know then pass a reference to the app object to the dialog
or a reference to the dialog to the app (latter is best for reuse).

HTH

Alan G.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040708/6abd493d/attachment.htm


More information about the Tutor mailing list