/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/__init__.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/__init__.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2642 - (hide annotations)
Fri Jul 1 20:49:04 2005 UTC (19 years, 8 months ago) by bh
Original Path: trunk/thuban/Thuban/UI/__init__.py
File MIME type: text/x-python
File size: 3179 byte(s)
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

1 bh 2642 # Copyright (c) 2001, 2002, 2003, 2005 by Intevation GmbH
2 bh 6 # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7 bh 230
8 bh 1871
9     _locale = None
10     def install_wx_translation():
11     """Install the wx translation function in Thuban.
12    
13     For more information about translations in Thuban see the comment in
14     Thuban/__init__.py
15     """
16     global _locale
17     import Thuban
18     if not Thuban.translation_function_installed():
19     # Only import wx modules when we actually can install the
20     # function so that the test suite can inhibit this
21     import wxPython.wx as wx
22     wx.wxLocale_AddCatalogLookupPathPrefix(Thuban._message_dir)
23     _locale = wx.wxLocale()
24     _locale.AddCatalog("thuban")
25    
26 bh 2642 # With a unicode build of wxPython, wxGetTranslation returns a
27     # unicode object, so we have a wrapper that handles the case of
28     # not using unicode as the internal string representation of
29     # Thuban: If wxGetTranslation returns unicode and the internal
30     # string representation of Thuban is not unicode, we convert the
31     # translated string to the internal representation. wxPython
32     # will convert such strings back to unicode if necessary,
33     # provided the internal encoding used is the one expected by
34     # wxPython, which is taken care of below.
35     def thuban_wx_translation(s):
36     t = wx.wxGetTranslation(s)
37     if isinstance(t, unicode) and Thuban._internal_encoding!="unicode":
38     t = t.encode(Thuban._internal_encoding, "replace")
39     return t
40    
41     Thuban.install_translation_function(thuban_wx_translation)
42    
43 bh 1871 # Reset the python locale. This makes sure that the LC_NUMERIC
44     # seen by the python interpreter and by C modules is "C" instead
45     # of the user's locale. Python code will still see the user's
46     # locale where it matters. Without this, drawing the map doesn't
47     # work for some reason
48     import locale
49     locale.setlocale(locale.LC_NUMERIC, "")
50    
51 bh 2642 # determine the internal encoding to use.
52     # This is very tricky. It's probably not optimal yet.
53     encoding = None
54    
55     # If we have a wxPython >= 2.5.4.1, we use the
56     # GetDefaultPyEncoding function to use exactly what wxPython
57     # also uses when converting between unicode and byte-strings ...
58     if hasattr(wx, "wxGetDefaultPyEncoding"):
59     # AFAICT from the code this will always be a usable string,
60     # although it could be "ascii".
61     internal_encoding = wx.wxGetDefaultPyEncoding()
62    
63     # ... otherwise we use Python's getdefaultlocale. This is what
64     # GetDefaultPyEncoding also uses ...
65     if encoding is None:
66     encoding = locale.getdefaultlocale()[1]
67    
68     # ... finally, if we haven't figured it out yet, use latin 1 for
69     # historical reasons. Maybe ascii would be better.
70     if encoding is None:
71     encoding = "latin1"
72    
73     # set the encoding
74     Thuban.set_internal_encoding(encoding)
75    
76    
77 bh 1871 install_wx_translation()

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26