]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Unicode.py
0ddb0e8b8b237a0f3fed02b9b3cf1c986e8610ea
3 from wxPython
.wx
import *
5 #----------------------------------------------------------------------
8 chi_uni
= (u
'Python ?\u8200?\u619f\u8cdc?\u877a\u51fd?\u96a4\ued67?\u5697',
9 '(Python is best programming language)')
11 lt1_uni
= (u
'Pythonas yra \u017eaviausia \u0161neka',
12 '(Python is the best)')
13 lt2_uni
= (u
'A\u0161 m\u0117gstu \u0161okolad\u0105',
17 # Equivalents in UTF-8. Should I demo these somehow???
18 chi_utf8
= ('Python ?\xe8\x88\x80?\xe6\x86\x9f\xe8\xb3\x9c?\xe8\x9d\xba\xe5\x87\xbd?\xe9\x9a\xa4\xee\xb5\xa7?\xe5\x9a\x97',
19 '(Python is best programming language)')
21 lt1_utf8
= ('Pythonas yra \xc5\xbeaviausia \xc5\xa1neka',
22 '(Python is the best)')
23 lt2_utf8
= ('A\xc5\xa1 m\xc4\x97gstu \xc5\xa1okolad\xc4\x85',
26 #----------------------------------------------------------------------
28 class TestPanel(wxPanel
):
29 def __init__(self
, parent
, log
):
31 wxPanel
.__init
__(self
, parent
, -1)
33 box
= wxBoxSizer(wxVERTICAL
)
37 self
.AddText(box
, "Sorry, this wxPython was not built with Unicode support.",
38 font
= wxFont(12, wxSWISS
, wxNORMAL
, wxBOLD
))
43 font
= wxFont(14, f
.GetFamily(), f
.GetStyle(), wxBOLD
, false
,
44 f
.GetFaceName(), f
.GetEncoding())
47 self
.AddText(box
, chi_uni
[0], chi_uni
[1], 'Chinese:', font
)
50 self
.AddText(box
, lt1_uni
[0], lt1_uni
[1], 'Lithuanian:', font
)
52 self
.AddText(box
, lt2_uni
[0], lt2_uni
[1], 'Lithuanian:', font
)
56 border
= wxBoxSizer(wxVERTICAL
)
57 border
.Add(box
, 1, wxEXPAND|wxALL
, 10)
58 self
.SetAutoLayout(true
)
62 def AddLine(self
, sizer
):
63 sizer
.Add(wxStaticLine(self
, -1), 0, wxEXPAND
)
65 def AddText(self
, sizer
, text1
, text2
='', lang
='', font
=None):
66 # create some controls
67 lang
= wxStaticText(self
, -1, lang
)
68 text1
= wxStaticText(self
, -1, text1
)#, style=wxALIGN_CENTRE)
69 text2
= wxStaticText(self
, -1, text2
)
74 row
= wxBoxSizer(wxHORIZONTAL
)
77 row
.Add(text1
, 1, wxEXPAND
)
80 # put the row in the main sizer
81 sizer
.Add(row
, 0, wxEXPAND|wxALL
, 5)
84 #----------------------------------------------------------------------
86 def runTest(frame
, nb
, log
):
87 win
= TestPanel(nb
, log
)
90 #----------------------------------------------------------------------
94 overview
= """<html><body>
95 <h2><center>wxPython Unicode Support</center></h2>
97 wxWindows and wxPython can be compiled with unicode support enabled or
98 disabled. Previous to wxPython 2.3.3 non-unicode mode was always
99 used. Starting with 2.3.3 either mode is supported, but only if it is
100 also available in wxWindow on the platform. Currently wxWindows only
101 supports unicode on MS Windows platforms, but with the recent release
102 of GTK+ 2.0 it is only a matter of time until it can be done on wxGTK
103 (Linux and other unixes) as well.
105 When unicode is enabled, then all functions and methods in wxPython
106 that return a wxString from the C++ function will return a Python
107 unicode object, and parameters to C++ functions/methods that expect a
108 wxString can accept either a Python string or unicode object. If a
109 string object is passed then it will be decoded into unicode using the
110 converter pointed to by wxConvCurrent, which will use the default
111 system encoding. If you need to use string in some other encoding
112 then you should convert it to unicode using the Python codecs first
113 and then pass the unicode to the wxPython method.