dabo Commit
Revision 6898
Date: 2011-10-13 14:33:14 -0700 (Thu, 13 Oct 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6898

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

Log:
Remapped most of the grid editors to instances of dTextBox. Augmented
the dTextBox editor to respond to up/down arrow keys to behave like
a non-editable grid and move the pointer up and down.

For the test dGrid, I set TabNavigates to False.



Diff:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py      2011-10-13 11:08:13 UTC (rev 6897)
+++ trunk/dabo/ui/uiwx/__init__.py      2011-10-13 21:33:14 UTC (rev 6898)
@@ -14,6 +14,7 @@
 from dabo.lib.utils import ustr
 from dabo.lib import utils
 import dabo.dEvents as dEvents
+import dKeys
 
 # Very VERY first thing: ensure a minimal wx is selected, but only if
 # wx hasn't already been imported, and if we aren't running frozen:
@@ -1415,7 +1416,7 @@
        return mb
 
 
-def makeGridEditor(controlClass, minWidth=None, minHeight=None):
+def makeGridEditor(controlClass, minWidth=None, minHeight=None, 
**controlProps):
        class _BaseCellEditor(wx.grid.PyGridCellEditor):
                _controlClass = None
                _minWidth = None
@@ -1430,11 +1431,36 @@
                        """
                        if not self._controlClass:
                                raise TypeError(_("Cannot create custom editor 
without a control class specified."))
-                       self._control = self._controlClass(parent)
+                       self._control = self._controlClass(parent, 
**controlProps)
+                       self._grid = parent.GetParent()
+                       self._control.bindEvent(dabo.dEvents.KeyDown, 
self._onKeyDown)
                        self.SetControl(self._control)
                        if evtHandler:
                                self._control.PushEventHandler(evtHandler)
 
+               def _onKeyDown(self, evt):
+                       ed = evt.EventData
+                       key, mod, shift = (ed["keyCode"], ed["hasModifiers"], 
+                                       ed["shiftDown"] or getattr(self, 
"_shiftDown", False))
+                       ctrl = self._control
+                       grid = self._grid
+
+                       if key == dKeys.key_Up and not mod and not shift:
+                               grid.HideCellEditControl()
+                               row = grid.CurrentRow - 1
+                               if row < 0:
+                                       row = 0
+                               grid.CurrentRow = row
+                               evt.stop()
+
+                       elif key == dKeys.key_Down and not mod and not shift:
+                               grid.HideCellEditControl()
+                               row = grid.CurrentRow + 1
+                               if row > grid.RowCount - 1:
+                                       row = grid.RowCount + 1
+                               grid.CurrentRow = row
+                               evt.stop()
+
                def SetSize(self, rect):
                        """
                        Called to position/size the edit control within the 
cell rectangle.
@@ -1526,12 +1552,13 @@
                def Clone(self):
                        """
                        Create a new object which is the copy of this one
-                       
-                       *Must Override*
-                       
                        """
+                       # pkm: I'm not seeing this method ever called. If it is 
ever called,
+                       #      the following line will make that clear. :)
+                       1/0
                        return self.__class__
 
+
        class _CustomEditor(_BaseCellEditor):
                _controlClass = controlClass
                _minWidth = minWidth

Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2011-10-13 11:08:13 UTC (rev 6897)
+++ trunk/dabo/ui/uiwx/dGrid.py 2011-10-13 21:33:14 UTC (rev 6898)
@@ -482,13 +482,13 @@
                self.floatRendererClass = wx.grid.GridCellFloatRenderer
                self.listRendererClass = wx.grid.GridCellStringRenderer
                self.imageRendererClass = gridRenderers.ImageRenderer
-               self.stringEditorClass = wx.grid.GridCellTextEditor
+               self.stringEditorClass = 
dabo.ui.makeGridEditor(dabo.ui.dTextBox) ##wx.grid.GridCellTextEditor
                self.wrapStringEditorClass = 
wx.grid.GridCellAutoWrapStringEditor
                self.boolEditorClass = wx.grid.GridCellBoolEditor
-               self.intEditorClass = wx.grid.GridCellNumberEditor
-               self.longEditorClass = wx.grid.GridCellNumberEditor
-               self.decimalEditorClass = wx.grid.GridCellFloatEditor
-               self.floatEditorClass = wx.grid.GridCellFloatEditor
+               self.intEditorClass = dabo.ui.makeGridEditor(dabo.ui.dTextBox, 
Alignment="Right") ##wx.grid.GridCellNumberEditor
+               self.longEditorClass = dabo.ui.makeGridEditor(dabo.ui.dTextBox, 
Alignment="Right") ##wx.grid.GridCellNumberEditor
+               self.decimalEditorClass = 
dabo.ui.makeGridEditor(dabo.ui.dTextBox, Alignment="Right") 
##wx.grid.GridCellFloatEditor
+               self.floatEditorClass = 
dabo.ui.makeGridEditor(dabo.ui.dTextBox, Alignment="Right") 
##wx.grid.GridCellFloatEditor
                self.listEditorClass = wx.grid.GridCellChoiceEditor
 #              self.listEditorClass = GridListEditor
 
@@ -514,6 +514,7 @@
                        "string" : self.stringEditorClass,
                        "bool" : self.boolEditorClass,
                        "int" : self.intEditorClass,
+                       "integer" : self.intEditorClass,
                        "long" : self.longEditorClass,
                        "decimal" : self.decimalEditorClass,
                        "float" : self.floatEditorClass,
@@ -3731,7 +3732,6 @@
                        evt.stop()
                        self.Navigate(not evt.EventData["shiftDown"])
 
-
        def _onKeyChar(self, evt):
                """Occurs when the user presses a key inside the grid."""
                if (self.Editable and self.Columns[self.CurrentColumn].Editable
@@ -5156,7 +5156,8 @@
                        for i in range(20):
                                ds[row]["i_%s" % i] = "sss%s" % i
                self.DataSet = ds
-
+       
+               self.TabNavigates = False
                self.Width = 360
                self.Height = 150
                self.Editable = 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