From: Kevin A. <al...@se...> - 2004-09-16 21:28:59
|
On Sep 16, 2004, at 12:28 PM, John wrote: > Why don't we put this back on the list. Others may be interested. > > Something else popped up for me. While looking at converting my > dialogs I realized I need to pass a database 'handle' from my main app > to > the dialogs which executes operations on the tables. With the dialogs > it > was easy, call the dialog with the handle when I instantiate the > class, and > assign the handle to self.handle in the __init__ method. If I were to > call > a 'sub' -app it does not seem to be as straight forward, give how > backgrounds are called. Although I could have a get like method say > getdbhandle, to accomplish what I was doing in the > 'constructor' __init__. I'll guess I'll dive into the background > code and find out. ;) You have a couple of options. One, simply refer to variables in the parent. For example, it is common when creating a CustomDialog to set the parent as so (example from resourceEditor dialogInfoDialog.py... class DialogInfoDialog(model.CustomDialog): def __init__(self, aBg, rsrc): model.CustomDialog.__init__(self, aBg) self.parent = aBg ... If you had an attribute in the main background that called the dialog called db then you could refer to it as self.parent.db. Actually, the line above is redundant because CustomDialog __init__ sets the parent as well. For Background, CustomDialog, and PageBackground you can always just use the wxPython GetParent() method to get the same info. There is a mixedCase getParent alias as well. If you're creating a child window then you can set variables in the child using the reference you keep when you create the child, so something like: self.subWindow = model.childWindow(...) self.subWindow.db = self.db In your child window, you could then use self.db. The on_initialize event handler won't run until after your current event handler terminates, so the on_initialize can actually make references to self.db. ka |