For the record, the issue was due to an Edit initialised with "> "
caption. As it's with python 2.x, the string is not unicode, but the
text I entered was.
So in _normalise_to_caption(widget.py l.970) tu is true, but cu is
false, and the method try to encode the text unicode string to ascii (l.
987), resulting in a crash.
I resolved it by using u"> " instead of "> "
cheers
Goffi
Le 03/10/2011 02:03, Ian Ward a écrit :
>
>> - I have crashed in my app when I pressed an unicode key (like the
>> french "é"). I quickly looked the code and saw in widget.py, line 983
>> and beyong:
>>
>> tu = isinstance(text, unicode)
>> [...]
>> if tu:
>> return text.encode('ascii') # follow python2's implicit
>> conversion<=== crash
>>
>> if tu is unicode, the crash is normal (the line should be "return
>> text.encode('utf-8')"), but I'm not sure to understand the intention
>> here, so it probably need more investigation.
> Edit widgets now try to convert their edit_text to the same type
> (unicode or bytes) as their captions. If the caption is unicode but
> input received is bytes (because the terminal isn't detected to be in
> UTF-8 mode) then that line will run. The proper fix is probably to use
> the detected encoding instead of 'ascii'.
>
> Are you sure your terminal is detected as using utf-8? what does
>
> import urwid; print urwid.get_encoding_mode()
>
> say?
>
> A workaround is to set your caption to '' (or any byte string) which was
> the default in 0.9.9. For the best compatibility I'd have to change
> that back, but byte strings really aren't a good default for edit widgets.
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid