From: <m.e...@at...> - 2004-10-27 05:38:13
|
In attempting to get through walkthrough 3 I have run into a bit of a wall. It appears that the on_openBackground methods in the counter module and the child module never execute. Has the name changed? Do I need to add code to specifically execute these event methods? I would appreciate any guidance. Here is the Counter code: # Second PythonCard program following walkthrough 3 from PythonCard import model import child class Counter(model.Background): def on_openBackground(self, event): self.childWindow = model.childWindow(self, child.Child) # override resource position self.childWindow.SetPostion((200,5)) self.childWindow.Show() # Counter modification methods def incrCtr(self): startValue = int(self.components.field1.text) endValue = startValue + 1 self.components.field1.text = str(endValue) self.childWindow.components.field1.text = str(endValue) def decrCtr(self): startValue = int(self.components.field1.text) endValue = startValue - 1 self.components.field1.text = str(endValue) self.childWindow.components.field1.text = str(endValue) def rstCtr(self): self.components.field1.text = "42" # Event Handlers def on_counterMenuIncr_select(self, event): self.incrCtr() def on_counterMenuDecr_select(self, event): self.decrCtr() def on_counterMenuRst_select(self, event): self.rstCtr() def on_incrBtn_mouseClick(self, event): self.incrCtr() def on_decBtn_mouseClick(self, event): self.decrCtr() def on_rstBtn_mouseClick(self, event): self.rstCtr() if __name__ == '__main__': app = model.Application(Counter) app.MainLoop() The child module: """ __version__ = "$Revision: 1.10 $" __date__ = "$Date: 2004/04/24 22:13:31 $" """ from PythonCard import model class Child(model.Background): def on_openBackground(self, event): self.parent = self.GetParent() def on_btnReset_mouseClick(self, event): self.parent.components.field1.text = "0" def doExit(self): self.parent.components.field1.text = "99" def on_close(self, event): self.doExit() self.Show(0) def on_menuFileExit_select(self, event): self.Close() if __name__ == '__main__': app = model.Application(Child) app.MainLoop() When I execute Counter and press the increment button I get the following traceback: Traceback (most recent call last): File "C:\Program Files\Python23\lib\site-packages\PythonCard\widget.py", line 402, in _dispatch handler(background, aWxEvent) File "C:\Program Files\Python23\Lib\site-packages\PythonCard\samples\myCounter \myCounter.py", line 44, in on_incrBtn_mouseClick self.incrCtr() File "C:\Program Files\Python23\Lib\site-packages\PythonCard\samples\myCounter \myCounter.py", line 22, in incrCtr self.childWindow.components.field1.text = str(endValue) AttributeError: 'Counter' object has no attribute 'childWindow' It looks like childWindow is not defined because the method that defines it didn't execute. If it had, i would have expected it to work or traceback on the references to the attribute in that method. Mark |