dabo Commit
Revision 1275
Date: 2005-09-08 23:00:04 -0700 (Thu, 08 Sep 2005)
Author: paul
Changed:
U trunk/dabo/common/eventMixin.py
Log:
Added functionality for the auto event bindings to look for and
attach to functions in the form object of the form:
on<Event>_<Object.RegId>
If found, the event binding will happen like:
<Object>.bindEvent(<Event>, Form.on<Event>_<Object.Regid>)
Note that if we decide to move forward with this, we should
disallow the _ character from being part of RegId, and we must
never use the _ character in dEvent names.
Diff:
Modified: trunk/dabo/common/eventMixin.py
===================================================================
--- trunk/dabo/common/eventMixin.py 2005-09-09 05:45:48 UTC (rev 1274)
+++ trunk/dabo/common/eventMixin.py 2005-09-09 06:00:04 UTC (rev 1275)
@@ -107,7 +107,7 @@
return r
- def unBindEvent(self, eventClass=None, function=None):
+ def unbindEvent(self, eventClass=None, function=None):
""" Remove a previously registered event binding.
Removes all registrations that exist for the given binding for
this
@@ -165,24 +165,48 @@
This feature is inspired by PythonCard.
"""
import dabo.dEvents as dEvents
- funcNames = [i for i in dir(self) if i[:2] == "on"]
- for funcName in funcNames:
- for m in self.__class__.mro():
- funcObj = None
- try:
- funcObj = m.__dict__[funcName]
- break
- except KeyError:
- pass
- if type(funcObj) in (types.FunctionType,
types.MethodType):
- evtName = funcName[2:]
- if evtName in dir(dEvents):
- evtObj = dEvents.__dict__[evtName]
- funcObj = eval("self.%s" % funcName)
## (can't use __class__.dict...)
- self.bindEvent(evtObj, funcObj)
+ def autoBind(context):
+ if context is None:
+ return
- # Allow for alternate capitalization
- unbindEvent = unBindEvent
+ regid = None
+ if context != self:
+ regid = self.RegID
+ if regid is None or regid == "":
+ return
+
+ funcNames = [i for i in dir(context) if i[:2] == "on"]
+ for funcName in funcNames:
+ s = funcName.split("_")
+ if regid is not None:
+ if len(s) < 2 or s[1] != regid:
+ continue
+ else:
+ if len(s) > 1:
+ continue
+ for m in context.__class__.mro():
+ funcObj = None
+ try:
+ funcObj = m.__dict__[funcName]
+ break
+ except KeyError:
+ pass
+ if type(funcObj) in (types.FunctionType,
types.MethodType):
+ evtName = funcName[2:].split("_")[0]
+ if evtName in dir(dEvents):
+ evtObj =
dEvents.__dict__[evtName]
+ funcObj = eval("context.%s" %
funcName) ## (can't use __class__.dict...)
+ self.bindEvent(evtObj, funcObj)
+
+ autoBind(context=self)
+ try:
+ autoBind(context=self.Form)
+ except AttributeError:
+ # some objects don't have Form property
+ pass
+
+ # Allow for alternate capitalization (deprecated):
+ unBindEvent = unbindEvent
def _getEventBindings(self):
try:
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev