dabo Commit
Revision 1586
Date: 2005-11-27 15:57:41 -0800 (Sun, 27 Nov 2005)
Author: paul
Changed:
U trunk/dabo/lib/eventMixin.py
U trunk/dabo/ui/uiwx/dComboBox.py
U trunk/dabo/ui/uiwx/dDropdownList.py
U trunk/dabo/ui/uiwx/dListBox.py
U trunk/dabo/ui/uiwx/dListControl.py
U trunk/dabo/ui/uiwx/dPemMixin.py
U trunk/dabo/ui/uiwx/dRadioGroup.py
U trunk/dabo/ui/uiwx/dTextBox.py
U trunk/dabo/ui/uiwx/dTimer.py
U trunk/dabo/ui/uiwx/dToggleButton.py
Log:
Improved autoBindEvents() to bind not only to matching methods in self and
self.Form, but also in all parent containers.
Made it more robust by also calling autoBindEvents() whenever the RegID,
Parent, or Name properties change. Added code to first remove any prior
auto bindings before running the autobinding a second time.
Removed old explicit calls to autoBindEvents in several of the tests.
Diff:
Modified: trunk/dabo/lib/eventMixin.py
===================================================================
--- trunk/dabo/lib/eventMixin.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/lib/eventMixin.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -11,14 +11,15 @@
All Dabo objects inherit this functionality.
"""
def __init__(self, *args, **kwargs):
- self._autoBindEvents(context=self)
+ self.autoBindEvents()
- def bindEvent(self, eventClass, function):
+
+ def bindEvent(self, eventClass, function, _auto=False):
"""Bind a dEvent to a callback function.
"""
eb = self._EventBindings
if (eventClass, function) not in eb:
- eb.append((eventClass, function))
+ eb.append((eventClass, function, _auto))
def bindEvents(self, bindings):
@@ -153,17 +154,20 @@
This feature is inspired by PythonCard.
"""
- # We call _autoBindEvents for self and form, and force it
because it was
- # asked for explicitly.
+ # First remove any previous auto bindings (in case the name or
parent of
+ # the object is changing: we don't want the old bindings to
stay active).
+ self._removeAutoBindings()
+
+ # We call _autoBindEvents for self and all parent containers,
and force
+ # it because it was asked for explicitly.
self._autoBindEvents(context=self, force=True)
- try:
- form = self.Form
- except AttributeError:
- form = None
- if form is not None:
- self._autoBindEvents(context=form, force=True)
+ parent = self.Parent
+ while parent:
+ self._autoBindEvents(context=parent, force=True)
+ parent = parent.Parent
+
def _autoBindEvents(self, context, force=False):
import dabo.dEvents as dEvents
@@ -219,7 +223,7 @@
if type(funcObj) in (types.FunctionType,
types.MethodType):
evtObj = dEvents.__dict__[parsedEvtName]
funcObj = eval("context.%s" % funcName)
## (can't use __class__.dict...)
- self.bindEvent(evtObj, funcObj)
+ self.bindEvent(evtObj, funcObj,
_auto=True)
def getEventList(cls):
@@ -256,7 +260,19 @@
# Allow for alternate capitalization (deprecated):
unBindEvent = unbindEvent
-
+
+
+ def _removeAutoBindings(self):
+ """Remove all event bindings originally set by
autoBindEvents()."""
+ toRemove = []
+ for idx, binding in enumerate(self._EventBindings):
+ if binding[2]:
+ toRemove.append(idx)
+ toRemove.reverse()
+ for idx in toRemove:
+ del(self._EventBindings[idx])
+
+
def _getEventBindings(self):
try:
return self._eventBindings
Modified: trunk/dabo/ui/uiwx/dComboBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dComboBox.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dComboBox.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -110,9 +110,6 @@
self.setup()
self.appendOnEnter = True
- def initEvents(self):
- self.autoBindEvents()
-
def setup(self):
# Simulating a database:
wannabeCowboys = ({"lname": "Reagan", "fname": "Ronald", "iid":
42},
Modified: trunk/dabo/ui/uiwx/dDropdownList.py
===================================================================
--- trunk/dabo/ui/uiwx/dDropdownList.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dDropdownList.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -46,10 +46,6 @@
self.ValueMode = "key"
- def initEvents(self):
- self.autoBindEvents()
-
-
def onHit(self, evt):
print "KeyValue: ", self.KeyValue
print "PositionValue: ", self.PositionValue
Modified: trunk/dabo/ui/uiwx/dListBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dListBox.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dListBox.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -60,9 +60,6 @@
def initProperties(self):
self.setup()
- def initEvents(self):
- self.autoBindEvents()
-
def setup(self):
# Simulate a database:
actors = ({"lname": "Jason Leigh", "fname": "Jennifer", "iid":
42},
Modified: trunk/dabo/ui/uiwx/dListControl.py
===================================================================
--- trunk/dabo/ui/uiwx/dListControl.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dListControl.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -433,9 +433,6 @@
self.VerticalRules = True
#self.HeaderVisible = False
- def initEvents(self):
- self.autoBindEvents()
-
def onHit(self, evt):
print "KeyValue: ", self.KeyValue
print "PositionValue: ", self.PositionValue
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -1388,6 +1388,9 @@
# Parent could be None
pass
+ ## When the name changes, we need to autobind again:
+ self.autoBindEvents()
+
else:
self._properties["Name"] = name
@@ -1405,6 +1408,8 @@
def _setParent(self, val):
if self._constructed():
self.changeParent(val)
+ ## When the object's parent changes, we need to
autobind again:
+ self.autoBindEvents()
else:
self._properties["Parent"] = val
@@ -1429,10 +1434,11 @@
self._registryID = val
try:
self.Form.registerObject(self)
- # If the Form defines event callbacks for the object,
bind them:
- self._autoBindEvents(context=self.Form)
except:
dabo.errorLog.write(_("Failed to register RegID '%s'")
% val)
+
+ # When the object's RegID is set, we need to autobind again:
+ self.autoBindEvents()
def _getSize(self):
Modified: trunk/dabo/ui/uiwx/dRadioGroup.py
===================================================================
--- trunk/dabo/ui/uiwx/dRadioGroup.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dRadioGroup.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -342,9 +342,6 @@
self.Orientation = "None"
self.setup()
- def initEvents(self):
- self.autoBindEvents()
-
def setup(self):
print "Simulating a database:"
developers = ({"lname": "McNett", "fname": "Paul", "iid": 42},
Modified: trunk/dabo/ui/uiwx/dTextBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dTextBox.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dTextBox.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -408,9 +408,6 @@
TestBase.doDefault()
self.LogEvents = ["ValueChanged",]
- def initEvents(self):
- self.autoBindEvents()
-
def onValueChanged(self, evt):
if self.IsSecret:
print "%s changed, but the new value is a
secret!" % self.Name
Modified: trunk/dabo/ui/uiwx/dTimer.py
===================================================================
--- trunk/dabo/ui/uiwx/dTimer.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dTimer.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -97,9 +97,6 @@
self.Visible = True
self.start()
- def initEvents(self):
- self.autoBindEvents()
-
def onHit(self, evt):
print "timer fired!"
Modified: trunk/dabo/ui/uiwx/dToggleButton.py
===================================================================
--- trunk/dabo/ui/uiwx/dToggleButton.py 2005-11-26 23:43:10 UTC (rev 1585)
+++ trunk/dabo/ui/uiwx/dToggleButton.py 2005-11-27 23:57:41 UTC (rev 1586)
@@ -26,9 +26,6 @@
self.Caption = "Toggle me!"
self.Size = (100, 31)
- def initEvents(self):
- self.autoBindEvents()
-
def onHit(self, evt):
if self.Value:
state = "down"
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev