commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9061 - in trunk/gnue-forms/src: GFObjects uidrivers/curses/widge


From: johannes
Subject: [gnue] r9061 - in trunk/gnue-forms/src: GFObjects uidrivers/curses/widgets uidrivers/gtk2/widgets uidrivers/qt3/widgets uidrivers/wx/widgets uidrivers/wx26/widgets
Date: Fri, 24 Nov 2006 03:46:10 -0600 (CST)

Author: johannes
Date: 2006-11-24 03:46:08 -0600 (Fri, 24 Nov 2006)
New Revision: 9061

Modified:
   trunk/gnue-forms/src/GFObjects/GFField.py
   trunk/gnue-forms/src/GFObjects/GFTabStop.py
   trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Added a _ui_set_choices_() method for controls with items 
(listbox/dropdown).  This method get's called whenever the list of 
available choices has changed.


Modified: trunk/gnue-forms/src/GFObjects/GFField.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFField.py   2006-11-23 13:36:09 UTC (rev 
9060)
+++ trunk/gnue-forms/src/GFObjects/GFField.py   2006-11-24 09:46:08 UTC (rev 
9061)
@@ -451,6 +451,9 @@
         # Remember the resultSet for later
         self.__fk_resultSet = resultSet
 
+        # Update the list of choices in all entries bound to this field
+        self.__refresh_ui_choices()
+
         # Update the UI to also for other rows
         self.__refresh_ui_all()
  
@@ -487,7 +490,17 @@
         for entry in self._entryList:
             entry.refresh_ui_all()
 
+    # -------------------------------------------------------------------------
 
+    def __refresh_ui_choices(self):
+
+        choices = self._allowedValuesDescr[:]
+        choices.sort()
+
+        for entry in self._entryList:
+            entry.refresh_ui_choices(choices)
+
+
     # =========================================================================
     # Trigger functions
     # =========================================================================

Modified: trunk/gnue-forms/src/GFObjects/GFTabStop.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-11-23 13:36:09 UTC (rev 
9060)
+++ trunk/gnue-forms/src/GFObjects/GFTabStop.py 2006-11-24 09:46:08 UTC (rev 
9061)
@@ -492,3 +492,13 @@
                 value = self._field.getValue(index - self._visibleIndex)
                 display = self._displayHandler.getDisplayFiller(value)
                 self.uiWidget._ui_set_value_(index, display)
+
+
+    # -------------------------------------------------------------------------
+    # Update the available list of choices for all uiWidgets
+    # -------------------------------------------------------------------------
+
+    def refresh_ui_choices(self, choices):
+
+        for index in range(self._rows):
+            self.uiWidget._ui_set_choices_(index, choices)

Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py      2006-11-23 
13:36:09 UTC (rev 9060)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py      2006-11-24 
09:46:08 UTC (rev 9061)
@@ -64,14 +64,8 @@
         self.__index  = {}
         self.__pindex = {}
         self.__oldCursor = 1
+        self.__choices = []
 
-        if self.__style == 'dropdown':
-            self.__allowedValues = event.object._field._allowedValues
-
-        elif self.__style == 'listbox':
-            self.__data = event.object._field._allowedValues.values()
-            self.__data.sort()
-
         if self.__style == 'checkbox':
             self.__setCursor(1, 0)
 
@@ -143,9 +137,9 @@
 
     def _ui_set_value_(self, index, value):
 
-        if self.__style == 'listbox' and value in self.__data:
+        if self.__style == 'listbox' and value in self.__choices:
             if self.__value[index] <> value:
-                self.__index[index]  = self.__data.index(value)
+                self.__index[index]  = self.__choices.index(value)
                 self.__pindex[index] = 1
                 self.__offset[index] = self.__index[index]
 
@@ -153,6 +147,14 @@
         self.__repaint(index)
 
     # -------------------------------------------------------------------------
+    # Update the list of choices
+    # -------------------------------------------------------------------------
+
+    def _ui_set_choices_(self, index, choices):
+
+        self.__choices = choices[:]
+
+    # -------------------------------------------------------------------------
     # Set cursor position
     # -------------------------------------------------------------------------
 
@@ -304,7 +306,7 @@
         if self.__style == 'listbox':
             # First draw the visible items of the listbox
             offset = self.__offset[index]
-            lines  = self.__data[offset:offset + self.__height]
+            lines  = self.__choices[offset:offset + self.__height]
 
             for (line, value) in enumerate(lines):
                 text = value.ljust(self.__length)[:self.__length]
@@ -390,7 +392,10 @@
     def _keypress(self, key):
 
         if self.__style == 'dropdown' and key == chr(self._uiDriver.lookupKey):
-            res = self._uiDriver.getOption(u_("Select option"), 
self.__allowedValues)
+            mapping = {}
+            for item in self.__choices:
+                mapping[item] = item
+            res = self._uiDriver.getOption(u_("Select option"), mapping)
             if res is not None:
                 self._request('REPLACEVALUE', text = res)
         else:
@@ -421,20 +426,20 @@
         self.__index[index] += direction
 
         if self.__pindex[index] > self.__height:
-            if self.__index[index] < len(self.__data):
+            if self.__index[index] < len(self.__choices):
                 self.__offset[index] += direction
 
         elif self.__pindex[index] < 1:
             self.__offset[index] = max(0, self.__offset[index] - 1)
 
         self.__index[index] = max(0, self.__index[index])
-        self.__index[index] = min(len(self.__data) - 1, self.__index[index])
+        self.__index[index] = min(len(self.__choices) - 1, self.__index[index])
 
         self.__pindex[index] = max(1, self.__pindex[index])
         self.__pindex[index] = min(self.__pindex[index], self.__height)
 
-        self.__value[index] = self.__data[self.__index[index]]
-        self._request('REPLACEVALUE', text = self.__data[self.__index[index]])
+        self.__value[index] = self.__choices[self.__index[index]]
+        self._request('REPLACEVALUE', text = 
self.__choices[self.__index[index]])
 
     # -------------------------------------------------------------------------
     # Set cursor position for widget

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py        2006-11-23 
13:36:09 UTC (rev 9060)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py        2006-11-24 
09:46:08 UTC (rev 9061)
@@ -51,6 +51,7 @@
     """
     gfObject           = event.object
     self._eventHandler = event.eventHandler
+    self.items = []
 
     if hasattr (gfObject, 'Char__y'):
       posY = gfObject.Char__y
@@ -243,11 +244,6 @@
     if isinstance (widget, gtk.ComboBoxEntry):
       gfObject = self._uiDriver._WidgetToGFObj [widget]
 
-      # Check if list of allowed value (~= foreign keys, ~= dropdown content)
-      # changed
-      if gfObject.style == "dropdown":
-        self._updateChoices (widget, gfObject)
-
       self._blockHandler (widget.child, '_insert_handler')
       self._blockHandler (widget.child, '_delete_handler')
 
@@ -269,8 +265,6 @@
 
     elif isinstance (widget, gtk.TreeView):
       gfObject = self._uiDriver._WidgetToGFObj [widget]
-      if gfObject.style == "listbox":
-        self._updateChoices (widget, gfObject)
 
       if value in self.items:
         path = "%s" % self.items.index (value)

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py        2006-11-23 
13:36:09 UTC (rev 9060)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py        2006-11-24 
09:46:08 UTC (rev 9061)
@@ -73,9 +73,6 @@
     # return self.__createOldDropDown (gfObject, event)
     newWidget = gtk.combo_box_entry_new_text ()
     
-    newWidget._origAllowedValues = None
-    self._updateChoices (newWidget, gfObject)
-
     # Enter does NOT open the popup list
     # newWidget.set_activate (False)
 
@@ -322,6 +319,22 @@
             self._request('SELECTWITHMOUSE', position1=bounds[0],
                     position2=bounds[1], cursor=pos)
 
+  # -------------------------------------------------------------------------
+
+  def _ui_set_choices_(self, index, choices):
+    widget = self.widgets[index]
+
+    self.items = choices[:]
+    if isinstance (widget, gtk.ComboBox):
+        widget.get_model ().clear ()
+        map (widget.append_text, choices)
+
+    elif isinstance (widget, gtk.TreeView):
+        self.listStore.clear ()
+
+        for item in choices:
+          self.listStore.append([item])
+
   # ---------------------------------------------------------------------------
   # insert text into gtk.Entry widgets
   # ---------------------------------------------------------------------------
@@ -456,46 +469,11 @@
 
 
   # ---------------------------------------------------------------------------
-  # Update the list of allowed values on a Combo widget if neccessary
-  # ---------------------------------------------------------------------------
-
-  def _updateChoices (self, widget, gfObject):
-
-    if isinstance (widget, gtk.ComboBox):
-      if widget._origAllowedValues != gfObject._field._allowedValues:
-        (self.reverse, self.choices) = gfObject._field.allowedValues ()
-        self.choices.sort ()
-
-        widget._origAllowedValues = gfObject._field._allowedValues
-
-        widget.get_model ().clear ()
-        map (widget.append_text, self.choices)
-
-    elif isinstance (widget, gtk.TreeView):
-      if widget._origAllowedValues != gfObject._field._allowedValues:
-        self.listStore.clear ()
-
-        self.choices = gfObject._field.allowedValues () [0]
-
-        nDict = {}
-        for (key, value) in self.choices.items ():
-          nDict [value] = key
-
-        self.items = nDict.keys ()
-        self.items.sort ()
-
-        for key in self.items:
-          self.listStore.append ([nDict [key], key])
-
-        widget._origAllowedValues = gfObject._field._allowedValues
-
-
-  # ---------------------------------------------------------------------------
   # Create a listbox entry
   # ---------------------------------------------------------------------------
 
   def __createListBox (self, gfObject, event):
-    self.listStore = gtk.ListStore (str, str)
+    self.listStore = gtk.ListStore (str)
 
     hbox = gtk.HBox (False, 0)
     hbox.set_size_request (self.itemWidth, self.itemHeight)
@@ -508,8 +486,6 @@
 
     newWidget = gtk.TreeView (self.listStore)
     newWidget.set_headers_visible (False)
-    newWidget._origAllowedValues = None
-    self._updateChoices (newWidget, gfObject)
 
     if newWidget.get_vadjustment () is not None:
       adjustment = newWidget.get_vadjustment ()
@@ -526,11 +502,11 @@
         self._selectionChanged, gfObject)
 
     tvCol = gtk.TreeViewColumn ()
-    newWidget.append_column (tvCol)
+    r = newWidget.append_column (tvCol)
 
     cell = gtk.CellRendererText ()
     tvCol.pack_start (cell, False)
-    tvCol.add_attribute (cell, 'text', 1)
+    tvCol.add_attribute (cell, 'text', 0)
 
     frame.add (newWidget)
     if event.initialize:
@@ -552,7 +528,7 @@
 
     (model, tIter) = treeSelection.get_selected ()
     if tIter is not None:
-      desc = model.get_value (tIter, 1)
+      desc = model.get_value (tIter, 0)
 
     fRef = gfObject._form
 

Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-11-23 13:36:09 UTC 
(rev 9060)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-11-24 09:46:08 UTC 
(rev 9061)
@@ -232,7 +232,15 @@
         if hasattr(widget, '_ui_select_all_'):
             widget._ui_select_all_()
 
+    # -------------------------------------------------------------------------
 
+    def _ui_set_choices_(self, index, choices):
+
+        widget = self.widgets[index]
+        if hasattr(widget, '_ui_set_choices_'):
+            widget._ui_set_choices_(choices)
+
+
 # =============================================================================
 # Base class for entry widgets
 # =============================================================================
@@ -638,74 +646,18 @@
 
         self.ui_widget = ui_widget
         self.qt_class = qt_class
-        self.__last_choices = None
 
     # -------------------------------------------------------------------------
-    # Check the list of choices against the bound field
+    # Implementation of virtual methods
     # -------------------------------------------------------------------------
 
-    def update_choices(self):
-        """
-        Check wether an update of the available choices is needed.
-        """
-        field = self.ui_widget._gfObject._field
-        if self.__last_choices != field._allowedValues:
-            self._freeze_()
-            try:
-                choices = field._allowedValuesReverse.keys()
-                choices.sort()
+    def _ui_set_choices_(self, choices):
+        self.clear()
 
-                self._clear_()
+        for item in choices:
+            self.insertItem(item)
 
-                for dsc in choices:
-                    self._append_(field._allowedValuesReverse[dsc], dsc)
 
-                self.__last_choices = field._allowedValues
-
-            finally:
-                self._thaw_()
-
-    # -------------------------------------------------------------------------
-    # Virtual methods
-    # -------------------------------------------------------------------------
-
-    def _freeze_(self):
-        """
-        Descendants can override this method to freeze widget updates while
-        changing the choices
-        """
-        pass
-
-    # -------------------------------------------------------------------------
-
-    def _thaw_(self):
-        """
-        Descendants can override this method to enable widget update after
-        changing the choices
-        """
-        pass
-
-    # -------------------------------------------------------------------------
-
-    def _clear_(self):
-        """
-        Descendants must implement this method to clear it's list of choices
-        """
-        raise NotImplementedError
-
-    # -------------------------------------------------------------------------
-
-    def _append_(self, key, description):
-        """
-        Descendants must implement this method to add an item to the widget
-
-        @param key: the key of the item to be added
-        @param description: the full text to be shown in the widget
-        """
-        raise NotImplementedError
-
-
-
 # =============================================================================
 # Dropdown widgets
 # =============================================================================
@@ -730,8 +682,6 @@
         self.__lineEdit.lookup = self
         self.setLineEdit(self.__lineEdit)
 
-        self.update_choices()
-
         self.connect(self, qt.SIGNAL('activated(int)'), self.__on_activated)
 
 
@@ -748,18 +698,8 @@
     # Implementation of virtual methods
     # -------------------------------------------------------------------------
 
-    def _clear_(self):
-        self.clear()
-
-    # -------------------------------------------------------------------------
-
-    def _append_(self, key, description):
-        self.insertItem(description)
-
-    # -------------------------------------------------------------------------
-
     def _ui_set_value_(self, value):
-        self.update_choices()
+
         self.setCurrentText(value)
 
     # -------------------------------------------------------------------------
@@ -816,7 +756,6 @@
 
         qt.QListBox.__init__(self, parent)
         ChoiceEntry.__init__(self, ui_widget, qt.QListBox)
-        self.update_choices()
 
         self.connect(self, qt.SIGNAL('highlighted(int)'), 
self.__on_highlighted)
 
@@ -829,23 +768,10 @@
         self.ui_widget._request('REPLACEVALUE',
                 text=unicode(self.currentText()))
 
-
     # -------------------------------------------------------------------------
-    # Implementation of virtual methods
-    # -------------------------------------------------------------------------
 
-    def _clear_(self):
-        self.clear()
-
-    # -------------------------------------------------------------------------
-
-    def _append_(self, key, description):
-        self.insertItem(description)
-
-    # -------------------------------------------------------------------------
-
     def _ui_set_value_(self, value):
-        self.update_choices()
+
         self.setCurrentItem(self.findItem(value))
 
 

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py  2006-11-23 13:36:09 UTC 
(rev 9060)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/entry.py  2006-11-24 09:46:08 UTC 
(rev 9061)
@@ -73,13 +73,9 @@
 
       if event.initialize:
         choices = []
-        for val in object._field.allowedValues()[1]:
-          choices.append(wxEncode(val))
       else:
         choices = [""]
 
-      choices.sort()
-
       newWidget = wxComboBox(event.container, -1, "", defaultPoint,
                              defaultSize, choices, wxCB_DROPDOWN,) 
#|wxWANTS_CHARS,)
       if event.initialize:
@@ -96,13 +92,9 @@
     elif style == 'listbox':
       if event.initialize:
         choices = []
-        for val in object._field.allowedValues()[1]:
-          choices.append(wxEncode(val))
       else:
         choices = [""]
 
-#      choices.sort()
-
       newWidget = wxListBox(event.container, -1, defaultPoint, defaultSize,
                              choices, wxLB_SINGLE)
 
@@ -329,7 +321,22 @@
             self._request('SELECTWITHMOUSE', position1=start_pos,
                     position2=end_pos, cursor=end_pos)
 
+  # ---------------------------------------------------------------------------
 
+  def _ui_set_choices_(self, index, choices):
+
+      widget = self.widgets[index]
+      widget.Freeze()
+      try:
+          widget.Clear()
+          for item in choices:
+              widget.Append(item)
+
+      finally:
+          widget.Thaw()
+
+
+
 # ----------------------------------------------------------------------------
 # Configuration data
 # ----------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-11-23 
13:36:09 UTC (rev 9060)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/_base.py        2006-11-24 
09:46:08 UTC (rev 9061)
@@ -197,27 +197,25 @@
     # Update the choices of a ComboBox or a Listbox
     # -------------------------------------------------------------------------
 
-    def update_choices(self, widget):
+    def _ui_set_choices_(self, index, choices):
         """
         Update the choices of a combo- or listbox widget with the allowed
-        values from the associated GFEntry.  The values will be alphabetically
-        sorted before adding them to the wx control.  A reference to the
-        original allowed values dictionary will be kept with the wx control.
+        values from the associated GFEntry.  The values are alphabetically
+        sorted.
+
+        @param index: index of the widget to set the values for
+        @param choices: alphabetically sorted list of values
         """
 
+        widget = self.widgets[index]
         widget.Freeze()
 
         try:
-            choices = self._gfObject._field._allowedValuesReverse.keys()
-            choices.sort()
-
             widget.Clear()
+
             for dsc in choices:
-                widget.Append(dsc, \
-                        self._gfObject._field._allowedValuesReverse[dsc])
+                widget.Append(dsc)
 
-            widget._orig_allowed_values = self._gfObject._field._allowedValues
-
         finally:
             widget.Thaw()
 

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-11-23 
13:36:09 UTC (rev 9060)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py        2006-11-24 
09:46:08 UTC (rev 9061)
@@ -156,8 +156,6 @@
         result = wx.ComboBox(parent, -1, size=csize, style=wx.CB_DROPDOWN |
                 wx.TE_PROCESS_TAB | wx.TE_PROCESS_ENTER)
 
-        self.update_choices(result)
-
         # On wxMac a Combobox is a container holding a TextCtrl and a Choice.
         # We have to bind the Focus- and Char-Events to the TextCtrl widget.
         if 'wxMac' in wx.PlatformInfo:
@@ -193,7 +191,6 @@
         self.__border = self._uiDriver.control_border('default')
 
         result = wx.ListBox(parent, -1, size=csize, style=wx.LB_SINGLE)
-        self.update_choices(result)
 
         result.Bind(wx.EVT_LISTBOX, self.__on_item_selected)
         result.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
@@ -406,11 +403,6 @@
         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)
 





reply via email to

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