From: Kevin A. <al...@se...> - 2004-05-13 17:39:58
|
On May 13, 2004, at 1:07 AM, chr...@ph... wrote: > Dear all, > > When I upgrade wxPython 2.4.0.4 to 2.5.1.5 the addMethod() function > does > not function properly anymore. I am running PythonCard 0.7.3.1 and > python > 2.2 (also in python 2.3 it gives the same results). The code works > fine in > the old wxPython. > > offending code snippet: > > def on_openBackground(self,event): > for key in self.components.data: > if isinstance(self.components[key],(wx.wxTextCtrl, > wx.wxTextCtrlPtr)): > exec 'def on_'+key+'_mouseDown(self,event): > self.set_active(event.target)' > exec 'self.addMethod(on_'+key+'_mouseDown)' > > gives the following error: > > c:\python22\lib\regsub.py:15: DeprecationWarning: the regsub module is > deprecated; please use re.sub() > DeprecationWarning) > Traceback (most recent call last): > File "C:\Python22\lib\site-packages\PythonCardPrototype\binding.py", > line > 268, in dispatchOpenBackground > self.scriptable.dispatch.eventOccurred( event.OpenBackgroundEvent( > self.scriptable ) ) > File "C:\Python22\lib\site-packages\PythonCardPrototype\dispatch.py", > line 83, in eventOccurred > handler.getFunction()(self._scriptable, nativeEvent) > File "corrector_control.py", line 56, in on_openBackground > exec 'self.addMethod(on_'+key+'_mouseDown)' > File "<string>", line 1, in ? > File "C:\Python22\lib\site-packages\PythonCardPrototype\model.py", > line > 519, in addMethod > self.__class__.__dict__[aMethod.__name__] = aMethod > TypeError: object does not support item assignment This problem stems from wxPython using new-style classes and bad code on my part. I should have been using setattr instead, so change that line in model.py from: self.__class__.__dict__[aMethod.__name__] = aMethod to setattr(self.__class__, aMethod.__name__, aMethod) and addMethod should work again using wxPython 2.5.1.5 and PythonCard 0.7.3.1. ka |