[Urwid] Problem with Text widgets & leading spaces
Rebecca Breu
rebecca at rbreu.de
Wed Mar 22 07:47:25 EST 2006
Hi all!
I observed a problem with Text widgets that begin with a space.
If I put such Text widgets into a ListBox, and resize the terminal window
to something very narrow, that can lead to an AssertionError. Without leading
spaces (if I replace them by underscores, for example), all works just fine.
Here is my program:
###################################################################
#! /usr/bin/env python
import urwid.curses_display;
import urwid;
def body():
mylist = urwid.ListBox([urwid.Text(" Die Gedanken sind frei,"),
urwid.Text(" wer kann sie erraten?")]);
return mylist;
def run():
dim = ui.get_cols_rows();
main_view = body();
#Main event loop:
while True:
ui.draw_screen(dim, main_view.render(dim, True));
keys = ui.get_input()
if "window resize" in keys:
dim = ui.get_cols_rows();
main_view = body();
ui = urwid.curses_display.Screen();
ui.run_wrapper(run)
######################################################################
You may have to try out which terminal size lets the program crash.
For me, it's an aterm or xterm with *exactly* width 3.
The backtracke is the following:
######################################################################
Traceback (most recent call last):
File "./test.py", line 35, in ?
ui.run_wrapper(run)
File "/home/rbreu/unicore/config_server/config_bin/urwid/curses_display.py",
line 160, in run_wrapper
return fn()
File "./test.py", line 23, in run
ui.draw_screen(dim, main_view.render(dim, True));
File "/home/rbreu/unicore/config_server/config_bin/urwid/listbox.py", line
254, in render
focus_canvas = focus_widget.render((maxcol,), focus=focus)
File "/home/rbreu/unicore/config_server/config_bin/urwid/widget.py", line 166,
in render
maxcol )
File "/home/rbreu/unicore/config_server/config_bin/urwid/canvas.py", line 362,
in apply_text_layout
s = LayoutSegment(seg)
File "/home/rbreu/unicore/config_server/config_bin/urwid/util.py", line 300,
in __init__
assert self.sc > 0, `seg`
AssertionError: (0, 0, 0)
######################################################################
I'm using:
urwid-0.9.1
python 2.4.1
Linux-2.6.13 (SuSE-10.0-i586)
Greetings,
Rebecca
More information about the Urwid
mailing list