Ian Ward wrote:
Nuutti Kotivuori wrote:
In any case, this slowness is a showstopper for me - and I'm wondering
what would be the best way to optimize this.

Currently Urwid redraws all the visible widgets every time you call render. The Text widgets do cache the result of their alignment and wrapping, but Urwid might be calling calc_width unnecessarily on text it should already know the width of.

Please try the attached patch. The Columns widget was causing calc_width to be called unnecessarily.

Ian
Index: urwid/canvas.py
===================================================================
RCS file: /home/cvs/urwid/urwid/canvas.py,v
retrieving revision 1.51
diff -u -r1.51 canvas.py
--- urwid/canvas.py	2 Oct 2006 03:08:27 -0000	1.51
+++ urwid/canvas.py	11 Oct 2006 18:16:10 -0000
@@ -35,7 +35,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, check_width=True):
 		"""
 		text -- list of strings, one for each line
 		attr -- list of run length encoded attributes for text
@@ -45,11 +45,15 @@
 		"""
 		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`)
-			widths.append( calc_width( t, 0, len(t)) )
+
+		if check_width:
+			widths = []
+			for t in text:
+				if type(t) != type(""):
+					raise CanvasError("Canvas text must be plain strings encoded in the screen's encoding", `text`)
+				widths.append( calc_width( t, 0, len(t)) )
+		else:
+			widths = [maxcol] * len(text)
 
 		if maxcol is None:
 			if widths:
@@ -347,7 +351,7 @@
 		if cnv.cursor:
 			cnv.translate_coords(x, 0)
 			cursor = cnv.cursor
-	d = Canvas( ["".join(lt) for lt in t], a, c, cursor, xw )
+	d = Canvas( ["".join(lt) for lt in t], a, c, cursor, xw, False )
 	return d
 
 
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to