From: John <joh...@jo...> - 2004-09-17 15:11:06
|
On Thu, 16 Sep 2004, Kevin Altis wrote: > 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 > I get the dialog in fact that's close to what I'm currently doing. My question is how to pass parameters to a class derived from model.background *in the constructor* once you have the instance it's easy enough to set them, but is it possible to pass parameters to the __init__ for model.background or oninitialize when you make the call app = model.Application(Launcher) for example. -john --------------------------------------------------------- My religion consists of a humble admiration of the illimitable superior spirit who reveals himself in the slight details we are able to perceive with our frail and feeble mind. Albert Einstein |