|
From: <kc1...@ya...> - 2006-11-10 20:36:07
|
Oops! Didn't see this when I first read the trick page:=0A=0AA simpler sol= ution may just be using the wx.CallAfter=0Amethod to execute any additional= code you want to run. Just put the=0Acode you want to execute after your e= vent is finished AND the new=0Awindows on_initialize has finished in anothe= r method which you call=0Ausing wx.CallAfter. Use the findfiles sample for = examples in the samples and tools directories.=0A=0AMaybe that would accomp= lish what I said...=0A =0A--=0AJohn Henry=0A=0A----- Original Message ----= =0AFrom: "kc1...@ya..." <kc1...@ya...= >=0ATo: pyt...@li...=0ASent: Friday, November 10,= 2006 12:26:23 PM=0ASubject: Passing parameters to childwindow=0A=0AOn the = age old issue of passing parameters to childwindow, I think it's rather con= fusing that we have to rely on "trick" to do it. See, for example:=0A=0Aht= tp://wiki.wxpython.org/index.cgi/PythonCardTricks=0A=0Awhere it was suggest= ed that we use the rather unnatural and "magical" way of:=0A=0Adef on_Butto= n1_mouseClick(self, event):=0A self.childWin =3D model.ChildWindow(self, = bar.Bar)=0A self.childWin.dbNamePassedFromParent =3D self.databaseName=0A= Instead of doing that, is there anything wrong if I pass down a CallBackFun= ction such as:=0A=0A def on_Button1_mouseClick(self, event):=0A s= elf.childWin =3D model.childWindow(self, tchild, SetInitParamFct=3Dself.Set= ChildInitParam)=0A pass=0A =0A def SetChildInitParam(self,= childWindow):=0A ...do what ever...=0A pass=0A=0Aand then i= n childWindow, we allow an extra parameter:=0A=0Adef childWindow(parent, fr= ameClass, filename=3DNone, rsrc=3DNone, SetInitParamFct=3DSetInitParam):=0A= .....=0A return frameClass(parent, rsrc.application.backgrounds[0], SetI= nitParamFct=3DSetInitParamFct)=0A=0Aand then invoke the call back function = at the very end of the __init__ function of the Background class:=0A=0Aclas= s Background(Scriptable, wx.Frame, event.EventSource):=0A=0A def __init_= _(self, aParent, aBgRsrc, SetInitParamFct=3DSetInitParam):=0A ....= =0A SetInitParamFct(self)=0A return=0A=0AOf course, I nee= d a stub function somewhere in model.py in case the call back function was = not defined:=0A=0A# Stub function for setting ChildWindow parameters=0A=0Ad= ef SetInitParam(childWindow):=0A=0A pass=0A=0A =0ADoes anybody know i= f there would be side-effects that I am not aware of?=0A=0AWith this approa= ch, I don't need to remind myself how the event dispatcher works when I loo= k at my own code few years down the road....=0A=0A=0A=0A =0A--=0AJohn Henry= =0A=0A=0A=0A=0A |