commit-gnue
[Top][All Lists]
Advanced

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

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


From: reinhard
Subject: [gnue] r8723 - trunk/gnue-forms/src/uidrivers/wx26/widgets
Date: Tue, 10 Oct 2006 07:54:25 -0500 (CDT)

Author: reinhard
Date: 2006-10-10 07:54:24 -0500 (Tue, 10 Oct 2006)
New Revision: 8723

Modified:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Moved stuff from _base to entry that only is necessary in entry.


Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-10-10 
12:01:49 UTC (rev 8722)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-10-10 
12:54:24 UTC (rev 8723)
@@ -26,7 +26,6 @@
 """
 
 import wx
-import os
 
 from gnue.common.definitions import GParser
 from gnue.forms.GFObjects import GFTabStop, GFBox, GFScrollBar, GFLabel
@@ -272,119 +271,6 @@
 
 
     # -------------------------------------------------------------------------
-    # Set the value of a widget
-    # FIXME: Could this function and the next 2 be moved to entry.py?
-    # -------------------------------------------------------------------------
-
-    def _ui_set_value_(self, index, value):
-        """
-        This function sets the value of a widget and optionally enables or
-        disables the widget.
-        """
-
-        widget = self.widgets[index]
-
-        if not widget:
-            return
-
-        widget.SetEvtHandlerEnabled (False)
-
-        try:
-            if self._gfObject.style in ['dropdown', 'listbox']:
-                field = self._gfObject._field
-                if field._allowedValues != widget._orig_allowed_values:
-                    self.update_choices (widget)
-
-            if isinstance (widget, wx.StaticText):
-                widget.SetLabel (value)
-
-            elif isinstance (widget, wx.ListBox):
-                if value:
-                    widget.SetStringSelection (value, True)
-
-            elif isinstance(widget, wx.CheckBox):
-                if value is None:
-                    widget.Set3StateValue(wx.CHK_UNDETERMINED)
-                elif value:
-                    widget.Set3StateValue(wx.CHK_CHECKED)
-                else:
-                    widget.Set3StateValue(wx.CHK_UNCHECKED)
-
-            else:
-                if isinstance (widget, wx.ComboBox):
-                    # We use SetStringSelection to keep the selected index in
-                    # sync with the string value (e.g. in Choice-Controls on OS
-                    # X)
-                    if not widget.SetStringSelection (value):
-                        widget.SetValue (value)
-                else:
-                    widget.SetValue (value)
-
-        finally:
-            if self.in_grid and widget._gnue_label_:
-                if isinstance(widget._gnue_label_, wx.StaticText):
-                    widget._gnue_label_.SetLabel("%s" % value)
-                else:
-                    widget._gnue_label_.SetValue(value)
-
-            widget.SetEvtHandlerEnabled (True)
-            widget.Refresh ()
-
-
-    # ------------------------------------------------------------------------
-    # Set the cursor's location in a widget
-    # ------------------------------------------------------------------------
-
-    def _ui_set_cursor_position_(self, index, position):
-        """
-        Set the cursor position to the given location inside a capable widget.
-
-        @param position: new position of the insertion point
-        @param index: index of the widget to be changed (if rows > 0)
-        """
-
-        widget = self.widgets[index]
-
-        if isinstance (widget, wx.ComboBox):
-            if 'wxMac' in wx.PlatformInfo:
-                widget._entry.SetInsertionPoint (position)
-            else:
-                widget.SetMark (position, position)
-
-        elif hasattr (widget, 'SetInsertionPoint'):
-            widget.SetInsertionPoint (self.__position_to_wx (widget, position))
-
-
-    # ------------------------------------------------------------------------
-    # Set the selection inside a widget
-    # ------------------------------------------------------------------------
-
-    def _ui_set_selected_area_(self, index, selection1, selection2):
-        """
-        Sets the selection start/end inside a capable widget.
-
-        @param selection1: start position of the selection
-        @param selection2: end position of the selection
-        @param index: index of the widget to be changed
-        """
-    
-        widget = self.widgets[index]
-
-        if isinstance (widget, wx.ComboBox):
-            if 'wxMac' in wx.PlatformInfo:
-                widget._entry.SetSelection (selection1, selection2)
-            else:
-                widget.SetMark (selection1, selection2)
-
-        elif hasattr (widget, 'SetSelection'):
-            if isinstance (widget, wx.TextCtrl) and widget.IsMultiLine ():
-                selection1 = self.__position_to_wx (widget, selection1)
-                selection2 = self.__position_to_wx (widget, selection2)
-
-            widget.SetSelection (selection1, selection2)
-
-
-    # -------------------------------------------------------------------------
     # Add a widget into a vertical box sizer
     # -------------------------------------------------------------------------
 
@@ -464,49 +350,6 @@
             widget.Thaw()
 
 
-    # -------------------------------------------------------------------------
-    # Convert a GF-position to a wx position within a multiline edit
-    # -------------------------------------------------------------------------
-
-    def __position_to_wx(self, widget, position):
-
-        if len(os.linesep) < 2 or not position:
-            return position
-
-        text = widget.GetValue()[:position]
-        num  = text.count('\n')
-        result = position + num
-
-        return result
-
-
-    # -------------------------------------------------------------------------
-    # Convert a wx position to a GF position within a multiline edit
-    # -------------------------------------------------------------------------
-
-    def _wx_to_position(self, widget, position):
-        """
-        Convert a wx position within a multiline edit into a position suitable
-        for a GFEntry widget.  This method treats different lineendings used by
-        the various OSes correct.
-
-        @param widget: the wx control the convert the position for
-        @param position: the current position to be converted
-
-        @returns: the converted position usable for GFEntry intances (and their
-            displayhandler)
-        """
-
-        if len(os.linesep) < 2 or not position:
-            return position
-
-        text   = widget.GetValue().replace('\n', os.linesep)[:position]
-        num    = text.count(os.linesep)
-        result = max(0, position - num)
-
-        return result
-
-
     # =========================================================================
     # Virtual methods
     # =========================================================================

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-10-10 
12:01:49 UTC (rev 8722)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-10-10 
12:54:24 UTC (rev 8723)
@@ -24,6 +24,7 @@
 Implementation of the <entry> tag
 """
 
+import os
 import wx
 
 from gnue.forms.uidrivers.wx26.widgets import _base
@@ -143,7 +144,6 @@
 
         return [label, result]
 
-
     # -------------------------------------------------------------------------
 
     def __build_dropdown(self, parent):
@@ -195,7 +195,6 @@
 
         return [self.__add_entry_label(parent), result]
 
-
     # -------------------------------------------------------------------------
 
     def __add_entry_label(self, parent):
@@ -249,10 +248,7 @@
 
         event.Skip()
 
-
     # -------------------------------------------------------------------------
-    # Event handler
-    # -------------------------------------------------------------------------
 
     def __on_set_focus(self, event):
 
@@ -271,10 +267,7 @@
 
         event.Skip()
 
-
     # -------------------------------------------------------------------------
-    # Release of the left mouse-button for textcontrols and combos
-    # -------------------------------------------------------------------------
 
     def __on_left_mouseup(self, event):
 
@@ -283,19 +276,13 @@
 
         wx.CallAfter(self.__update_insertion_point, widget)
 
-
     # -------------------------------------------------------------------------
-    # Toggle the state of a checkbox
-    # -------------------------------------------------------------------------
 
     def __on_toggle_checkbox(self, event):
 
         self._request('TOGGLECHKBOX')
 
-
     # -------------------------------------------------------------------------
-    # An item of a listbox has been selected
-    # -------------------------------------------------------------------------
 
     def __on_item_selected(self, event):
 
@@ -309,10 +296,7 @@
             self._request('REPLACEVALUE', index=event.GetSelection(),
                                           text=event.GetString())
 
-
     # -------------------------------------------------------------------------
-    # Process a key-press in an entry
-    # -------------------------------------------------------------------------
 
     def __on_keypress(self, event):
 
@@ -388,6 +372,7 @@
         # prevent it from changing options in dropdowns
         event.StopPropagation()
 
+
     # -------------------------------------------------------------------------
     # Do the dirty work for moving the focus and adjusting the row
     # -------------------------------------------------------------------------
@@ -437,8 +422,8 @@
             (left, right) = widget.GetSelection()
 
             if widget.IsMultiLine():
-                left  = self._wx_to_position(widget, left)
-                right = self._wx_to_position(widget, right)
+                left  = self.__wx_to_position(widget, left)
+                right = self.__wx_to_position(widget, right)
 
         elif isinstance(widget, wx.ComboBox):
             if 'wxMac' in wx.PlatformInfo:
@@ -468,6 +453,158 @@
         self.widgets[index].Enable(False)
 
 
+    # -------------------------------------------------------------------------
+    # Set the value of a widget
+    # -------------------------------------------------------------------------
+
+    def _ui_set_value_(self, index, value):
+        """
+        This function sets the value of a widget and optionally enables or
+        disables the widget.
+        """
+
+        widget = self.widgets[index]
+
+        if not widget:
+            return
+
+        widget.SetEvtHandlerEnabled (False)
+
+        try:
+            if self._gfObject.style in ['dropdown', 'listbox']:
+                field = self._gfObject._field
+                if field._allowedValues != widget._orig_allowed_values:
+                    self.update_choices (widget)
+
+            if isinstance (widget, wx.StaticText):
+                widget.SetLabel (value)
+
+            elif isinstance (widget, wx.ListBox):
+                if value:
+                    widget.SetStringSelection (value, True)
+
+            elif isinstance(widget, wx.CheckBox):
+                if value is None:
+                    widget.Set3StateValue(wx.CHK_UNDETERMINED)
+                elif value:
+                    widget.Set3StateValue(wx.CHK_CHECKED)
+                else:
+                    widget.Set3StateValue(wx.CHK_UNCHECKED)
+
+            else:
+                if isinstance (widget, wx.ComboBox):
+                    # We use SetStringSelection to keep the selected index in
+                    # sync with the string value (e.g. in Choice-Controls on OS
+                    # X)
+                    if not widget.SetStringSelection (value):
+                        widget.SetValue (value)
+                else:
+                    widget.SetValue (value)
+
+        finally:
+            if self.in_grid and widget._gnue_label_:
+                if isinstance(widget._gnue_label_, wx.StaticText):
+                    widget._gnue_label_.SetLabel("%s" % value)
+                else:
+                    widget._gnue_label_.SetValue(value)
+
+            widget.SetEvtHandlerEnabled (True)
+            widget.Refresh ()
+
+
+    # ------------------------------------------------------------------------
+    # Set the cursor's location in a widget
+    # ------------------------------------------------------------------------
+
+    def _ui_set_cursor_position_(self, index, position):
+        """
+        Set the cursor position to the given location inside a capable widget.
+
+        @param position: new position of the insertion point
+        @param index: index of the widget to be changed (if rows > 0)
+        """
+
+        widget = self.widgets[index]
+
+        if isinstance (widget, wx.ComboBox):
+            if 'wxMac' in wx.PlatformInfo:
+                widget._entry.SetInsertionPoint (position)
+            else:
+                widget.SetMark (position, position)
+
+        elif hasattr (widget, 'SetInsertionPoint'):
+            widget.SetInsertionPoint (self.__position_to_wx (widget, position))
+
+
+    # ------------------------------------------------------------------------
+    # Set the selection inside a widget
+    # ------------------------------------------------------------------------
+
+    def _ui_set_selected_area_(self, index, selection1, selection2):
+        """
+        Sets the selection start/end inside a capable widget.
+
+        @param selection1: start position of the selection
+        @param selection2: end position of the selection
+        @param index: index of the widget to be changed
+        """
+    
+        widget = self.widgets[index]
+
+        if isinstance (widget, wx.ComboBox):
+            if 'wxMac' in wx.PlatformInfo:
+                widget._entry.SetSelection (selection1, selection2)
+            else:
+                widget.SetMark (selection1, selection2)
+
+        elif hasattr (widget, 'SetSelection'):
+            if isinstance (widget, wx.TextCtrl) and widget.IsMultiLine ():
+                selection1 = self.__position_to_wx (widget, selection1)
+                selection2 = self.__position_to_wx (widget, selection2)
+
+            widget.SetSelection (selection1, selection2)
+
+
+    # -------------------------------------------------------------------------
+    # Helper functions to convert internal to wx position and back
+    # -------------------------------------------------------------------------
+
+    def __position_to_wx(self, widget, position):
+
+        if len(os.linesep) < 2 or not position:
+            return position
+
+        text = widget.GetValue()[:position]
+        num  = text.count('\n')
+        result = position + num
+
+        return result
+
+    # -------------------------------------------------------------------------
+
+    def __wx_to_position(self, widget, position):
+        """
+        Convert a wx position within a multiline edit into a position suitable
+        for a GFEntry widget.  This method treats different lineendings used by
+        the various OSes correct.
+
+        @param widget: the wx control the convert the position for
+        @param position: the current position to be converted
+
+        @returns: the converted position usable for GFEntry intances (and their
+            displayhandler)
+        """
+
+        if len(os.linesep) < 2 or not position:
+            return position
+
+        text   = widget.GetValue().replace('\n', os.linesep)[:position]
+        num    = text.count(os.linesep)
+        result = max(0, position - num)
+
+        return result
+
+
 # =============================================================================
 # Configuration
 # =============================================================================





reply via email to

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