]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Unicode.py
Made widgets sample take up less space
[wxWidgets.git] / wxPython / demo / Unicode.py
1
2
3 from wxPython.wx import *
4
5 #----------------------------------------------------------------------
6
7 # Some unicode strings
8 chi_uni = (u'Python \u662f\u6700\u597d\u7684\u7de8\u7a0b\u8a9e\u8a00\uff01',
9 'Python is the best\nprogramming language!')
10
11 lt1_uni = (u'Pythonas yra \u017eaviausia \u0161neka',
12 'Python is the best')
13 lt2_uni = (u'A\u0161 m\u0117gstu \u0161okolad\u0105',
14 'I like chocolate')
15
16 kor_uni = (u'\ud30c\uc774\uc36c\uc740 \ucd5c\uace0\uc758 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc774\ub2e4!',
17 'Python is the best\nprogramming language!')
18
19 bul_uni = (u'\u041f\u0438\u0442\u043e\u043d \u0435 \u043d\u0430\u0439-\u0434\u043e\u0431\u0440\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0435\u043d \u0435\u0437\u0438\u043a!',
20 'Python is the best\nprogramming language!')
21 rus_uni = (u'\u041f\u0438\u0442\u043e\u043d - \u043b\u0443\u0447\u0448\u0438\u0439 \u044f\u0437\u044b\u043a \n\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!',
22 'Python is the best\nprogramming language!')
23
24
25 # Equivalents in UTF-8. Should I demo these somehow???
26 chi_utf8 = ('Python \xe6\x98\xaf\xe6\x9c\x80\xe5\xa5\xbd\xe7\x9a\x84\xe7\xb7\xa8\xe7\xa8\x8b\xe8\xaa\x9e\xe8\xa8\x80\xef\xbc\x81',
27 'Python is the best programming language')
28
29 lt1_utf8 = ('Pythonas yra \xc5\xbeaviausia \xc5\xa1neka',
30 'Python is the best')
31 lt2_utf8 = ('A\xc5\xa1 m\xc4\x97gstu \xc5\xa1okolad\xc4\x85',
32 'I like chocolate')
33
34 kor_utf8 = ('\xed\x8c\x8c\xec\x9d\xb4\xec\x8d\xac\xec\x9d\x80 \xec\xb5\x9c\xea\xb3\xa0\xec\x9d\x98 \xed\x94\x84\xeb\xa1\x9c\xea\xb7\xb8\xeb\x9e\x98\xeb\xb0\x8d \xec\x96\xb8\xec\x96\xb4\xec\x9d\xb4\xeb\x8b\xa4!',
35 'Python is the best programming language!')
36
37 bul_utf8 = ('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd \xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9-\xd0\xb4\xd0\xbe\xd0\xb1\xd1\x80\xd0\xb8\xd1\x8f \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xb5\xd0\xbd \xd0\xb5\xd0\xb7\xd0\xb8\xd0\xba!',
38 'Python is the best programming language!')
39 rus_utf8 = ('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - \xd0\xbb\xd1\x83\xd1\x87\xd1\x88\xd0\xb8\xd0\xb9 \xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x8f!',
40 'Python is the best programming language!')
41
42 #----------------------------------------------------------------------
43
44 class TestPanel(wxPanel):
45 def __init__(self, parent, log):
46 self.log = log
47 wxPanel.__init__(self, parent, -1)
48
49 box = wxBoxSizer(wxVERTICAL)
50
51 if not wxUSE_UNICODE:
52 self.AddLine(box)
53 self.AddText(box, "Sorry, this wxPython was not built with Unicode support.",
54 font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
55 self.AddLine(box)
56
57 else:
58 f = self.GetFont()
59 font = wxFont(14, f.GetFamily(), f.GetStyle(), wxBOLD, false,
60 f.GetFaceName(), f.GetEncoding())
61
62 self.AddLine(box)
63 self.AddText(box, chi_uni[0], chi_uni[1], 'Chinese:', font)
64 self.AddLine(box)
65
66 self.AddText(box, lt1_uni[0], lt1_uni[1], 'Lithuanian:', font)
67 self.AddLine(box)
68 self.AddText(box, lt2_uni[0], lt2_uni[1], 'Lithuanian:', font)
69 self.AddLine(box)
70
71 self.AddText(box, kor_uni[0], kor_uni[1], 'Korean:', font)
72 self.AddLine(box)
73
74 self.AddText(box, bul_uni[0], bul_uni[1], 'Bulgarian:', font)
75 self.AddLine(box)
76 self.AddText(box, rus_uni[0], rus_uni[1], 'Russian:', font)
77 self.AddLine(box)
78
79
80 border = wxBoxSizer(wxVERTICAL)
81 border.Add(box, 1, wxEXPAND|wxALL, 10)
82 self.SetAutoLayout(true)
83 self.SetSizer(border)
84
85
86 def AddLine(self, sizer):
87 sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
88
89 def AddText(self, sizer, text1, text2='', lang='', font=None):
90 # create some controls
91 lang = wxStaticText(self, -1, lang)
92 text1 = wxStaticText(self, -1, text1)
93 text2 = wxStaticText(self, -1, text2, style=wxALIGN_RIGHT)
94 if font is not None:
95 text1.SetFont(font)
96
97 # put them in a sizer
98 row = wxBoxSizer(wxHORIZONTAL)
99 row.Add(lang)
100 row.Add(15,10)
101 row.Add(text1, 1, wxEXPAND)
102 row.Add(text2)
103
104 # put the row in the main sizer
105 sizer.Add(row, 0, wxEXPAND|wxALL, 5)
106
107
108 #----------------------------------------------------------------------
109
110 def runTest(frame, nb, log):
111 win = TestPanel(nb, log)
112 return win
113
114 #----------------------------------------------------------------------
115
116
117
118 overview = """<html><body>
119 <h2><center>wxPython Unicode Support</center></h2>
120
121 wxWindows and wxPython can be compiled with unicode support enabled or
122 disabled. Previous to wxPython 2.3.3 non-unicode mode was always
123 used. Starting with 2.3.3 either mode is supported, but only if it is
124 also available in wxWindow on the platform. Currently wxWindows only
125 supports unicode on MS Windows platforms, but with the recent release
126 of GTK+ 2.0 it is only a matter of time until it can be done on wxGTK
127 (Linux and other unixes) as well.
128 <p>
129 When unicode is enabled, then all functions and methods in wxPython
130 that return a wxString from the C++ function will return a Python
131 unicode object, and parameters to C++ functions/methods that expect a
132 wxString can accept either a Python string or unicode object. If a
133 string object is passed then it will be decoded into unicode using the
134 converter pointed to by wxConvCurrent, which will use the default
135 system encoding. If you need to use string in some other encoding
136 then you should convert it to unicode using the Python codecs first
137 and then pass the unicode to the wxPython method.
138
139
140 </body></html>
141 """