dabo Commit
Revision 4032
Date: 2008-04-06 09:04:33 -0700 (Sun, 06 Apr 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4032

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

Log:
Modified the dColumn class to automatically set its DataType property when its 
DataField prop gets changed. 


Diff:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2008-04-06 16:02:35 UTC (rev 4031)
+++ trunk/dabo/ui/uiwx/dGrid.py 2008-04-06 16:04:33 UTC (rev 4032)
@@ -36,13 +36,15 @@
        from decimal import InvalidOperation
 except ImportError:
        _USE_DECIMAL = False
+       # This is needed so that references to this class don't throw
+       # errors when running in Python 2.3
+       Decimal = float
 
 
 
 class dGridDataTable(wx.grid.PyGridTableBase):
        def __init__(self, parent):
                super(dGridDataTable, self).__init__()
-
                self.grid = parent
                self._initTable()
 
@@ -135,7 +137,6 @@
                                if nm in colDefs:
                                        nm = ""
                        colName = "Column_%s" % nm
-
                        pos = col._getUserSetting("Order")
                        if pos is not None:
                                col.Order = pos
@@ -505,7 +506,14 @@
                        "long" : self.longRendererClass,
                        "decimal" : self.decimalRendererClass,
                        "float" : self.floatRendererClass,
-                       "list" : self.listRendererClass  }
+                       "list" : self.listRendererClass,
+                       str : self.stringRendererClass,
+                       unicode : self.stringRendererClass,
+                       bool : self.boolRendererClass,
+                       int : self.intRendererClass,
+                       long : self.longRendererClass,
+                       float : self.floatRendererClass,
+                       list : self.listRendererClass}
                self.defaultEditors = {
                        "str" : self.stringEditorClass,
                        "string" : self.stringEditorClass,
@@ -514,7 +522,17 @@
                        "long" : self.longEditorClass,
                        "decimal" : self.decimalEditorClass,
                        "float" : self.floatEditorClass,
-                       "list" : self.listEditorClass }
+                       "list" : self.listEditorClass,
+                       str : self.stringEditorClass,
+                       unicode : self.stringEditorClass,
+                       bool : self.boolEditorClass,
+                       int : self.intEditorClass,
+                       long : self.longEditorClass,
+                       float : self.floatEditorClass,
+                       list : self.listEditorClass}
+               if _USE_DECIMAL:
+                       self.defaultRenderers[Decimal] = 
self.decimalRendererClass
+                       self.defaultEditors[Decimal] = self.decimalEditorClass
 
                # Default to string renderer
                self._rendererClass = self.stringRendererClass
@@ -686,6 +704,19 @@
                self._setUserSetting(prop, getattr(self, prop))
 
 
+       def _setDataTypeFromDataField(self, fld):
+               """When a column has its DataField changed, we need to set the 
+               correct DataType based on the new value.
+               """
+               if self.Parent:
+                       currDT = self.DataType
+                       dt = self.Parent.typeFromDataField(fld)
+                       if dt is not None and (dt != currDT):
+                               self.DataType = dt
+                               self._updateRenderer()
+                               self._updateEditor()
+
+
        def _getUserSetting(self, prop):
                """Get the property value from the user settings table."""
                app = self.Application
@@ -941,6 +972,8 @@
        def _setDataField(self, val):
                if self._constructed():
                        self._dataField = val
+                       # Use a callAfter, since the parent may not be finished 
instantiating yet.
+                       dabo.ui.callAfter(self._setDataTypeFromDataField, val)
                        if not self.Name or self.Name == "?":
                                self._name = _("col_%s") % val
                        self._updateRenderer()
@@ -1882,6 +1915,22 @@
                #self.SetCellRenderer(row, col, rnd)
 
 
+       def typeFromDataField(self, df):
+               """When the DataField is set for a column, it needs to set the 
corresponding 
+               value of its DataType property. Will return the Python data 
type, or None if 
+               there is no bizobj, or no DataStructure info available in the 
bizobj.
+               """
+               biz = self.getBizobj()
+               if biz is None:
+                       return None
+               try:
+                       pyType = biz.getDataTypeForField(df)
+               except ValueError, e:
+                       dabo.errorLog.write(e)
+                       return None
+               return pyType
+               
+
        def getTableClass(cls):
                """We don't expose the underlying table class to the ui 
namespace, as it's a 
                wx-specific implementation detail, but for cases where you need 
to subclass




_______________________________________________
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