Guilherme Polo wrote:
>> Guilherme Polo wrote:
>>> Hello,
>>>
>>> I am not sure if this is a problem related to wx only, STC only,
>>> python and windows or something else (why not?)
>>> I received a bug report from a person that tried to display some
>>> text in a STC control, but got this:
>>>
>>> File "H:\test\act_udtfinpay\udt_ui\udtgui.py", line 354, in _display_file
>>> self.uview.SetText(intext)
>>> File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\stc.py",
>>> line 2934, in SetText
>>> return _stc.StyledTextCtrl_SetText(*args, **kwargs)
>>> File "C:\Python25\lib\encodings\cp1252.py", line 15, in decode
>>> return codecs.charmap_decode(input,errors,decoding_table)
>>> UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position
>>> 112004: character maps to <undefined>
>>>
>>> It works on Linux.
>>>
>> The default encoding for the locale (apparently cp1252 based on the
>> traceback) doesn't know how to convert the \x8f character to a Unicode
>> value.
>>
>> >>> st = '\x8f'
>> >>> st
>> '\x8f'
>> >>> print st
>> è
>> >>> wx.GetDefaultPyEncoding()
>> 'mac-roman'
>> >>> st.decode('cp1252')
>> Traceback (most recent call last):
>> File "<input>", line 1, in <module>
>> File
>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/encodings/cp1252.py",
>> line 15, in decode
>> return codecs.charmap_decode(input,errors,decoding_table)
>> UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position
>> 0: character maps to <undefined>
>> >>>
>>
>>
>> You'll probably need to convert the string value to unicode yourself
>> before passing it to the STC. That way you can use a more permissive
>> conversion mode, or you can choose a different codec if you happen to
>> know the encoding of the string.
>>
>
> Isn't it possible to patch STC in a way that it would substitute those
> "bad" chars with something like '?' or anything else automatically ?
No, it's not STC that is doing the conversion. It's the standard
wxPython wxString wrapper that is used everywhere in wxPython, and it
would not be appropriate to do a relaxed conversion in most places.
If you want a relaxed conversion then you need to do it yourself.
See UnicodeBuild - wxPyWiki for more info
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Sorry for taking long to mail back, but I get a segfault now.
$ python stc_segfault.py
wx.__version__ 2.9.0.0
wx.PlatformInfo ('__WXGTK__', 'wxGTK', 'unicode', 'gtk2',
'wx-assertions-on', 'SWIG-1.3.29')
Segmentation fault (core dumped)
With this sample code:
import wx
import wx.stc as stc
class STC(stc.StyledTextCtrl):
def __init__(self, parent):
stc.StyledTextCtrl.__init__(self, parent, -1)
class Win(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
stc = STC(self)
stc.SetText(unicode('\x8f', errors='replace')) # segfault
box = wx.BoxSizer(wx.VERTICAL)
box.Add(stc, 0, wx.EXPAND, 0)
self.SetSizer(box)
box.Fit(self)
self.SetAutoLayout(True)
if __name__ == "__main__":
print 'wx.__version__', wx.__version__
print 'wx.PlatformInfo', wx.PlatformInfo
app = wx.App()
frame = Win()
frame.Show()
app.MainLoop()
···
2007/10/5, Robin Dunn <robin@alldunn.com>:
> 2007/10/3, Robin Dunn <robin@alldunn.com>:
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
--
-- Guilherme H. Polo Goncalves