commit-gnue
[Top][All Lists]
Advanced

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

r6007 - in trunk/gnue-forms/src/uidrivers/gtk2: . widgets widgets/form


From: johannes
Subject: r6007 - in trunk/gnue-forms/src/uidrivers/gtk2: . widgets widgets/form
Date: Wed, 21 Jul 2004 06:22:49 -0500 (CDT)

Author: johannes
Date: 2004-07-21 06:22:48 -0500 (Wed, 21 Jul 2004)
New Revision: 6007

Modified:
   trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py
   trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py
   trunk/gnue-forms/src/uidrivers/gtk2/about.py
   trunk/gnue-forms/src/uidrivers/gtk2/common.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/box.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/button.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py
   trunk/gnue-forms/src/uidrivers/gtk2/widgets/label.py
Log:
Fixed change of allowed values in dropdowns and fixed unicode stuff


Modified: trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py       2004-07-20 
22:37:50 UTC (rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/UILoginHandler.py       2004-07-21 
11:22:48 UTC (rev 6007)
@@ -18,12 +18,13 @@
 #
 # Copyright 2000-2004 Free Software Foundation
 #
-# $Id :$
+# $Id: $
 
 import gtk
 import os.path
+import types
 
-from gnue.common.apps import GConfig
+from gnue.common.apps import GConfig, i18n
 from gnue.common.datasources import GLoginHandler
 
 # =============================================================================
@@ -60,7 +61,7 @@
     text = u_('Login required for %(newline)s"%(description)s"') \
            % {'newline': len (description) and '\n' or '',
               'description': description or connection}
-    label = gtk.Label (text.encode ('utf-8'))
+    label = gtk.Label (text)
     label.set_line_wrap (True)
     label.set_justify (gtk.JUSTIFY_CENTER)
     self.dialog.vbox.pack_start (label, True, True, 20)
@@ -72,7 +73,9 @@
     for ix in range (len (fields)):
       item = fields [ix]
       text = "%s" % item [1]
-      label = gtk.Label (text.encode ('utf-8'))
+      if isinstance (text, types.StringType):
+        text = unicode (text, i18n.encoding)
+      label = gtk.Label (text)
       label.set_alignment (0, label.get_alignment () [1])
       table.attach (label, 0, 1, ix, ix + 1)
       label.show ()
@@ -91,7 +94,9 @@
 
     # Add an error text if given
     if error is not None:
-      label = gtk.Label (error.encode ('utf-8'))
+      if isinstance (error, types.StringType):
+        error = unicode (error, i18n.encoding)
+      label = gtk.Label (error)
       label.set_line_wrap (True)
       label.modify_fg (gtk.STATE_NORMAL, gtk.gdk.color_parse ('red'))
       self.dialog.vbox.pack_start (label, True, True, 10)
@@ -112,7 +117,8 @@
 
     result = {}
     for ix in range (len (fields)):
-      result [fields [ix][0]] = self.textEntries [ix].get_text ()
+      text = unicode (self.textEntries [ix].get_text (), 'utf-8')
+      result [fields [ix][0]] = text
 
     return result
 
@@ -129,7 +135,7 @@
       if data < len (self.textEntries):
         self.textEntries [data].grab_focus ()
       else:
-        self.dialog.response(gtk.RESPONSE_OK)
+        self.dialog.response (gtk.RESPONSE_OK)
 
 
   # Hack for McMillan packaging on win32

Modified: trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py     2004-07-20 22:37:50 UTC 
(rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py     2004-07-21 11:22:48 UTC 
(rev 6007)
@@ -28,7 +28,9 @@
 #
 import sys
 import string
+import types
 
+from gnue.common.apps import i18n
 from gnue.forms.uidrivers._base import Exceptions
 
 try:
@@ -244,10 +246,11 @@
   # ---------------------------------------------------------------------------
 
   def setClipboardContents(self, event):
-    print "Set to clip:", event.text
     ui = self._gfObjToUIWidget [event._form]
     if ui.mainWindow.get_screen () is not None:
       text = "%s" % event.text
+      if isinstance (text, types.StringType):
+        text = unicode (text, i18n.encoding)
       disp = ui.mainWindow.get_screen ().get_display ()
       clip = gtk.Clipboard (disp, 'CLIPBOARD')
       clip.set_text (text.encode ('utf-8'), -1)
@@ -281,7 +284,9 @@
         message_format = message)
 
     if title is not None and len (title):
-      dialog.set_title (title.encode ('utf-8'))
+      if isinstance (title, types.StringType):
+        title = unicode (title, i18n.encoding)
+      dialog.set_title (title)
     cButtons = [gtk.BUTTONS_CANCEL, gtk.BUTTONS_OK_CANCEL]
     if cancel and not mbRec ['buttons'] in cButtons:
       dialog.add_button (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)


Property changes on: trunk/gnue-forms/src/uidrivers/gtk2/UIdriver.py
___________________________________________________________________
Name: svn:keywords
   + +Id

Modified: trunk/gnue-forms/src/uidrivers/gtk2/about.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/about.py        2004-07-20 22:37:50 UTC 
(rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/about.py        2004-07-21 11:22:48 UTC 
(rev 6007)
@@ -21,8 +21,9 @@
 # $Id: $
 
 import gtk
+import types
 
-from gnue.common.apps import GDebug
+from gnue.common.apps import GDebug, i18n
 
 # =============================================================================
 # Class implementing an about box for GTK2
@@ -85,7 +86,9 @@
   # ---------------------------------------------------------------------------
 
   def _newLabel (self, text, table, left, right, top, bottom):
-    result = gtk.Label (text.encode ('utf-8'))
+    if isinstance (text, types.StringType):
+      text = unicode (text, i18n.encoding)
+    result = gtk.Label (text)
     result.set_alignment (0, 0)
     table.attach (result, left, right, top, bottom)
     result.show ()


Property changes on: trunk/gnue-forms/src/uidrivers/gtk2/common.py
___________________________________________________________________
Name: svn:keywords
   + +Id

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py        2004-07-20 
22:37:50 UTC (rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/_base.py        2004-07-21 
11:22:48 UTC (rev 6007)
@@ -21,13 +21,13 @@
 # $Id: $
 
 import gtk
+import types
 
 from gnue.common import events
-from types import UnicodeType
+from gnue.common.apps import GDebug, i18n
 from gnue.forms.GFForm import *
 from gnue.forms.uidrivers._base.widgets._base import UIWidget
 from gnue.forms.uidrivers.gtk2.common import _setDefaultEventHandlers
-from gnue.common.apps import GDebug
 
 
 #############################################################################
@@ -229,8 +229,8 @@
     widget = self.widgets [index]
     GDebug.printMesg (1, "setValue %s [%s] %s" % (repr (value), index, widget))
     
-    # fix for 0.5.1 (Unicode is not internal encoding)
-    if not isinstance (widget, gtk.CheckButton) and type (value) != 
UnicodeType:
+    if not isinstance (widget, gtk.CheckButton) and \
+        type (value) != types.UnicodeType:
       GDebug.printMesg (3, "converting %s to unicode using %s" % \
           (repr (value), gConfigForms ('textEncoding')))
       value = unicode (value, gConfigForms ('textEncoding'))
@@ -241,10 +241,8 @@
       
       # Check if list of allowed value (~= foreign keys, ~= dropdown content) 
       # changed
-      if gfObject.style == "dropdown" and \
-         not gfObject._field._allowedValues == widget._origAllowedValues:
-        widget._origAllowedValues = gfObject._field._allowedValues
-        widget.set_popdown_strings (gfObject._field._allowedValuesDescr)
+      if gfObject.style == "dropdown":
+        self._updateChoices (widget, gfObject)
         
       widget.entry.set_text (value)
       
@@ -304,3 +302,12 @@
           (['Block', 'Unblock'] [unblock], handlerName, handler, widget))
       method (handler)
 
+
+  # ---------------------------------------------------------------------------
+  # Make sure a string will be converted into unicode
+  # ---------------------------------------------------------------------------
+
+  def _makeSafe (self, value):
+    if isinstance (value, types.StringType):
+      value = unicode (value, i18n.encoding)
+    return value

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/box.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/box.py  2004-07-20 22:37:50 UTC 
(rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/box.py  2004-07-21 11:22:48 UTC 
(rev 6007)
@@ -38,7 +38,7 @@
     gfObject = event.object
     text     = None
     if hasattr (gfObject, 'label') and len (gfObject.label):
-      text = " %s " % gfObject.label.encode ('utf-8')
+      text = " %s " % self._makeSafe (gfObject.label)
     
     half = int (event.widgetHeight / 2)
 

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/button.py       2004-07-20 
22:37:50 UTC (rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/button.py       2004-07-21 
11:22:48 UTC (rev 6007)
@@ -40,7 +40,7 @@
     object = event.object
 
     text = "%s" % object.label
-    newWidget = gtk.Button (text.encode ('utf-8'))
+    newWidget = gtk.Button (self._makeSafe (text))
     newWidget.modify_font (self._uiDriver.mono_font)
     newWidget.set_size_request (self.itemWidth, self.itemHeight)
 

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py        2004-07-20 
22:37:50 UTC (rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/entry.py        2004-07-21 
11:22:48 UTC (rev 6007)
@@ -62,16 +62,10 @@
   # ---------------------------------------------------------------------------
 
   def __createDropDown (self, gfObject, event):
-    if event.initialize:
-      (self.reverse, self.choices) = gfObject._field.allowedValues ()
-    else:
-      (self.reverse, self.choices) = ({}, [""])
-
-    self.choices.sort ()
-
     newWidget = gtk.Combo ()
     newWidget.entry.modify_font (self._uiDriver.mono_font)
-    newWidget.set_popdown_strings (self.choices)
+    newWidget._origAllowedValues = None
+    self._updateChoices (newWidget, gfObject)
 
     # Enter does NOT open the popup list
     newWidget.disable_activate ()
@@ -84,9 +78,10 @@
       newWidget._origAllowedValues = gfObject._field._allowedValues
       self._addDefaultEventHandler (newWidget)
       self._addFocusHandler (newWidget.entry, newWidget)
-      newWidget.list.connect ('select-child', self.comboHandler, newWidget)
+      newWidget._selectHandler = newWidget.list.connect ('select-child',
+                                                  self.comboHandler, newWidget)
       newWidget._keypressHandler = newWidget.entry.connect ('key-press-event',
-                                               self.comboEntryKeyPress)
+                                                  self.comboEntryKeyPress)
 
     return newWidget
 
@@ -367,17 +362,13 @@
     """
     GDebug.printMesg (2, "Selected %s in %s" % (listChild, combo))
 
+    gfObject      = self._uiDriver._WidgetToGFObj [combo]
     selection     = comboList.child_position (listChild)
-    # TODO: why can this happen ?
-    if selection >= len (self.choices):
-      selection = 0
+    compare       = self.reverse.get (gfObject.getValue (), None)
     selected_text = self.choices [selection]
-
-    gfObject      = self._uiDriver._WidgetToGFObj [combo]
-    compare       = self.reverse.get (gfObject.getValue (), None)
     
     GDebug.printMesg (1, "Selection is %s in %s" % (selected_text, gfObject))
-    GDebug.printMesg (1, "Old %s vs %s" % (repr (compare), selected_text))
+    GDebug.printMesg (1, "Old %s vs %s" % (repr(compare), repr(selected_text)))
       
     comboList.stop_emission ('select-child')
 
@@ -432,6 +423,30 @@
     return gtk.TRUE
 
 
+  # ---------------------------------------------------------------------------
+  # Update the list of allowed values on a Combo widget if neccessary
+  # ---------------------------------------------------------------------------
+
+  def _updateChoices (self, combo, gfObject):
+    if not isinstance (combo, gtk.Combo):
+      GDebug.printMesg (1, "Called 'updateChoices' on non-Combo-widget!")
+      return
+
+    if combo._origAllowedValues != gfObject._field._allowedValues:
+      (self.reverse, self.choices) = gfObject._field.allowedValues ()
+      self.choices.sort ()
+
+      GDebug.printMesg (1, "ALLOW-CHANGED: from '%s' to '%s'" % \
+          (combo._origAllowedValues, gfObject._field._allowedValues))
+      combo._origAllowedValues = gfObject._field._allowedValues
+      if hasattr (combo, '_selectHandler'):
+        combo.list.handler_block (combo._selectHandler)
+      combo.set_popdown_strings (self.choices)
+      if hasattr (combo, '_selectHandler'):
+        combo.list.handler_unblock (combo._selectHandler)
+
+
+
 # -----------------------------------------------------------------------------
 # Base configuration data
 # -----------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py  2004-07-20 
22:37:50 UTC (rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/form/widget.py  2004-07-21 
11:22:48 UTC (rev 6007)
@@ -23,6 +23,7 @@
 import gtk
 import string
 import wrappers
+import types
 
 from gnue.common import events
 from gnue.common.apps import GDebug
@@ -103,7 +104,7 @@
     self.mainWindow.connect ('delete_event', self.windowExitEvent)
 
     title = "%s" % self._form.title
-    self.mainWindow.set_title (title.encode ('utf-8'))
+    self.mainWindow.set_title (self._makeSafe (title))
 
     if gfObject._layout.tabbed != 'none':
       self._wrapper = wrappers.TabbedWrapper (self)
@@ -182,27 +183,27 @@
       return
     
     if tip is not None:
-      text = "%s" % tip
+      text = self._makeSafe ("%s" % tip)
       context = self.statusBar1.get_context_id ('tip')
-      self.statusBar1.push (context, text.encode ('utf-8'))
+      self.statusBar1.push (context, text)
 
     if statusValue:
       context = self.statusBar2.get_context_id ('statusValue')
-      self.statusBar2.push (context, statusValue.encode ('utf-8'))
+      self.statusBar2.push (context, self._makeSafe (statusValue))
       
     if insertValue:
       context = self.statusBar3.get_context_id ('insertValue')
-      self.statusBar3.push (context, insertValue.encode ('utf-8'))
+      self.statusBar3.push (context, self._makeSafe (insertValue))
 
     if currentRecord and maxRecord:
       context = self.statusBar4.get_context_id ('currentRecord_and_maxRecord')
       text    = string.strip ("%s/%s" % (currentRecord, maxRecord))
-      self.statusBar4.push (context, text)
+      self.statusBar4.push (context, self._makeSafe (text))
 
     if currentPage and maxPage:
       context = self.statusBar5.get_context_id ('currentPage_and_maxPage')
       text    = string.strip ("%s/%s" % (currentPage, maxPage))
-      self.statusBar5.push (context, text)
+      self.statusBar5.push (context, self._makeSafe (text))
 
 
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/uidrivers/gtk2/widgets/label.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/gtk2/widgets/label.py        2004-07-20 
22:37:50 UTC (rev 6006)
+++ trunk/gnue-forms/src/uidrivers/gtk2/widgets/label.py        2004-07-21 
11:22:48 UTC (rev 6007)
@@ -51,7 +51,7 @@
 
     text = "%s" % gfObject.text
 
-    newWidget = gtk.Label (text.encode ('utf-8'))
+    newWidget = gtk.Label (self._makeSafe (text))
     newWidget.modify_font (self._uiDriver.mono_font)
 
     newWidget.set_justify (_alignmentStyle [gfObject.alignment])





reply via email to

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