My last patch causes problem because I replaced tabs by spaces. Here is a
better patch (and also smaller ;-)).
Benchmark
without the patch: 7.8 sec
with the patch: 4.1 sec
Haypo
diff -urb urwid-0.9.7.1/urwid/canvas.py urwid-unicode-tab/urwid/canvas.py
--- urwid-0.9.7.1/urwid/canvas.py 2006-10-09 17:18:35.000000000 +0200
+++ urwid-unicode-tab/urwid/canvas.py 2006-12-31 02:12:04.000000000 +0100
@@ -22,6 +22,7 @@
from __future__ import nested_scopes
from util import *
from escape import *
+from util import _byte_encoding
try: True # old python?
except: False, True = 0, 1
@@ -35,7 +36,7 @@
class for storing rendered text and attributes
"""
def __init__(self,text = None,attr = None, cs = None,
- cursor = None, maxcol=None):
+ cursor = None, maxcol=None, unitext=None):
"""
text -- list of strings, one for each line
attr -- list of run length encoded attributes for text
@@ -46,9 +47,10 @@
if text == None:
text = []
widths = []
- for t in text:
- if type(t) != type(""):
- raise CanvasError("Canvas text must be plain strings encoded in the screen's encoding", `text`)
+ if not unitext:
+ unitext = [ unicode(t, _byte_encoding) for t in text ]
+ for t in unitext:
+ assert type(t) == type(u"")
widths.append( calc_width( t, 0, len(t)) )
if maxcol is None:
@@ -86,6 +88,7 @@
self.cs = cs
self.cursor = cursor
self.text = text
+ self.unitext = unitext
self.maxcol = maxcol
def rows(self):
@@ -274,6 +277,7 @@
def CanvasCombine(l):
"""Stack canvases in l vertically and return resulting canvas."""
t = []
+ tu = []
a = []
c = []
rows = 0
@@ -281,6 +285,7 @@
cursor = None
for r in l:
t += r.text
+ tu += r.unitext
a += r.attr
c += r.cs
cols = max(cols, r.cols())
@@ -288,7 +293,7 @@
x,y = r.cursor
cursor = x, y+rows
rows = len( t )
- d = Canvas(t, a, c, cursor, cols )
+ d = Canvas(t, a, c, cursor, cols, unitext=tu)
return d
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid