dabo Commit
Revision 6747
Date: 2011-08-06 04:48:48 -0700 (Sat, 06 Aug 2011)
Author: Jacekk
Trac: http://trac.dabodev.com/changeset/6747

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

Log:
Added data controls on empty data source automatic enable/disable status 
handling.

Diff:
Modified: trunk/dabo/ui/dDataControlMixinBase.py
===================================================================
--- trunk/dabo/ui/dDataControlMixinBase.py      2011-08-06 11:38:01 UTC (rev 
6746)
+++ trunk/dabo/ui/dDataControlMixinBase.py      2011-08-06 11:48:48 UTC (rev 
6747)
@@ -14,6 +14,8 @@
        """Provide common functionality for the data-aware controls."""
        def __init__(self, *args, **kwargs):
                self._fldValidFailed = False
+               # Control enabling/disabling on empty data source helper 
attribute.
+               self._dsDisabled = False
                self.__src = self._srcIsBizobj = self._srcIsInstanceMethod = 
None
                self._designerMode = None
                self._oldVal = None
@@ -95,6 +97,17 @@
                return None
 
 
+       def _verifyEnabledStatus(self, enable):
+               if enable:
+                       if self._dsDisabled:
+                               self._dsDisabled = False
+                               self.Enabled = True
+               else:
+                       if not self._dsDisabled:
+                               self._dsDisabled = True
+                               self.Enabled = False
+
+
        def update(self):
                """Update control's value to match the current value from the 
source."""
                # We need to do the data handling stuff before calling super()
@@ -117,8 +130,13 @@
                        self._inDataUpdate = True
                        try:
                                self.Value = src.getFieldVal(self.DataField)
-                       except (TypeError, dException.NoRecordsException):
+                               self._verifyEnabledStatus(True)
+                       except dException.NoRecordsException:
                                self.Value = self.getBlankValue()
+                               self._verifyEnabledStatus(False)
+                       except (TypeError):
+                               self.Value = self.getBlankValue()
+                               self._verifyEnabledStatus(True)
                        except dException.FieldNotFoundException:
                                # See if DataField refers to an attribute of 
the bizobj:
                                att = getattr(src, self.DataField, None)
@@ -126,6 +144,7 @@
                                        self.Value = method()
                                else:
                                        self.Value = att
+                               self._verifyEnabledStatus(True)
                        self._inDataUpdate = False
                else:
                        if self._srcIsInstanceMethod is None and src is not 
None:

Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py     2011-08-06 11:38:01 UTC (rev 6746)
+++ trunk/dabo/ui/uiwx/dPemMixin.py     2011-08-06 11:48:48 UTC (rev 6747)
@@ -43,6 +43,8 @@
                self._transparency = 255
                # Time to change transparency
                self._transparencyDelay = 0.25
+               # DataControl enabling/disabling helper attribute.
+               self._uiDisabled = False
 
                # There are a few controls that don't yet support 3-way inits 
(grid, for
                # one). These controls will send the wx classref as the 
preClass argument,
@@ -2094,6 +2096,22 @@
 
        def _setEnabled(self, val):
                if self._constructed():
+                       # Handle DataControl disabling on empty data source.
+                       try:
+                               inDataUpdate = self._inDataUpdate
+                       except AttributeError:
+                               inDataUpdate = False
+                       if inDataUpdate:
+                               if self._uiDisabled:
+                                       val = False
+                       else:
+                               self._uiDisabled = not val
+                               try:
+                                       dsDisabled = self._dsDisabled
+                               except AttributeError:
+                                       dsDisabled = False
+                               if dsDisabled:
+                                       val = False
                        self.Enable(val)
                else:
                        self._properties["Enabled"] = False



_______________________________________________
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