bh: thuban/Thuban/UI about.py,1.21,1.22 __init__.py,1.4,1.5
cvs@intevation.de
cvs at intevation.de
Fri Jul 1 22:49:06 CEST 2005
- Previous message: bh: thuban ChangeLog,1.818,1.819
- Next message: bh: thuban/test test_save.py, 1.36, 1.37 test_load_1_0.py, 1.1, 1.2 test_load_0_9.py, 1.3, 1.4 test_load_0_8.py, 1.4, 1.5 test_load.py, 1.46, 1.47 support.py, 1.20, 1.21 runtests.py, 1.16, 1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: bh
Update of /thubanrepository/thuban/Thuban/UI
In directory doto:/tmp/cvs-serv11857/Thuban/UI
Modified Files:
about.py __init__.py
Log Message:
First step towards unicode. With this roughly we're at step 1
string_representation.txt
* Doc/technotes/string_representation.txt: New. Document how
strings are represented in Thuban and how to get to a Unicode
Thuban.
* Thuban/__init__.py (set_internal_encoding)
(unicode_from_internal, internal_from_unicode): New. The first few
functions for the internal string representation
* Thuban/UI/about.py (unicodeToLocale): Removed. Use
internal_from_unicode instead.
* Thuban/UI/__init__.py (install_wx_translation): Determine the
encoding to use for the internal string representation. Also,
change the translation function to return strings in internal
representation even on unicode builds of wxPython
* Thuban/Model/load.py (SessionLoader.check_attrs): Decode
filenames too.
(SessionLoader.start_clrange): Use check_attrs to decode and check
the attributes.
* Thuban/Model/xmlreader.py (XMLReader.encode): Use
internal_from_unicode to convert unicode strings.
* Thuban/Model/xmlwriter.py (XMLWriter.encode): Use
unicode_from_internal when applicable
* test/runtests.py (main): New command line option:
internal-encoding to specify the internal string encoding to use
in the tests.
* test/support.py (initthuban): Set the internal encoding to
latin-1
* test/test_load.py (TestSingleLayer.test, TestClassification.test)
(TestLabelLayer.test): Use the internal string representation when
dealing with non-ascii characters
* test/test_load_1_0.py (TestSingleLayer.test)
(TestClassification.test, TestLabelLayer.test): Use the internal
string representation when dealing with non-ascii characters
* test/test_load_0_9.py (TestSingleLayer.test)
(TestClassification.test): Use the internal string representation
when dealing with non-ascii characters
* test/test_load_0_8.py (TestUnicodeStrings.test): Use the
internal string representation when dealing with non-ascii
characters
* test/test_save.py (XMLWriterTest.testEncode)
(SaveSessionTest.testClassifiedLayer): Use the internal string
representation when dealing with non-ascii characters where
applicable
Index: about.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/about.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- about.py 10 Mar 2005 22:47:14 -0000 1.21
+++ about.py 1 Jul 2005 20:49:04 -0000 1.22
@@ -17,7 +17,7 @@
from locale import getdefaultlocale
-from Thuban import _
+from Thuban import _, internal_from_unicode
from Thuban.version import versions
from Thuban.Model.resource import gdal_support_status
@@ -39,11 +39,12 @@
lead_developer = 'Bernhard Herzog'
developers = [ 'Jonathan Coles',
'Frank Koormann',
- unicodeToLocale(u'Martin M\xfcller'),
+ internal_from_unicode(u'Martin M\xfcller'),
'Bernhard Reiter',
'Jan-Oliver Wagner' ]
translators = [ ( _('French'), 'Daniel Calvelo Aros' ),
- ( _('German'), unicodeToLocale(u'Bj\xf6rn Broscheit')),
+ ( _('German'),
+ internal_from_unicode(u'Bj\xf6rn Broscheit')),
( _('Hungarian'), 'Norbert Solymosi'),
( _('Italian'), 'Maurizio Napolitano'),
( _('Portuguese (Brazilian)'), 'Eduardo Patto Kanegae'),
@@ -163,15 +164,3 @@
def OnCancel(self, event):
self.EndModal(wxID_CANCEL)
-
-
-def unicodeToLocale(unicodeStr):
- "Function to convert unicode to the user's locale encoding"
- # Under a german windows 2000 getlocale returns an encoding name
- # that's not direcly usable (it's missing a "cp" at the beginning).
- # getdefaultlocale does return a usable encoding name so we use that
- # instead.
- locale=getdefaultlocale()[1]
- if locale is None:
- locale = 'ascii'
- return unicodeStr.encode(locale,'replace')
Index: __init__.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- __init__.py 27 Oct 2003 17:11:06 -0000 1.4
+++ __init__.py 1 Jul 2005 20:49:04 -0000 1.5
@@ -1,4 +1,4 @@
-# Copyright (c) 2001, 2002, 2003 by Intevation GmbH
+# Copyright (c) 2001, 2002, 2003, 2005 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh at intevation.de>
#
@@ -22,7 +22,23 @@
wx.wxLocale_AddCatalogLookupPathPrefix(Thuban._message_dir)
_locale = wx.wxLocale()
_locale.AddCatalog("thuban")
- Thuban.install_translation_function(wx.wxGetTranslation)
+
+ # With a unicode build of wxPython, wxGetTranslation returns a
+ # unicode object, so we have a wrapper that handles the case of
+ # not using unicode as the internal string representation of
+ # Thuban: If wxGetTranslation returns unicode and the internal
+ # string representation of Thuban is not unicode, we convert the
+ # translated string to the internal representation. wxPython
+ # will convert such strings back to unicode if necessary,
+ # provided the internal encoding used is the one expected by
+ # wxPython, which is taken care of below.
+ def thuban_wx_translation(s):
+ t = wx.wxGetTranslation(s)
+ if isinstance(t, unicode) and Thuban._internal_encoding!="unicode":
+ t = t.encode(Thuban._internal_encoding, "replace")
+ return t
+
+ Thuban.install_translation_function(thuban_wx_translation)
# Reset the python locale. This makes sure that the LC_NUMERIC
# seen by the python interpreter and by C modules is "C" instead
@@ -31,5 +47,31 @@
# work for some reason
import locale
locale.setlocale(locale.LC_NUMERIC, "")
+
+ # determine the internal encoding to use.
+ # This is very tricky. It's probably not optimal yet.
+ encoding = None
+
+ # If we have a wxPython >= 2.5.4.1, we use the
+ # GetDefaultPyEncoding function to use exactly what wxPython
+ # also uses when converting between unicode and byte-strings ...
+ if hasattr(wx, "wxGetDefaultPyEncoding"):
+ # AFAICT from the code this will always be a usable string,
+ # although it could be "ascii".
+ internal_encoding = wx.wxGetDefaultPyEncoding()
+
+ # ... otherwise we use Python's getdefaultlocale. This is what
+ # GetDefaultPyEncoding also uses ...
+ if encoding is None:
+ encoding = locale.getdefaultlocale()[1]
+
+ # ... finally, if we haven't figured it out yet, use latin 1 for
+ # historical reasons. Maybe ascii would be better.
+ if encoding is None:
+ encoding = "latin1"
+
+ # set the encoding
+ Thuban.set_internal_encoding(encoding)
+
install_wx_translation()
- Previous message: bh: thuban ChangeLog,1.818,1.819
- Next message: bh: thuban/test test_save.py, 1.36, 1.37 test_load_1_0.py, 1.1, 1.2 test_load_0_9.py, 1.3, 1.4 test_load_0_8.py, 1.4, 1.5 test_load.py, 1.46, 1.47 support.py, 1.20, 1.21 runtests.py, 1.16, 1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)