Hi!

I'm trying to write a urwid backend for my UI abstraction layer [1]. While doing some simple tests, I've encountered an exception that might either be a bug or a misunderstanding in how to use urwid.

Steps to reproduce:
1. Run the attached Python script.
2. Press <cursor down>

The following traceback will be printed:

Traceback (most recent call last):
   File "./x.py", line 30, in ?
     ui.run_wrapper( run )
File "/usr/lib/python2.4/site-packages/urwid/curses_display.py", line 202, in run_wrapper
     return fn()
   File "./x.py", line 28, in run
     fill.keypress( (cols, rows), k )
File "/usr/lib/python2.4/site-packages/urwid/widget.py", line 1460, in keypress
     return self.body.keypress( (maxcol,), key )
File "/usr/lib/python2.4/site-packages/urwid/widget.py", line 2380, in keypress
     if self.focus_item.move_cursor_to_coords(
File "/usr/lib/python2.4/site-packages/urwid/widget.py", line 595, in move_cursor_to_coords
     pos = calc_pos( self.get_text()[0], trans, x, y )
File "/usr/lib/python2.4/site-packages/urwid/util.py", line 592, in calc_pos
     pos = calc_line_pos( text, layout[row], pref_col )
File "/usr/lib/python2.4/site-packages/urwid/util.py", line 566, in calc_line_pos
     if closest_sc is None or ( abs(pref_col-current_sc)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'


This only happens for the combination Button+Edit (in this order). Using the same widget twice or listing the Edit first works fine. Because of that, I suspect it's a bug, but since I haven't fully grasped urwids design yet, it might as well just work by chance in the other cases.


CU Sascha

[1] http://projects.silbe.org/permalink/en/i_7249a450%2d4b98%2d44a5%2da8a0%2dceefdfef7d5e_%2d%2d%3E.html

--
http://sascha.silbe.org/
http://www.infra-silbe.de/
#!/usr/bin/env python
import urwid.curses_display
import urwid

ui = urwid.curses_display.Screen()

def run():
        cols, rows = ui.get_cols_rows()

        ask1 = urwid.Edit("What is your name?")
#        ask1.set_edit_text("")
        button1 = urwid.Button("Button1")
#        button2 = urwid.Button("Button2")
#        ask2 = urwid.Edit("Foobar")
#        ask2.set_edit_text("a")
        pile = urwid.Pile([button1, ask1])
        fill = urwid.Filler( pile )
        reply = None

        while True:
                canvas = fill.render( (cols, rows), focus=True )
                ui.draw_screen( (cols, rows), canvas )

                keys = ui.get_input()
                for k in keys:
                        if k == "enter":
                                return
                        if fill.selectable():
                                fill.keypress( (cols, rows), k )

ui.run_wrapper( run )

Attachment: pgpeSidoE48GS.pgp
Description: PGP signature

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

Reply via email to