Update of /cvsroot/pythoncard/PythonCard
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2193
Modified Files:
model.py
Log Message:
tweaked addMethod and isPythonCardHandler to handle functions and methods
Index: model.py
===================================================================
RCS file: /cvsroot/pythoncard/PythonCard/model.py,v
retrieving revision 1.198
retrieving revision 1.199
diff -C2 -d -r1.198 -r1.199
*** model.py 28 Jul 2007 23:13:31 -0000 1.198
--- model.py 28 Jul 2007 23:44:04 -0000 1.199
***************
*** 537,541 ****
Return true if the object is a PythonCard handler.
"""
! return isinstance(aObject, types.FunctionType) and aObject.__name__.split('_')[0] == 'on'
def _addHandler(self, aMethod):
--- 537,543 ----
Return true if the object is a PythonCard handler.
"""
! return isinstance(aObject, types.FunctionType) or \
! isinstance(aObject, types.MethodType) and \
! aObject.__name__.split('_')[0] == 'on'
def _addHandler(self, aMethod):
***************
*** 547,552 ****
def addMethod(self, aFunction):
! if isinstance(aFunction, types.FunctionType):
! if self.isPythonCardHandler(aFunction) :
#aMethod = new.instancemethod(aFunction, self, self.__class__)
aMethod = new.instancemethod(aFunction, None, self.__class__)
--- 549,554 ----
def addMethod(self, aFunction):
! if self.isPythonCardHandler(aFunction):
! if isinstance(aFunction, types.FunctionType):
#aMethod = new.instancemethod(aFunction, self, self.__class__)
aMethod = new.instancemethod(aFunction, None, self.__class__)
***************
*** 555,576 ****
#print aMethod.__name__
#print aMethod
! setattr(self.__class__, aMethod.__name__, aMethod)
! # now add the method info to our handler lookup dictionary
! # KEA 2001-11-29 simplified _addHandler
! #handler = event.Handler(aMethod.__name__, aMethod)
! #self._addHandler(aMethod.__name__, handler)
! self._addHandler(aMethod)
!
! # KEA 2004-05-13
! # will need to call _bindEvents here to make sure the event handler
! # is bound to the right component instances
! # trying to figure out all the components as well as the reverse mapping
! # from an event name like mouseDown to event.MouseDownEvent is tricky
! # at best so we'll probably need to have user-code make explicit calls
! # to _bindEvents for each component they want to bind
! # the name to event class mapping can be found by iterativing over the
! # events defined in the spec for a given component to find a name match
! # maybe just calling _bindEvents with a full list of relevant events
! # would work, since the boundEvents list will prevent double-binding
def findHandler(self, aString):
--- 557,580 ----
#print aMethod.__name__
#print aMethod
! else:
! aMethod = aFunction
! setattr(self.__class__, aMethod.__name__, aMethod)
! # now add the method info to our handler lookup dictionary
! # KEA 2001-11-29 simplified _addHandler
! #handler = event.Handler(aMethod.__name__, aMethod)
! #self._addHandler(aMethod.__name__, handler)
! self._addHandler(aMethod)
!
! # KEA 2004-05-13
! # will need to call _bindEvents here to make sure the event handler
! # is bound to the right component instances
! # trying to figure out all the components as well as the reverse mapping
! # from an event name like mouseDown to event.MouseDownEvent is tricky
! # at best so we'll probably need to have user-code make explicit calls
! # to _bindEvents for each component they want to bind
! # the name to event class mapping can be found by iterativing over the
! # events defined in the spec for a given component to find a name match
! # maybe just calling _bindEvents with a full list of relevant events
! # would work, since the boundEvents list will prevent double-binding
def findHandler(self, aString):
|