|
From: <kc1...@ya...> - 2006-11-10 20:26:30
|
On the age old issue of passing parameters to childwindow, I think it's rat= her confusing that we have to rely on "trick" to do it. See, for example:= =0A=0Ahttp://wiki.wxpython.org/index.cgi/PythonCardTricks=0A=0Awhere it was= suggested that we use the rather unnatural and "magical" way of:=0A=0Adef = on_Button1_mouseClick(self, event):=0A self.childWin =3D model.ChildWindo= w(self, bar.Bar)=0A self.childWin.dbNamePassedFromParent =3D self.databas= eName=0AInstead of doing that, is there anything wrong if I pass down a Cal= lBackFunction such as:=0A=0A def on_Button1_mouseClick(self, event):=0A = self.childWin =3D model.childWindow(self, tchild, SetInitParamFct=3D= self.SetChildInitParam)=0A pass=0A =0A def SetChildInitPar= am(self, childWindow):=0A ...do what ever...=0A pass=0A=0Aan= d then in childWindow, we allow an extra parameter:=0A=0Adef childWindow(pa= rent, frameClass, filename=3DNone, rsrc=3DNone, SetInitParamFct=3DSetInitPa= ram):=0A.....=0A return frameClass(parent, rsrc.application.backgrounds[= 0], SetInitParamFct=3DSetInitParamFct)=0A=0Aand then invoke the call back f= unction at the very end of the __init__ function of the Background class:= =0A=0Aclass Background(Scriptable, wx.Frame, event.EventSource):=0A=0A d= ef __init__(self, aParent, aBgRsrc, SetInitParamFct=3DSetInitParam):=0A = ....=0A SetInitParamFct(self)=0A return=0A=0AOf cour= se, I need a stub function somewhere in model.py in case the call back func= tion was not defined:=0A=0A# Stub function for setting ChildWindow paramete= rs=0A=0Adef SetInitParam(childWindow):=0A=0A pass=0A=0A =0ADoes anybo= dy know if there would be side-effects that I am not aware of?=0A=0AWith th= is approach, I don't need to remind myself how the event dispatcher works w= hen I look at my own code few years down the road....=0A=0A=0A=0A =0A--=0AJ= ohn Henry=0A=0A |