commit-gnue
[Top][All Lists]
Advanced

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

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


From: johannes
Subject: [gnue] r8245 - trunk/gnue-forms/src/uidrivers/wx26/widgets
Date: Mon, 3 Apr 2006 18:20:03 -0500 (CDT)

Author: johannes
Date: 2006-03-21 13:29:49 -0600 (Tue, 21 Mar 2006)
New Revision: 8245

Modified:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Better handling of focus requests of wx.widgets


Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-03-20 
15:51:47 UTC (rev 8244)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-03-21 
19:29:49 UTC (rev 8245)
@@ -94,7 +94,7 @@
     result = wx.TextCtrl (parent, -1, '', self.__pos, self.__size, xFlags)
 
     result.Bind (wx.EVT_CHAR, self.__keypress)
-    result.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+    result.Bind (wx.EVT_SET_FOCUS, self.__on_set_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 keypress event
@@ -128,7 +128,7 @@
 
     result = wx.CheckBox (parent, -1, self._gfObject.label, self.__pos)
     result.Bind (wx.EVT_CHECKBOX, self.__toggleCheckbox)
-    result.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+    result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
 
     return result
 
@@ -158,7 +158,7 @@
 
     result.Bind (wx.EVT_COMBOBOX, self.__itemSelected)
     item.Bind (wx.EVT_CHAR, self.__keypress)
-    item.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+    item.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
 
     # On Mac we don't bind the button release event, as it does not get fired
     if not 'wxMac' in wx.PlatformInfo:
@@ -182,19 +182,16 @@
     self._updateChoices (result)
 
     result.Bind (wx.EVT_LISTBOX, self.__itemSelected)
-    result.Bind (wx.EVT_SET_FOCUS, self.__setFocus)
+    result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
 
     return result
 
 
   # ---------------------------------------------------------------------------
-  # Make sure to keep the focus in gf-layer in sync with the UI
-  # ---------------------------------------------------------------------------
 
-  def __setFocus (self, event):
+  def __on_set_focus (self, event):
 
-    if self._form._currentEntry != self._gfObject:
-      wx.CallAfter (self._request, 'FOCUS', data = self._gfObject)
+    doFocus = (self._form._currentEntry != self._gfObject)
 
     # adjust the record number if necessary
     lookup = event.GetEventObject ()
@@ -203,13 +200,51 @@
 
     count  = self.widgets.index (lookup)
     adjust = count - self._gfObject._visibleIndex
-    if adjust:
-      wx.CallAfter (self._request, 'JUMPRECORD', data = adjust)
 
+    # 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.__focusWorker, event.GetEventObject (), doFocus, adjust)
+
     event.Skip ()
 
 
+
   # ---------------------------------------------------------------------------
+  # Do the dirty work for moving the focus and adjusting the row
+  # ---------------------------------------------------------------------------
+
+  def __focusWorker (self, widget, doFocus = 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 hasattr (widget, 'GetInsertionPoint'):
+      args = (widget.GetInsertionPoint (),)
+      restore = widget.SetInsertionPoint
+
+    else:
+      restore = None
+
+    if doFocus:
+      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)
+
+
+  # ---------------------------------------------------------------------------
   # Release of the left mouse-button for textcontrols and combos
   # ---------------------------------------------------------------------------
 





reply via email to

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