]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Unicode.py
3 from wxPython
.wx
import *
5 #----------------------------------------------------------------------
8 chi_uni
= (u
'Python \u662f\u6700\u597d\u7684\u7de8\u7a0b\u8a9e\u8a00\uff01',
9 '(Python is the 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',
16 kor_uni
= (u
'\ud30c\uc774\uc36c\uc774 \ucd5c\uc120\uc774\ub2e4!',
17 '(Python is the best!)')
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)')
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',
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!)')
32 #----------------------------------------------------------------------
34 class TestPanel(wxPanel
):
35 def __init__(self
, parent
, log
):
37 wxPanel
.__init
__(self
, parent
, -1)
39 box
= wxBoxSizer(wxVERTICAL
)
43 self
.AddText(box
, "Sorry, this wxPython was not built with Unicode support.",
44 font
= wxFont(12, wxSWISS
, wxNORMAL
, wxBOLD
))
49 font
= wxFont(14, f
.GetFamily(), f
.GetStyle(), wxBOLD
, false
,
50 f
.GetFaceName(), f
.GetEncoding())
53 self
.AddText(box
, chi_uni
[0], chi_uni
[1], 'Chinese:', font
)
56 self
.AddText(box
, lt1_uni
[0], lt1_uni
[1], 'Lithuanian:', font
)
58 self
.AddText(box
, lt2_uni
[0], lt2_uni
[1], 'Lithuanian:', font
)
61 self
.AddText(box
, kor_uni
[0], kor_uni
[1], 'Korean:', font
)
65 border
= wxBoxSizer(wxVERTICAL
)
66 border
.Add(box
, 1, wxEXPAND|wxALL
, 10)
67 self
.SetAutoLayout(true
)
71 def AddLine(self
, sizer
):
72 sizer
.Add(wxStaticLine(self
, -1), 0, wxEXPAND
)
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
)
83 row
= wxBoxSizer(wxHORIZONTAL
)
86 row
.Add(text1
, 1, wxEXPAND
)
89 # put the row in the main sizer
90 sizer
.Add(row
, 0, wxEXPAND|wxALL
, 5)
93 #----------------------------------------------------------------------
95 def runTest(frame
, nb
, log
):
96 win
= TestPanel(nb
, log
)
99 #----------------------------------------------------------------------
103 overview
= """<html><body>
104 <h2><center>wxPython Unicode Support</center></h2>
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.
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.