[Urwid] urwid in pure unicore

Victor Stinner victor.stinner at haypocalc.com
Sat Dec 30 19:37:25 EST 2006


Julien Muchembled learn me how to record stdin and then replay it:
   tee events|program  # record
   program < events
Using that, I'm able to do good benchmark. Something _necessary_ to work on 

So one big problem of urwid in UTF-8 is that urwid convert Unicode string to 
UTF-8 and then reconvert them to Unicode... It's slow and useless.

The problem is in Canvas class. The attached patch is a proposition to fix the 
problem (double conversion). The idea is to store text encoded for the 
terminal (UTF-8) in Canvas.text but also to keep the Unicode version in 

Instead of "for ut in unitext: ..." we may use:
if unitext:
   for t in text:
      t = unicode(t, charset)
^^ convert to unicode here avoid many slow functions

Don't apply my patch! It's just an example to show the problem. With my patch, 
a UTF-8 terminal and with a program (hachoir-urwid) speaking full-Unicode: 
the program runs 2 times faster (8 seconds => 4 seconds) ;-) It's not 
an "optimization", it's a fix urwid code :)


Would it be possible to use spaces in urwid code because I hate TAB! PEP 8 
propose "4 spaces per indentation level":


Where/How can I download urwid by subversion?

Victor Stinner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: urwid-unicode.patch
Type: text/x-diff
Size: 4757 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20061231/0e054367/urwid-unicode.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: canvas.py
Type: application/x-python
Size: 11971 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20061231/0e054367/canvas.bin

More information about the Urwid mailing list