]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/Unicode.py
moved vararg CRT functions wrappers to a new wxcrtvararg.h header
[wxWidgets.git] / wxPython / demo / Unicode.py
CommitLineData
03d84e7a 1
8fa876ca 2import wx
03d84e7a
RD
3
4#----------------------------------------------------------------------
5
6# Some unicode strings
257f0da1 7chi_uni = (u'Python \u662f\u6700\u597d\u7684\u7de8\u7a0b\u8a9e\u8a00\uff01',
69ca6f3c 8 'Python is the best\nprogramming language!')
03d84e7a
RD
9
10lt1_uni = (u'Pythonas yra \u017eaviausia \u0161neka',
69ca6f3c 11 'Python is the best')
03d84e7a 12lt2_uni = (u'A\u0161 m\u0117gstu \u0161okolad\u0105',
69ca6f3c 13 'I like chocolate')
03d84e7a 14
69ca6f3c
RD
15kor_uni = (u'\ud30c\uc774\uc36c\uc740 \ucd5c\uace0\uc758 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc774\ub2e4!',
16 'Python is the best\nprogramming language!')
17
18bul_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!',
19 'Python is the best\nprogramming language!')
20rus_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!',
21 'Python is the best\nprogramming language!')
257f0da1 22
03d84e7a
RD
23
24# Equivalents in UTF-8. Should I demo these somehow???
257f0da1 25chi_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',
69ca6f3c 26 'Python is the best programming language')
03d84e7a
RD
27
28lt1_utf8 = ('Pythonas yra \xc5\xbeaviausia \xc5\xa1neka',
69ca6f3c 29 'Python is the best')
03d84e7a 30lt2_utf8 = ('A\xc5\xa1 m\xc4\x97gstu \xc5\xa1okolad\xc4\x85',
69ca6f3c
RD
31 'I like chocolate')
32
33kor_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!',
34 'Python is the best programming language!')
03d84e7a 35
69ca6f3c
RD
36bul_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!',
37 'Python is the best programming language!')
38rus_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!',
39 'Python is the best programming language!')
257f0da1 40
03d84e7a
RD
41#----------------------------------------------------------------------
42
8fa876ca 43class TestPanel(wx.Panel):
03d84e7a
RD
44 def __init__(self, parent, log):
45 self.log = log
8fa876ca 46 wx.Panel.__init__(self, parent, -1)
03d84e7a 47
8fa876ca 48 box = wx.BoxSizer(wx.VERTICAL)
03d84e7a 49
8fa876ca 50 if not wx.USE_UNICODE:
03d84e7a
RD
51 self.AddLine(box)
52 self.AddText(box, "Sorry, this wxPython was not built with Unicode support.",
8fa876ca 53 font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
03d84e7a
RD
54 self.AddLine(box)
55
56 else:
57 f = self.GetFont()
8fa876ca 58 font = wx.Font(14, f.GetFamily(), f.GetStyle(), wx.BOLD, False,
03d84e7a
RD
59 f.GetFaceName(), f.GetEncoding())
60
61 self.AddLine(box)
62 self.AddText(box, chi_uni[0], chi_uni[1], 'Chinese:', font)
63 self.AddLine(box)
64
65 self.AddText(box, lt1_uni[0], lt1_uni[1], 'Lithuanian:', font)
66 self.AddLine(box)
67 self.AddText(box, lt2_uni[0], lt2_uni[1], 'Lithuanian:', font)
68 self.AddLine(box)
69
257f0da1
RD
70 self.AddText(box, kor_uni[0], kor_uni[1], 'Korean:', font)
71 self.AddLine(box)
72
69ca6f3c
RD
73 self.AddText(box, bul_uni[0], bul_uni[1], 'Bulgarian:', font)
74 self.AddLine(box)
75 self.AddText(box, rus_uni[0], rus_uni[1], 'Russian:', font)
76 self.AddLine(box)
77
03d84e7a 78
8fa876ca
RD
79 border = wx.BoxSizer(wx.VERTICAL)
80 border.Add(box, 1, wx.EXPAND|wx.ALL, 10)
1e4a197e 81 self.SetAutoLayout(True)
03d84e7a
RD
82 self.SetSizer(border)
83
84
85 def AddLine(self, sizer):
8fa876ca 86 sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND)
03d84e7a
RD
87
88 def AddText(self, sizer, text1, text2='', lang='', font=None):
89 # create some controls
8fa876ca
RD
90 lang = wx.StaticText(self, -1, lang)
91 text1 = wx.StaticText(self, -1, text1)
92 text2 = wx.StaticText(self, -1, text2, style=wx.ALIGN_RIGHT)
03d84e7a
RD
93 if font is not None:
94 text1.SetFont(font)
95
96 # put them in a sizer
8fa876ca 97 row = wx.BoxSizer(wx.HORIZONTAL)
03d84e7a 98 row.Add(lang)
8fa876ca
RD
99 row.Add((15,10))
100 row.Add(text1, 1, wx.EXPAND)
03d84e7a
RD
101 row.Add(text2)
102
103 # put the row in the main sizer
8fa876ca 104 sizer.Add(row, 0, wx.EXPAND|wx.ALL, 5)
03d84e7a
RD
105
106
107#----------------------------------------------------------------------
108
109def runTest(frame, nb, log):
110 win = TestPanel(nb, log)
111 return win
112
113#----------------------------------------------------------------------
114
115
116
117overview = """<html><body>
118<h2><center>wxPython Unicode Support</center></h2>
119
120wxWindows and wxPython can be compiled with unicode support enabled or
121disabled. Previous to wxPython 2.3.3 non-unicode mode was always
122used. Starting with 2.3.3 either mode is supported, but only if it is
123also available in wxWindow on the platform. Currently wxWindows only
124supports unicode on MS Windows platforms, but with the recent release
125of GTK+ 2.0 it is only a matter of time until it can be done on wxGTK
126(Linux and other unixes) as well.
127<p>
128When unicode is enabled, then all functions and methods in wxPython
129that return a wxString from the C++ function will return a Python
130unicode object, and parameters to C++ functions/methods that expect a
131wxString can accept either a Python string or unicode object. If a
132string object is passed then it will be decoded into unicode using the
133converter pointed to by wxConvCurrent, which will use the default
134system encoding. If you need to use string in some other encoding
135then you should convert it to unicode using the Python codecs first
136and then pass the unicode to the wxPython method.
137
138
139</body></html>
140"""
1fded56b
RD
141
142
143
144
145if __name__ == '__main__':
146 import sys,os
147 import run
8eca4fef 148 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b 149