Hi List,

I'm having some problems using a Text instance's pack method to get the screen columns a multi-line string will display as. I've stuck a short example that demonstrates this problem for me at the end of the email.

It looks as though there's an off-by-one error in the special-case handling of '\n' in strings, and I believe the fix is to apply the following patch:

-- snip --

--- widget.py   2006-09-17 23:42:53.000000000 +0100
+++ /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/urwid/widget.py 2006-09-17 23:43:04.000000000 +0100
@@ -239,7 +239,7 @@
                i = 0
                cols = 0
                while i < len(text):
-                       j = text.find('\n')
+                       j = text.find('\n', i)
                        if j == -1:
                                j = len(text)
                        c = calc_width(text, i, j)

-- snip --

Graham

-- snip --

sirion:~ graham$ python
Python 2.3.5 (#1, Jan 13 2006, 20:13:11)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urwid
>>> urwid.__version__
'0.9.6'
>>> t = urwid.Text('foo\nbar')
>>> t.pack()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/urwid/widget.py", line 245, in pack
    c = calc_width(text, i, j)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/site-packages/urwid/util.py", line 561, in calc_width
    assert start_offs <= end_offs, `start_offs, end_offs`
AssertionError: (4, 3)
>>>

-- snip --


_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to