dabo Commit
Revision 1273
Date: 2005-09-08 22:07:51 -0700 (Thu, 08 Sep 2005)
Author: paul

Changed:
U   trunk/dabo/ui/uiwx/dGrid.py

Log:
Made dColumn's HorizontalCellAlignment propery accept a value of 
"Automatic", which will align right for numeric data and left for
text, automatically. This is the default and can be overridden by
just assigning "Left", "Right", or "Center" explicitly.


Diff:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2005-09-09 00:57:31 UTC (rev 1272)
+++ trunk/dabo/ui/uiwx/dGrid.py 2005-09-09 05:07:51 UTC (rev 1273)
@@ -468,17 +468,8 @@
 
        def _setDataType(self, val):
                self._dataType = val
-               # Automatically set the Alignment based on the data type. TODO: 
refactor
-               # so that Alignment can be set to "Automatic" (the default) and 
run this
-               # code block only when that is the case.
-               if True:  ## (if self.HorizontalCellAlignment == "Automatic")
-                       # for some reason, the DataType is first getting set to 
a type, and then
-                       # to a common string representing that type. I've coded 
this to just 
-                       # respond to the string values, but I'm not sure that's 
right.
-                       if isinstance(val, basestring):
-                               if val in ("decimal", "float", "long", "int"):
-                                       self.HorizontalCellAlignment = "Right"
-
+               if "Automatic" in self.HorizontalCellAlignment:
+                       self._setAutoHorizontalCellAlignment()
                self.changeMsg("DataType")
        
 
@@ -511,6 +502,11 @@
                self.Parent.Refresh()
        
        def _getHorizontalCellAlignment(self):
+               try:
+                       auto = self._autoHorizontalCellAlignment
+               except AttributeError:
+                       auto = self._autoHorizontalCellAlignment = True
+               
                mapping = {wx.ALIGN_LEFT: "Left", wx.ALIGN_RIGHT: "Right",
                     wx.ALIGN_CENTRE: "Center"}
                
@@ -519,9 +515,25 @@
                        val = mapping[wxAlignment]
                except KeyError:
                        val = "Left"
+               
+               if auto:
+                       val = "%s (Automatic)" % val
                return val
 
-       def _setHorizontalCellAlignment(self, val):
+       def _setAutoHorizontalCellAlignment(self):
+               dt = self.DataType
+               if isinstance(dt, basestring):
+                       if dt in ("decimal", "float", "long", "int"):
+                               self._setHorizontalCellAlignment("Right", 
_autoAlign=True)
+               
+       def _setHorizontalCellAlignment(self, val, _autoAlign=False):
+               if val == "Automatic" and not _autoAlign:
+                       self._autoHorizontalCellAlignment = True
+                       self._setAutoHorizontalCellAlignment()
+                       return
+               if val != "Automatic" and not _autoAlign:
+                       self._autoHorizontalCellAlignment = False
+
                mapping = {"Left": wx.ALIGN_LEFT, "Right": wx.ALIGN_RIGHT,
                     "Center": wx.ALIGN_CENTRE}
                
@@ -618,7 +630,11 @@
        HorizontalCellAlignment = property(_getHorizontalCellAlignment, 
_setHorizontalCellAlignment, None,
                        _("""Horizontal alignment for all cells in this column. 
(str)
 
-Acceptable values are "Left", "Center", and "Right". """))
+Acceptable values are:
+       "Automatic": The cell's contents will align right for numeric data, 
left for text. (default)
+       "Left"
+       "Center"
+       "Right" """))
 
        Order = property(_getOrder, _setOrder, None,
                        _("Order of this column  (int)") )




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

Reply via email to