I want to use wx.lib.fancytext.StaticFancyText control in my wxPython application and make my script run under WinXP and Linux.
I found this control does not support unicode text.
Here is my testing code:
···
#-----------------------------------------------------------------------------------------
#!/usr/bin/python
-- coding: utf-8 --
import wx
import wx.lib.fancytext as fancytext
class MyFrame(wx.Frame):
def init(self, *args, **kwargs):
wx.Frame.init(self, *args, **kwargs)
toppanel = wx.Panel(self)
topsizer = wx.BoxSizer(wx.HORIZONTAL)
# NOTE: create a unicode text
stf = fancytext.StaticFancyText(toppanel, -1, u'<font color="red">测试</font>')
topsizer.Add(stf)
toppanel.SetSizer(topsizer)
topsizer.SetSizeHints(self)
if name == ‘main’:
app = wx.App(redirect=False)
frame = MyFrame(parent=None)
frame.Show()
app.MainLoop()
#-----------------------------------------------------------------------------------------
Save it as a utf-8 script file.
This script file can run under Linux But failed on WinXP.
When I ran it under WinXP, I got below error:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
E:\Desktop>test.py
Traceback (most recent call last):
File “E:\Desktop\test.py”, line 24, in
frame = MyFrame(parent=None)
File “E:\Desktop\test.py”, line 14, in init
stf = fancytext.StaticFancyText(toppanel, -1, u’娴?璇?</fo
')
File “D:\System\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\fancytext
.py”, line 395, in init
bmp = RenderToBitmap(text, background)
File “D:\System\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\fancytext
.py”, line 356, in RenderToBitmap
width, height, dy = GetFullExtent(str, dc, enclose)
File “D:\System\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\fancytext
.py”, line 346, in GetFullExtent
RenderToRenderer(str, renderer, enclose)
File “D:\System\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\fancytext
.py”, line 329, in RenderToRenderer
p.Parse(str, 1)
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 50-51: ord
inal not in range(128)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Does anyone know how to fix this bug? I want to use StaticFancyText for both WinXP and Linux.