]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Unicode.py
A Unicode sample for wxPython
[wxWidgets.git] / wxPython / demo / Unicode.py
CommitLineData
03d84e7a
RD
1
2
3from wxPython.wx import *
4
5#----------------------------------------------------------------------
6
7# Some unicode strings
8chi_uni = (u'Python ?\u8200?\u619f\u8cdc?\u877a\u51fd?\u96a4\ued67?\u5697',
9 '(Python is best programming language)')
10
11lt1_uni = (u'Pythonas yra \u017eaviausia \u0161neka',
12 '(Python is the best)')
13lt2_uni = (u'A\u0161 m\u0117gstu \u0161okolad\u0105',
14 '(I like chocolate)')
15
16
17# Equivalents in UTF-8. Should I demo these somehow???
18chi_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)')
20
21lt1_utf8 = ('Pythonas yra \xc5\xbeaviausia \xc5\xa1neka',
22 '(Python is the best)')
23lt2_utf8 = ('A\xc5\xa1 m\xc4\x97gstu \xc5\xa1okolad\xc4\x85',
24 '(I like chocolate)')
25
26#----------------------------------------------------------------------
27
28class TestPanel(wxPanel):
29 def __init__(self, parent, log):
30 self.log = log
31 wxPanel.__init__(self, parent, -1)
32
33 box = wxBoxSizer(wxVERTICAL)
34
35 if not wxUSE_UNICODE:
36 self.AddLine(box)
37 self.AddText(box, "Sorry, this wxPython was not built with Unicode support.",
38 font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
39 self.AddLine(box)
40
41 else:
42 f = self.GetFont()
43 font = wxFont(14, f.GetFamily(), f.GetStyle(), wxBOLD, false,
44 f.GetFaceName(), f.GetEncoding())
45
46 self.AddLine(box)
47 self.AddText(box, chi_uni[0], chi_uni[1], 'Chinese:', font)
48 self.AddLine(box)
49
50 self.AddText(box, lt1_uni[0], lt1_uni[1], 'Lithuanian:', font)
51 self.AddLine(box)
52 self.AddText(box, lt2_uni[0], lt2_uni[1], 'Lithuanian:', font)
53 self.AddLine(box)
54
55
56 border = wxBoxSizer(wxVERTICAL)
57 border.Add(box, 1, wxEXPAND|wxALL, 10)
58 self.SetAutoLayout(true)
59 self.SetSizer(border)
60
61
62 def AddLine(self, sizer):
63 sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
64
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)
70 if font is not None:
71 text1.SetFont(font)
72
73 # put them in a sizer
74 row = wxBoxSizer(wxHORIZONTAL)
75 row.Add(lang)
76 row.Add(25,10)
77 row.Add(text1, 1, wxEXPAND)
78 row.Add(text2)
79
80 # put the row in the main sizer
81 sizer.Add(row, 0, wxEXPAND|wxALL, 5)
82
83
84#----------------------------------------------------------------------
85
86def runTest(frame, nb, log):
87 win = TestPanel(nb, log)
88 return win
89
90#----------------------------------------------------------------------
91
92
93
94overview = """<html><body>
95<h2><center>wxPython Unicode Support</center></h2>
96
97wxWindows and wxPython can be compiled with unicode support enabled or
98disabled. Previous to wxPython 2.3.3 non-unicode mode was always
99used. Starting with 2.3.3 either mode is supported, but only if it is
100also available in wxWindow on the platform. Currently wxWindows only
101supports unicode on MS Windows platforms, but with the recent release
102of GTK+ 2.0 it is only a matter of time until it can be done on wxGTK
103(Linux and other unixes) as well.
104<p>
105When unicode is enabled, then all functions and methods in wxPython
106that return a wxString from the C++ function will return a Python
107unicode object, and parameters to C++ functions/methods that expect a
108wxString can accept either a Python string or unicode object. If a
109string object is passed then it will be decoded into unicode using the
110converter pointed to by wxConvCurrent, which will use the default
111system encoding. If you need to use string in some other encoding
112then you should convert it to unicode using the Python codecs first
113and then pass the unicode to the wxPython method.
114
115
116</body></html>
117"""