dabo Commit
Revision 1587
Date: 2005-11-27 16:25:44 -0800 (Sun, 27 Nov 2005)
Author: paul
Changed:
U trunk/dabo/lib/eventMixin.py
U trunk/dabo/ui/uiwx/dPemMixin.py
Log:
My last commit blew away the ability to turn auto event binding off. This
fixes that. I also added more to the docstring.
Diff:
Modified: trunk/dabo/lib/eventMixin.py
===================================================================
--- trunk/dabo/lib/eventMixin.py 2005-11-27 23:57:41 UTC (rev 1586)
+++ trunk/dabo/lib/eventMixin.py 2005-11-28 00:25:44 UTC (rev 1587)
@@ -11,7 +11,7 @@
All Dabo objects inherit this functionality.
"""
def __init__(self, *args, **kwargs):
- self.autoBindEvents()
+ self.autoBindEvents(force=False)
def bindEvent(self, eventClass, function, _auto=False):
@@ -143,15 +143,37 @@
self._EventBindings = newBindings
- def autoBindEvents(self):
+ def autoBindEvents(self, force=True):
"""Automatically bind any on*() methods to the associated event.
User code only needs to define the callback, and Dabo will
automatically
set up the event binding. This will satisfy lots of common
cases where
- you want an object to respond to its own events. If you want
another
- object to respond to an event, you'll still have to manually
set up that
- event binding.
+ you want an object or its parent to respond to the object's
events.
+ To use this feature, just define a method on<EventName>(), or
if you
+ want a parent container to respond to the event, make a method
in the
+ parent on<EventName>_<object Name or RegID>().
+
+ For example:
+ class MyButton(dabo.ui.dButton):
+ def onHit(self, evt):
+ print "Hit!"
+
+ class MyPanel(dabo.ui.dPanel):
+ def afterInit(self):
+ self.addObject(MyButton, RegID="btn1")
+
+ def onHit_btn1(self, evt):
+ print "panel: button hit!"
+
+ When the button is pressed, you'll see both 'hit' messages
because of
+ auto event binding.
+
+ If you want to bind your events explicitly, you can turn off
auto event
+ binding by calling:
+
+ dabo.autoBindEvents = False
+
This feature is inspired by PythonCard.
"""
# First remove any previous auto bindings (in case the name or
parent of
@@ -160,11 +182,11 @@
# We call _autoBindEvents for self and all parent containers,
and force
# it because it was asked for explicitly.
- self._autoBindEvents(context=self, force=True)
+ self._autoBindEvents(context=self, force=force)
parent = self.Parent
while parent:
- self._autoBindEvents(context=parent, force=True)
+ self._autoBindEvents(context=parent, force=force)
parent = parent.Parent
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2005-11-27 23:57:41 UTC (rev 1586)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2005-11-28 00:25:44 UTC (rev 1587)
@@ -1389,7 +1389,7 @@
pass
## When the name changes, we need to autobind again:
- self.autoBindEvents()
+ self.autoBindEvents(force=False)
else:
self._properties["Name"] = name
@@ -1409,7 +1409,7 @@
if self._constructed():
self.changeParent(val)
## When the object's parent changes, we need to
autobind again:
- self.autoBindEvents()
+ self.autoBindEvents(force=False)
else:
self._properties["Parent"] = val
@@ -1438,7 +1438,7 @@
dabo.errorLog.write(_("Failed to register RegID '%s'")
% val)
# When the object's RegID is set, we need to autobind again:
- self.autoBindEvents()
+ self.autoBindEvents(force=False)
def _getSize(self):
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev