[Thuban-commits] r2759 - in trunk/thuban: . Thuban/UI

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Apr 25 01:24:47 CEST 2007


Author: bernhard
Date: 2007-04-25 01:24:40 +0200 (Wed, 25 Apr 2007)
New Revision: 2759

Modified:
   trunk/thuban/ChangeLog
   trunk/thuban/Thuban/UI/__init__.py
   trunk/thuban/Thuban/UI/classgen.py
Log:
Fixing the problem that with localisation the selection of
a class generator might not work.

*  Thuban/UI/classgen.py(ClassGenDialog): translating result from
genChoice.GetString() back to internal encoding.

*  Thuban/UI/__init__.py: Added internal_from_wxstring() and
ugly code that actually sets this function. Using and internal
variable _wx_can_be_imported that install_wx_translation() will set.


Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog	2007-04-24 23:12:17 UTC (rev 2758)
+++ trunk/thuban/ChangeLog	2007-04-24 23:24:40 UTC (rev 2759)
@@ -1,5 +1,15 @@
 2007-04-25  Bernhard Reiter <bernhard at intevation.de>
 
+	Fixing the problem that with localisation the selection of
+	a class generator might not work.
+
+	*  Thuban/UI/classgen.py(ClassGenDialog): translating result from
+	genChoice.GetString() back to internal encoding.
+	
+	*  Thuban/UI/__init__.py: Added internal_from_wxstring() and
+	ugly code that actually sets this function. Using and internal
+	variable _wx_can_be_imported that install_wx_translation() will set.
+
 	* Doc/technotes/string_representation.txt: fixed a typo and 
 	made the text less string about dbf files not providing encoding
 	information, but it might be that some of them do.

Modified: trunk/thuban/Thuban/UI/__init__.py
===================================================================
--- trunk/thuban/Thuban/UI/__init__.py	2007-04-24 23:12:17 UTC (rev 2758)
+++ trunk/thuban/Thuban/UI/__init__.py	2007-04-24 23:24:40 UTC (rev 2759)
@@ -1,11 +1,15 @@
-# Copyright (c) 2001, 2002, 2003, 2005 by Intevation GmbH
+# Copyright (c) 2001, 2002, 2003, 2005, 2007 by Intevation GmbH
 # Authors:
-# Bernhard Herzog <bh at intevation.de>
+# Bernhard Herzog <bh at intevation.de>  2001, 2002, 2003, 2005
+# Bernhard Reiter <bernhard at intevation.de> 2007
 #
 # This program is free software under the GPL (>=v2)
 # Read the file COPYING coming with Thuban for details.
 
 
+
+_wx_can_be_imported = False
+
 _locale = None
 def install_wx_translation():
     """Install the wx translation function in Thuban.
@@ -14,10 +18,12 @@
     Thuban/__init__.py
     """
     global _locale
+    global _wx_can_be_imported
     import Thuban
     if not Thuban.translation_function_installed():
         # Only import wx modules when we actually can install the
         # function so that the test suite can inhibit this
+        _wx_can_be_imported = True
         import wx
         wx.Locale_AddCatalogLookupPathPrefix(Thuban._message_dir)
         _locale = wx.Locale(wx.LANGUAGE_DEFAULT)
@@ -75,3 +81,29 @@
 
 
 install_wx_translation()
+
+# We define a function that will return the internal representation
+# for a value returned from wxString.
+# This depends on if we have a unicode build and which encoding we run.
+internal_from_wxstring = lambda x: x  # identity
+
+def install_internal_from_wxstring():
+    """Install the needed internal_from_wxstring() function.
+
+    For unicode builds wxString will return a unicode object according to
+    the wxPython documentation (looked up in changelog coming with 2.6.3)
+    we need to convert this back to internal, unless we use unicode objects
+    internally already.
+
+    Otherwise no conversion will need to be done.
+    """
+    global _wx_can_be_imported
+    global internal_from_wxstring
+
+    if _wx_can_be_imported:
+        import Thuban
+        import wx
+        if wx.USE_UNICODE == 1 and Thuban.get_internal_encoding != "unicode":
+            internal_from_wxstring = lambda x : Thuban.internal_from_unicode(x)
+
+install_internal_from_wxstring()

Modified: trunk/thuban/Thuban/UI/classgen.py
===================================================================
--- trunk/thuban/Thuban/UI/classgen.py	2007-04-24 23:12:17 UTC (rev 2758)
+++ trunk/thuban/Thuban/UI/classgen.py	2007-04-24 23:24:40 UTC (rev 2759)
@@ -25,6 +25,7 @@
 
 from Thuban.Model.layer import SHAPETYPE_ARC
 from Thuban.Model.range import Range
+from Thuban.UI import internal_from_wxstring
 from Thuban.UI.common import ThubanBeginBusyCursor, ThubanEndBusyCursor
 
 import classifier, resource
@@ -213,7 +214,7 @@
 
         assert index != -1, "button should be disabled!"
 
-        genSel = self.genChoice.GetString(index)
+        genSel = internal_from_wxstring(self.genChoice.GetString(index))
         clazz, genPanel = self.genChoice.GetClientData(index)
 
         propPanel = self.propPanel



More information about the Thuban-commits mailing list