commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r8852 - trunk/gnue-forms/src/uidrivers/wx26/widgets


From: reinhard
Subject: [gnue] r8852 - trunk/gnue-forms/src/uidrivers/wx26/widgets
Date: Wed, 18 Oct 2006 10:38:28 -0500 (CDT)

Author: reinhard
Date: 2006-10-18 10:38:28 -0500 (Wed, 18 Oct 2006)
New Revision: 8852

Modified:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Fixed focus handling in grids. Things seem to have become a lot easier now
actually.


Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-10-18 
15:01:21 UTC (rev 8851)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-10-18 
15:38:28 UTC (rev 8852)
@@ -116,19 +116,10 @@
         """
 
         widget = self.widgets[index]
-        if self.in_grid and widget._gnue_label_:
-            label = widget._gnue_label_
-            widget.Show()
-            label.Hide()
-            sizer = widget.GetContainingSizer()
-            if sizer:
-                sizer.Layout()
-
         if isinstance(widget, wx.ComboBox) and 'wxMac' in wx.PlatformInfo:
             item = widget._entry
         else:
             item = widget
-
         item.SetFocus()
 
 
@@ -145,11 +136,7 @@
         @param index: the index of the wx widget to kill the focus for
         """
 
-        widget = self.widgets[index]
-        if self.in_grid and widget._gnue_label_:
-            widget.Hide()
-            widget._gnue_label_.Show()
-            widget.GetContainingSizer().Layout()
+        pass
 
 
     # -------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-10-18 
15:01:21 UTC (rev 8851)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-10-18 
15:38:28 UTC (rev 8852)
@@ -102,6 +102,7 @@
 
         ctrl.Bind(wx.EVT_CHAR, self.__on_keypress)
         ctrl.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
+        ctrl.Bind(wx.EVT_KILL_FOCUS, self.__on_kill_focus)
 
         # Currently wxMac does *not* recieve a button release event, so we
         # don't bind it here. Instead we check the insertion point in the
@@ -139,6 +140,7 @@
         result.Bind (wx.EVT_CHECKBOX, self.__on_toggle_checkbox)
         result.Bind (wx.EVT_CHAR, self.__on_keypress)
         result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
+        result.Bind (wx.EVT_KILL_FOCUS, self.__on_kill_focus)
 
         label = None
 
@@ -169,6 +171,7 @@
         result.Bind(wx.EVT_COMBOBOX, self.__on_item_selected)
         item.Bind(wx.EVT_CHAR, self.__on_keypress)
         item.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
+        item.Bind(wx.EVT_KILL_FOCUS, self.__on_kill_focus)
 
         # On MSW we don't get all keys in wx.EVT_CHAR, so we have to bind keyup
         if 'wxMSW' in wx.PlatformInfo:
@@ -192,6 +195,7 @@
 
         result.Bind(wx.EVT_LISTBOX, self.__on_item_selected)
         result.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
+        result.Bind(wx.EVT_KILL_FOCUS, self.__on_kill_focus)
 
         return [self.__add_entry_label(parent), result]
 
@@ -236,15 +240,9 @@
                 count  = self.widgets.index(lookup)
                 adjust = count - self._gfObject._visibleIndex
 
-        # Now follows a quite dirty trick.  The current widget does not have an
-        # insertion point set yet, which happens after wx.EVT_SET_FOCUS is
-        # processed.  Calling a requestFOCUS event sets the insertion point to
-        # the end of the display value (via beginEDIT).  So the real insertion
-        # point (of a mouse click for example) always gets lost.  To resolve
-        # that do all the dirty work of synchronizing the focus in GF *after*
-        # setting the initial wx-focus.
-                wx.CallAfter (self.__focus_worker, event.GetEventObject(),
-                        do_focus, adjust)
+                # This replaces the label with the actual entry and sets the
+                # focus on the entry
+                self._ui_set_focus_(count)
 
         event.Skip()
 
@@ -262,13 +260,27 @@
         count  = self.widgets.index(lookup)
         adjust = count - self._gfObject._visibleIndex
 
-        if do_focus or adjust:
-            self.__focus_worker(event.GetEventObject(), do_focus, adjust)
+        if do_focus:
+            self._request('FOCUS', data=self._gfObject)
 
+        if adjust:
+            self._request('JUMPRECORD', data=adjust)
+
         event.Skip()
 
     # -------------------------------------------------------------------------
 
+    def __on_kill_focus(self, event):
+
+        # If we are in a grid, exchange entry widget with the label
+        widget = event.GetEventObject()
+        if self.in_grid and widget._gnue_label_:
+            widget.Hide()
+            widget._gnue_label_.Show()
+            widget.GetContainingSizer().Layout()
+
+    # -------------------------------------------------------------------------
+
     def __on_left_mouseup(self, event):
 
         widget = event.GetEventObject()
@@ -371,40 +383,6 @@
 
 
     # -------------------------------------------------------------------------
-    # Do the dirty work for moving the focus and adjusting the row
-    # -------------------------------------------------------------------------
-
-    def __focus_worker(self, widget, do_focus=False, adjust=0):
-
-        # Before changing the focus in the GFForm, let's save the current
-        # insertion point for later restoring.
-        if isinstance(widget, wx.ComboBox):
-            args = widget.GetMark()
-            restore = widget.SetMark
-
-        elif isinstance(widget, wx.TextCtrl):
-            args = widget.GetSelection()
-            restore = widget.SetSelection
-
-        elif hasattr(widget, 'GetInsertionPoint'):
-            args = (widget.GetInsertionPoint(),)
-            restore = widget.SetInsertionPoint
-
-        else:
-            restore = None
-
-        if do_focus:
-            self._request('FOCUS', data=self._gfObject)
-
-        if adjust:
-            self._request('JUMPRECORD', data=adjust)
-
-        # Restore an insertion point (if the widget has something like that)
-        if restore is not None:
-            restore(*args)
-
-
-    # -------------------------------------------------------------------------
     # Make sure the insertion point or selection of a widget is in sync with 
GF*
     # -------------------------------------------------------------------------
 
@@ -446,6 +424,34 @@
 
 
     # -------------------------------------------------------------------------
+    # Set the focus to a given widget
+    # -------------------------------------------------------------------------
+
+    def _ui_set_focus_(self, index):
+
+        # If we are in a grid, exchange label with entry widget
+        widget = self.widgets[index]
+        if self.in_grid and widget._gnue_label_:
+            label = widget._gnue_label_
+            widget.Show()
+            label.Hide()
+            sizer = widget.GetContainingSizer()
+            if sizer:
+                sizer.Layout()
+
+        _base.UIHelper._ui_set_focus_(self, index)
+
+
+    # -------------------------------------------------------------------------
+    # On lose of the focus we un-select ComboBox-Entries
+    # -------------------------------------------------------------------------
+
+    def _ui_lose_focus_(self, index):
+
+        _base.UIHelper._ui_lose_focus_(self, index)
+
+
+    # -------------------------------------------------------------------------
     # Set the value of a widget
     # -------------------------------------------------------------------------
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]