/[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 2700 - (hide annotations)
Mon Sep 18 14:27:02 2006 UTC (18 years, 5 months ago) by dpinte
Original Path: trunk/thuban/Thuban/UI/__init__.py
File MIME type: text/x-python
File size: 3154 byte(s)
2006-09-18 Didrik Pinte <dpinte@itae.be>
    
        * wxPython 2.6 update : wx 2.4 syntax has been updated to 2.6


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 dpinte 2700 import wx
22     wx.Locale_AddCatalogLookupPathPrefix(Thuban._message_dir)
23     _locale = wx.Locale()
24 bh 1871 _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 dpinte 2700 t = wx.GetTranslation(s)
37 bh 2642 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 dpinte 2700 if hasattr(wx, "GetDefaultPyEncoding"):
59 bh 2642 # AFAICT from the code this will always be a usable string,
60     # although it could be "ascii".
61 dpinte 2700 internal_encoding = wx.GetDefaultPyEncoding()
62 bh 2642
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