]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Unicode.py
Added sizer.h
[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 programming 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\uc774 \ucd5c\uc120\uc774\ub2e4!',
17 '(Python is the best!)')
18
19
20 # Equivalents in UTF-8. Should I demo these somehow???
21 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',
22 '(Python is the best programming language)')
23
24 lt1_utf8 = ('Pythonas yra \xc5\xbeaviausia \xc5\xa1neka',
25 '(Python is the best)')
26 lt2_utf8 = ('A\xc5\xa1 m\xc4\x97gstu \xc5\xa1okolad\xc4\x85',
27 '(I like chocolate)')
28
29 kor_utf8 = ('\xed\x8c\x8c\xec\x9d\xb4\xec\x8d\xac\xec\x9d\xb4 \xec\xb5\x9c\xec\x84\xa0\xec\x9d\xb4\xeb\x8b\xa4!'
30 '(Python is the best!)')
31
32 #----------------------------------------------------------------------
33
34 class TestPanel(wxPanel):
35 def __init__(self, parent, log):
36 self.log = log
37 wxPanel.__init__(self, parent, -1)
38
39 box = wxBoxSizer(wxVERTICAL)
40
41 if not wxUSE_UNICODE:
42 self.AddLine(box)
43 self.AddText(box, "Sorry, this wxPython was not built with Unicode support.",
44 font = wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
45 self.AddLine(box)
46
47 else:
48 f = self.GetFont()
49 font = wxFont(14, f.GetFamily(), f.GetStyle(), wxBOLD, false,
50 f.GetFaceName(), f.GetEncoding())
51
52 self.AddLine(box)
53 self.AddText(box, chi_uni[0], chi_uni[1], 'Chinese:', font)
54 self.AddLine(box)
55
56 self.AddText(box, lt1_uni[0], lt1_uni[1], 'Lithuanian:', font)
57 self.AddLine(box)
58 self.AddText(box, lt2_uni[0], lt2_uni[1], 'Lithuanian:', font)
59 self.AddLine(box)
60
61 self.AddText(box, kor_uni[0], kor_uni[1], 'Korean:', font)
62 self.AddLine(box)
63
64
65 border = wxBoxSizer(wxVERTICAL)
66 border.Add(box, 1, wxEXPAND|wxALL, 10)
67 self.SetAutoLayout(true)
68 self.SetSizer(border)
69
70
71 def AddLine(self, sizer):
72 sizer.Add(wxStaticLine(self, -1), 0, wxEXPAND)
73
74 def AddText(self, sizer, text1, text2='', lang='', font=None):
75 # create some controls
76 lang = wxStaticText(self, -1, lang)
77 text1 = wxStaticText(self, -1, text1)#, style=wxALIGN_CENTRE)
78 text2 = wxStaticText(self, -1, text2)
79 if font is not None:
80 text1.SetFont(font)
81
82 # put them in a sizer
83 row = wxBoxSizer(wxHORIZONTAL)
84 row.Add(lang)
85 row.Add(25,10)
86 row.Add(text1, 1, wxEXPAND)
87 row.Add(text2)
88
89 # put the row in the main sizer
90 sizer.Add(row, 0, wxEXPAND|wxALL, 5)
91
92
93 #----------------------------------------------------------------------
94
95 def runTest(frame, nb, log):
96 win = TestPanel(nb, log)
97 return win
98
99 #----------------------------------------------------------------------
100
101
102
103 overview = """<html><body>
104 <h2><center>wxPython Unicode Support</center></h2>
105
106 wxWindows and wxPython can be compiled with unicode support enabled or
107 disabled. Previous to wxPython 2.3.3 non-unicode mode was always
108 used. Starting with 2.3.3 either mode is supported, but only if it is
109 also available in wxWindow on the platform. Currently wxWindows only
110 supports unicode on MS Windows platforms, but with the recent release
111 of GTK+ 2.0 it is only a matter of time until it can be done on wxGTK
112 (Linux and other unixes) as well.
113 <p>
114 When unicode is enabled, then all functions and methods in wxPython
115 that return a wxString from the C++ function will return a Python
116 unicode object, and parameters to C++ functions/methods that expect a
117 wxString can accept either a Python string or unicode object. If a
118 string object is passed then it will be decoded into unicode using the
119 converter pointed to by wxConvCurrent, which will use the default
120 system encoding. If you need to use string in some other encoding
121 then you should convert it to unicode using the Python codecs first
122 and then pass the unicode to the wxPython method.
123
124
125 </body></html>
126 """