dabo Commit
Revision 5563
Date: 2009-12-26 12:41:07 -0800 (Sat, 26 Dec 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5563

Changed:
U   trunk/dabo/ui/dDataControlMixinBase.py

Log:
Improved the flow when controls have their value changed from an update() call. 
Now the flushValue() is no longer called, which avoids unnecessary data 
validation calls.


Diff:
Modified: trunk/dabo/ui/dDataControlMixinBase.py
===================================================================
--- trunk/dabo/ui/dDataControlMixinBase.py      2009-12-21 15:26:04 UTC (rev 
5562)
+++ trunk/dabo/ui/dDataControlMixinBase.py      2009-12-26 20:41:07 UTC (rev 
5563)
@@ -18,6 +18,9 @@
                self._designerMode = None
                self._oldVal = None
                self._userChanged = False
+               # Flags to avoid calling flushValue() when it is not needed.
+               self._inDataUpdate = False
+               self._from_flushValue = False
 
                dabo.ui.dControlMixin.__init__(self, *args, **kwargs)
 
@@ -102,14 +105,14 @@
                """This handles all the value updating from the data source."""
                if getattr(self, "SelectOnEntry", False) and 
self.Form.ActiveControl == self:
                        self.selectAll()
-
-               if not (self.DataSource or isinstance(self.DataSource, 
dabo.dPref)) or not self.DataField:
+               if not self.DataField or not (self.DataSource or 
isinstance(self.DataSource, dabo.dPref)):
                        return
                if self._DesignerMode:
                        return
 
                src = self.Source
                if src and self._srcIsBizobj:
+                       self._inDataUpdate = True
                        try:
                                self.Value = src.getFieldVal(self.DataField)
                        except (TypeError, dException.NoRecordsException):
@@ -119,6 +122,7 @@
                                method = getattr(src, self.DataField, None)
                                if callable(method):
                                        self.Value = method()
+                       self._inDataUpdate = False
                else:
                        if self._srcIsInstanceMethod is None and src is not 
None:
                                if isinstance(src, basestring):
@@ -136,6 +140,7 @@
                                # that the current object doesn't have.
                                return
 
+                       self._inDataUpdate = True
                        if self._srcIsInstanceMethod:
                                try:
                                        self.Value = srcatt()
@@ -145,6 +150,7 @@
                                        self.Value = self.getBlankValue()
                        else:
                                self.Value = srcatt
+                       self._inDataUpdate = False
 
 
        def select(self, position, length):
@@ -246,7 +252,9 @@
                                                                        nm = 
str(self.DataSource)
                                                                
dabo.errorLog.write("Could not bind to '%s.%s'\nReason: %s" % (nm, 
self.DataField, e) )
                                self._oldVal = curVal
-                       self._afterValueChanged(_from_flushValue=True)
+                       self._from_flushValue = True
+                       self._afterValueChanged()
+                       self._from_flushValue = False
 
                        # Raise an event so that user code can react if needed:
                        dabo.ui.callAfterInterval(200, self.raiseEvent, 
dabo.dEvents.ValueChanged)
@@ -302,7 +310,7 @@
                        return "?"
 
 
-       def _afterValueChanged(self, _from_flushValue=False):
+       def _afterValueChanged(self):
                """Called after the control's value has changed.
 
                This is defined as one of:
@@ -311,7 +319,8 @@
 
                User code shouldn't need to access or override this.
                """
-
+               if self._inDataUpdate or self._from_flushValue:
+                       return
                # Maintain an internal copy of the value, separate from the
                # property, so that we still have the value regardless of 
whether
                # or not the underlying ui object still exists (in wx at least,
@@ -320,7 +329,7 @@
                # upon Destroy (saveValue, for instance)):
                self._value = self.Value
 
-               if not _from_flushValue and (self.Form.ActiveControl != self
+               if (self.Form.ActiveControl != self
                                or not getattr(self, "_flushOnLostFocus", 
False)):
                        # Value was changed programatically, and flushValue 
won't ever be
                        # called automatically (either the control won't flush 
itself upon



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to