dabo Commit
Revision 1284
Date: 2005-09-09 11:43:08 -0700 (Fri, 09 Sep 2005)
Author: paul

Changed:
U   trunk/dabo/common/propertyHelperMixin.py
U   trunk/dabo/ui/uiwx/dGrid.py
U   trunk/dabo/ui/uiwx/dPemMixin.py

Log:
Added a helper function to propertyHelperMixin that takes in a 
string value and a list of accepted property values, and applies
our rules for allowing lowercase property values and if all the
property values have unique first letters, allowing that. It will
also raise the ValueError exception if the value passed by the 
user isn't kosher. 

The intent is to simplify. Please refer to the two test setters 
that I've changed to implement this: dPemMixin.BorderLineStyle
which shows the case where a single letter isn't sufficient, and
dColumn.HorizontalCellAlignment which shows the case where a 
single letter is sufficient.


Diff:
Modified: trunk/dabo/common/propertyHelperMixin.py
===================================================================
--- trunk/dabo/common/propertyHelperMixin.py    2005-09-09 18:21:49 UTC (rev 
1283)
+++ trunk/dabo/common/propertyHelperMixin.py    2005-09-09 18:43:08 UTC (rev 
1284)
@@ -1,3 +1,5 @@
+from dabo.dLocalize import _
+
 class PropertyHelperMixin(object):
        """ Helper functions for getting information on class properties.
        """
@@ -2,2 +4,38 @@
 
+       def _expandPropStringValue(self, value, propList):
+               """ Called from various property setters: expand value into one 
of the
+               accepted property values in propList. We allow properties to be 
set
+               using case-insensitivity, and for properties with distinct 
first letters
+               for user code to just set the property using the first letter.
+               """
+               value = value.lower().strip()
+               
+               uniqueFirstLetter = True
+               firstLetterCounts = {}
+               firstLetters = {}
+               lowerPropMap = {}
+               for idx, prop in enumerate(propList):
+                       letter = prop[0:1].lower()
+                       firstLetterCounts[letter] = 
firstLetterCounts.get(letter, 0) + 1
+                       if firstLetterCounts[letter] > 1:
+                               uniqueFirstLetter = False
+                       firstLetters[letter] = propList[idx]
+                       lowerPropMap[prop.lower().strip()] = prop
+
+               if uniqueFirstLetter:
+                       # just worry about the first letter in value:
+                       value = firstLetters.get(value[0:1])
+               else:
+                       value = lowerPropMap.get(value)
+               
+               if value is None:
+                       s = _("The only accepted values for this property are ")
+                       for idx, p in enumerate(propList):
+                               if idx == len(propList) - 1:
+                                       s += """%s '%s'.""" % (_("and"), p)
+                               else:
+                                       s += """'%s', """ % p
+                       raise ValueError, s
+               return value
+
        def extractKeywordProperties(self, kwdict, propdict):

Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2005-09-09 18:21:49 UTC (rev 1283)
+++ trunk/dabo/ui/uiwx/dGrid.py 2005-09-09 18:43:08 UTC (rev 1284)
@@ -535,6 +535,7 @@
                                self._setHorizontalCellAlignment("Right", 
_autoAlign=True)
                
        def _setHorizontalCellAlignment(self, val, _autoAlign=False):
+               val = self._expandPropStringValue(val, ("Automatic", "Left", 
"Right", "Center"))
                if val == "Automatic" and not _autoAlign:
                        self._autoHorizontalCellAlignment = True
                        self._setAutoHorizontalCellAlignment()

Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py     2005-09-09 18:21:49 UTC (rev 1283)
+++ trunk/dabo/ui/uiwx/dPemMixin.py     2005-09-09 18:43:08 UTC (rev 1284)
@@ -694,7 +694,7 @@
                if self._borderWidth > 0:
                        dc = wx.ClientDC(self)
                        
-                       sty = self._borderLineStyle
+                       sty = self._borderLineStyle.lower()
                        lnStyle = wx.SOLID
                        if sty in ("dash", "dashed"):
 #                              lnStyle = wx.LONG_DASH          #wx.SHORT_DASH
@@ -788,12 +788,9 @@
                return self._borderLineStyle
        
        def _setBorderLineStyle(self, val):
-               val = val.lower().strip()
-               if val in ("solid", "dash", "dashed", "dot", "dotted", 
"dotdash", "dashdot"):
-                       self._borderLineStyle = val
-                       self._needRedraw = True
-               else:
-                       raise ValueError, "The only possible values are 
'Solid', 'Dash', 'Dot', or 'DotDash'"
+               val = self._expandPropStringValue(val, ("Solid", "Dash", 
"Dashed", "Dot", "Dotted", "DotDash", "DashDot"))
+               self._borderLineStyle = val
+               self._needRedraw = True
 
        def _getBorderWidth(self):
                return self._borderWidth




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to