commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8877 - in trunk/gnue-forms/src: . GFObjects uidrivers/curses/wid


From: reinhard
Subject: [gnue] r8877 - in trunk/gnue-forms/src: . GFObjects uidrivers/curses/widgets uidrivers/gtk2/widgets uidrivers/qt3/widgets uidrivers/win32/widgets uidrivers/wx/widgets uidrivers/wx26/widgets
Date: Thu, 19 Oct 2006 14:51:52 -0500 (CDT)

Author: reinhard
Date: 2006-10-19 14:51:50 -0500 (Thu, 19 Oct 2006)
New Revision: 8877

Modified:
   trunk/gnue-forms/src/GFForm.py
   trunk/gnue-forms/src/GFObjects/GFGrid.py
   trunk/gnue-forms/src/GFObjects/GFTabStop.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Fixed UI focus handling, especially for grids.
Don't call rows_changed before the UI is built.


Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py      2006-10-19 15:22:14 UTC (rev 8876)
+++ trunk/gnue-forms/src/GFForm.py      2006-10-19 19:51:50 UTC (rev 8877)
@@ -341,7 +341,7 @@
             if self._currentPage != self._currentEntry._page:
                 self._currentPage = self._currentEntry._page
                 self.uiWidget._ui_goto_page_(self._currentPage.uiWidget)
-            self._currentEntry.ui_focus_in()
+            self._currentEntry.ui_set_focus()
             if hasattr(self._currentEntry, '_displayHandler'):
                 self._currentEntry._displayHandler.generateRefreshEvent()
             raise
@@ -1062,15 +1062,13 @@
 
         self.endEditing()
         old_page = self._currentPage
-        if self._currentEntry is not None:
-            self._currentEntry.ui_focus_out()
         try:
             self.move_focus(widget, row_offset)
             if self._currentPage != old_page:
                 self.uiWidget._ui_goto_page_(self._currentPage.uiWidget)
         finally:
             if self._currentEntry is not None:
-                self._currentEntry.ui_focus_in()
+                self._currentEntry.ui_set_focus()
             self.beginEditing()
 
 

Modified: trunk/gnue-forms/src/GFObjects/GFGrid.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFGrid.py    2006-10-19 15:22:14 UTC (rev 
8876)
+++ trunk/gnue-forms/src/GFObjects/GFGrid.py    2006-10-19 19:51:50 UTC (rev 
8877)
@@ -60,12 +60,17 @@
 
         self._block = self.get_block()
         self.__rows = int(getattr(self, "rows", 1))
-        self.walk(self.__rows_walker)
+        self.walk(self.__init_rows_walker)
         self._block._rows = self.__rows
         self._block.register_scrollbar(self)
 
+    # -------------------------------------------------------------------------
 
+    def __init_rows_walker(self, item):
+        if (item is not self) and isinstance(item, (GFTabStop, GFGridLine)):
+            item._rows = self.__rows
 
+
     # -------------------------------------------------------------------------
     # UI event handlers
     # -------------------------------------------------------------------------
@@ -81,10 +86,7 @@
         self.walk(self.__rows_walker)
         self._block._event_rows_changed(new_rows)
 
-
     # -------------------------------------------------------------------------
-    # Walker function to set the "rows" property for all children
-    # -------------------------------------------------------------------------
 
     def __rows_walker(self, item):
         if (item is not self) and isinstance(item, (GFTabStop, GFGridLine)):

Modified: trunk/gnue-forms/src/GFObjects/GFTabStop.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-10-19 15:22:14 UTC (rev 
8876)
+++ trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-10-19 19:51:50 UTC (rev 
8877)
@@ -250,6 +250,7 @@
             # If this was the currently focused widget, move the focus along
             if self._form.get_focus_object() is self:
                 self.ui_focus_in()
+                self.ui_set_focus()
                 if hasattr(self, '_displayHandler') \
                         and self._displayHandler.editing:
                     self._displayHandler.generateRefreshEvent()
@@ -264,6 +265,8 @@
         Notify the object that it has received the focus.
         """
 
+        self.ui_focus_in()
+
         self.processTrigger('PRE-FOCUSIN')
         self.processTrigger('POST-FOCUSIN')
 
@@ -301,22 +304,66 @@
 
         self.processTrigger('POST-FOCUSOUT')
 
+        self.ui_focus_out()
 
+
     # -------------------------------------------------------------------------
     # UI focus movement
     # -------------------------------------------------------------------------
 
-    def ui_focus_in(self):
+    def ui_set_focus(self):
+        """
+        Set the focus to this widget on the UI layer.
 
+        This function is only called when the focus is set from the GF layer.
+        If the user changes the focus with a mouse click, this function is not
+        called because the UI focus already is on the target widget.
+
+        So the purpose of this function is to make the UI focus follow the GF
+        focus.
+        """
+
         self.uiWidget._ui_set_focus_(self._visibleIndex)
 
     # -------------------------------------------------------------------------
 
+    def ui_focus_in(self):
+        """
+        Notify the UI widget that is is going to receive the focus.
+
+        This function is always called, no matter whether the user requested
+        the focus change via mouse click, keypress, or trigger function.
+
+        The purpose of this function is to allow the UI widget to do things
+        that always must be done when it gets the focus, like changing the
+        color of the current widget, or activating the current entry in the
+        grid.
+        """
+
+        self.uiWidget._ui_focus_in_(self._visibleIndex)
+
+    # -------------------------------------------------------------------------
+
     def ui_focus_out(self):
+        """
+        Notify the UI widget that it has lost the focus.
 
-        self.uiWidget._ui_lose_focus_(self._visibleIndex)
+        This function is always called, no matter whether the user requested
+        the focus change via mouse click, keypress, or trigger function.
 
+        The purpose of this function is to allow the UI widget to do things
+        that always must be done when it loses the focus, like changing the
+        color of the formerly current widget back to normal, or deactivating
+        the no-longer-current entry in the grid.
 
+        This function works better than the KILL-FOCUS event of the UI, because
+        KILL-FOCUS runs too often, for example also when the dropdown is opened
+        (and the focus moves from the dropdown entry to the dropdown list).
+        """
+
+        self.uiWidget._ui_focus_out_(self._visibleIndex)
+
+
 # =============================================================================
 # Base class for all widgets bound to a field
 # =============================================================================
@@ -426,10 +473,6 @@
         if self.hidden:
             return
 
-        if not self.uiWidget:
-            print "refresh_ui called without uiWidget"
-            return
-
         for index in range (from_index, to_index + 1):
             # Do not execute if we were editing - would overwrite unsaved 
change
             if not (index == self._visibleIndex \

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py      2006-10-19 
15:22:14 UTC (rev 8876)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py      2006-10-19 
19:51:50 UTC (rev 8877)
@@ -54,7 +54,7 @@
     self._init (spacer)
 
   # ---------------------------------------------------------------------------
-  # Set focus to widget
+  # Focus handling
   # ---------------------------------------------------------------------------
 
   def _ui_set_focus_(self, index):
@@ -63,10 +63,14 @@
     self._getFocus (index)
 
   # ---------------------------------------------------------------------------
-  # Remove focus from widget
+
+  def _ui_focus_in_(self, index):
+
+    pass
+
   # ---------------------------------------------------------------------------
 
-  def _ui_lose_focus_(self, index):
+  def _ui_focus_out_(self, index):
 
     self._lose_focus (index)
 

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py        2006-10-19 
15:22:14 UTC (rev 8876)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py        2006-10-19 
19:51:50 UTC (rev 8877)
@@ -164,16 +164,11 @@
 
 
   # ---------------------------------------------------------------------------
-  # Set the focus to a given widget
+  # Focus handling
   # ---------------------------------------------------------------------------
 
   def _ui_set_focus_ (self, index):
-    """
-    This function set's the focus to the gtk-widget specified by index. If the
-    widget has a focusHandler it will be blocked and unblocked to prevent a
-    recursion. The focused widget will have a highlight color if it is set
-    in gnue.conf.
-    """
+
     widget = self.widgets [index]
     assert gDebug (6, "indexed_focus: %s [%s]" % (widget, index))
 
@@ -184,8 +179,21 @@
     assert gDebug (6, "Grab focus to %s for %s" % (item, widget))
     item.grab_focus ()
 
+    # To avoid the automatic select-all in a combo box, we explicitly set the
+    # selection to the current position only
+    if isinstance (widget, gtk.ComboBoxEntry):
+      pos = item.get_position ()
+      item.select_region (pos, pos)
 
+    self._blockHandler (item, '_focusHandler', True)
+
+  # ---------------------------------------------------------------------------
+
+  def _ui_focus_in_(self, index):
+
     # Change the background of a widget if requested via gnue.conf
+    widget = self.widgets [index]
+    item = isinstance (widget, gtk.ComboBoxEntry) and widget.child or widget
     if gConfigForms ('focusColor'):
       focusColor = gtk.gdk.color_parse ('#' + gConfigForms ('focusColor'))
       mode   = ['base', 'bg'] [isinstance (item, gtk.Button)]
@@ -197,21 +205,9 @@
 
       setcol (gtk.STATE_NORMAL, focusColor)
 
-
-    # To avoid the automatic select-all in a combo box, we explicitly set the
-    # selection to the current position only
-    if isinstance (widget, gtk.ComboBoxEntry):
-      pos = item.get_position ()
-      item.select_region (pos, pos)
-
-    self._blockHandler (item, '_focusHandler', True)
-
-
   # ---------------------------------------------------------------------------
-  # On lose of the focus we un-select ComboBox-Entries
-  # ---------------------------------------------------------------------------
 
-  def _ui_lose_focus_ (self, index):
+  def _ui_focus_out_(self, index):
 
       widget = self.widgets[index]
       assert gDebug (6, "Lose focus: %s" % widget)

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py 2006-10-19 15:22:14 UTC 
(rev 8876)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/_base.py 2006-10-19 19:51:50 UTC 
(rev 8877)
@@ -51,35 +51,28 @@
 
 
     # -------------------------------------------------------------------------
-    # Set the focus to the given widget
+    # Focus handling
     # -------------------------------------------------------------------------
 
     def _ui_set_focus_(self, index):
-        """
-        Set the focus to the qt widget specified by index.  For entries having
-        no rows the index will always be 0.
 
-        @param index: the index of the qt widget to set the focus to
-        """
         widget = self.widgets[index]
         if widget:
             widget.setFocus()
 
+    # -------------------------------------------------------------------------
 
+    def _ui_focus_out_(self, index):
+
+        pass
+
     # -------------------------------------------------------------------------
-    # The focus should move away from a widget
-    # -------------------------------------------------------------------------
 
-    def _ui_lose_focus_(self, index):
-        """
-        Take away the focus of the qt widget with the given index.  If this
-        object is used within a grid, losing the focus means hiding the entry
-        widget and displaying the label widget.
+    def _ui_focus_out_(self, index):
 
-        @param index: the index of the qt widget to kill the focus for
-        """
         pass
 
+
 # =============================================================================
 # Base class for H/V-Boxes in a managed layout
 # =============================================================================

Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py       2006-10-19 
15:22:14 UTC (rev 8876)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py       2006-10-19 
19:51:50 UTC (rev 8877)
@@ -694,9 +694,12 @@
   def _ui_set_focus_(self, index):
     self.widgets[index].SetFocus()
 
-  def _ui_lose_focus_(self, index):
+  def _ui_focus_in_(self, index):
     pass
 
+  def _ui_focus_out_(self, index):
+    pass
+
   def _ui_set_value_(self, index, value):
     widget = self.widgets[index]
     # Check if foreign key changed

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py  2006-10-19 15:22:14 UTC 
(rev 8876)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/_base.py  2006-10-19 19:51:50 UTC 
(rev 8877)
@@ -114,38 +114,36 @@
 
 
   # --------------------------------------------------------------------------
-  # Set the focus to a given widget
+  # Focus handling
   # --------------------------------------------------------------------------
+
   def _ui_set_focus_(self, index):
-    """
-    Sets the focus to the wx widget specified by index.
-    The focused widget will have a highlight color if it is set in gnue.conf.
-    """
+
     widget = self.widgets[index]
     widget.__focused = True
+    widget.SetFocus()
 
+  # --------------------------------------------------------------------------
+
+  def _ui_focus_in_(self, index):
+
     #Make the focused widget's color different
     #if focus color is set in gnue.conf.
     #We store the widget's original color so we can set it back to normal
     #when it loses focus.
     #TODO: CheckButtons don't get colored...
+    widget = self.widgets[index]
     if self._uiDriver._focusColour:
       try:
         widget.__color
       except:
         widget.__color = widget.GetBackgroundColour()
       widget.SetBackgroundColour(self._uiDriver._focusColour)
-    widget.SetFocus()
 
-
   # --------------------------------------------------------------------------
-  # On lose of the focus we un-select ComboBox-Entries
-  # --------------------------------------------------------------------------
-  def _ui_lose_focus_(self, index):
-    """
-    Releases focus from the widget that currently had it.
-    Resets the widget's color to normal if focus highlighting is used.
-    """
+
+  def _ui_focus_out_(self, index):
+
     widget = self.widgets[index]
     widget.__focused = False
     try:

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-10-19 
15:22:14 UTC (rev 8876)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-10-19 
19:51:50 UTC (rev 8877)
@@ -104,17 +104,11 @@
 
 
     # -------------------------------------------------------------------------
-    # Set the focus to a given widget
+    # Focus handling
     # -------------------------------------------------------------------------
 
     def _ui_set_focus_(self, index):
-        """
-        Set the focus to the wx widget specified by index.  For entries having
-        no rows the index will always be 0.
 
-        @param index: the index of the wx widget to set the focus to
-        """
-
         widget = self.widgets[index]
         if isinstance(widget, wx.ComboBox) and 'wxMac' in wx.PlatformInfo:
             item = widget._entry
@@ -122,21 +116,31 @@
             item = widget
         item.SetFocus()
 
+    # -------------------------------------------------------------------------
 
+    def _ui_focus_in_(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()
+
     # -------------------------------------------------------------------------
-    # On lose of the focus we un-select ComboBox-Entries
-    # -------------------------------------------------------------------------
 
-    def _ui_lose_focus_(self, index):
-        """
-        Take away the focus of the wx widget with the given index.  If this
-        object is used within a grid, losing the focus means hiding the entry
-        widget and displaying the label widget.
+    def _ui_focus_out_(self, index):
 
-        @param index: the index of the wx widget to kill the focus for
-        """
+        # If we are in a grid, exchange entry widget with the label
+        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-19 
15:22:14 UTC (rev 8876)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-10-19 
19:51:50 UTC (rev 8877)
@@ -102,7 +102,6 @@
 
         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
@@ -140,7 +139,6 @@
         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
 
@@ -171,7 +169,6 @@
         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:
@@ -195,7 +192,6 @@
 
         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,6 +232,7 @@
                 if item.IsEnabled():
                     # This replaces the label with the actual entry and sets
                     # the focus on the entry
+                    self._ui_focus_in_(self.widgets.index(item))
                     self._ui_set_focus_(self.widgets.index(item))
 
                 break
@@ -255,18 +252,6 @@
 
     # -------------------------------------------------------------------------
 
-    def __on_kill_focus(self, event):
-
-        event.Skip()
-        # 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()
@@ -410,25 +395,6 @@
 
 
     # -------------------------------------------------------------------------
-    # 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)
-
-
-    # -------------------------------------------------------------------------
     # Set the value of a widget
     # -------------------------------------------------------------------------
 





reply via email to

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