Ticket #76 (closed defect: fixed)

Opened 18 months ago

Last modified 16 months ago

Urwid 1.0.{0,1} has broken Padding?

Reported by: AndreasKloeckner Owned by: ian
Priority: major Milestone:
Component: unknown Version: 1.0
Keywords: Cc:

Description

When using PuDB's preferences screen with urwid >= 1.0.0, the following exception is raised once the cursor is moved down towards the "custom theme" field:

Traceback (most recent call last):
  File "pudb/__init__.py", line 62, in runscript
    dbg._runscript(mainpyfile)
  File "pudb/debugger.py", line 276, in _runscript
    self.run(statement, globals=globals_, locals=locals_)
  File "/usr/local/lib/python2.7/bdb.py", line 383, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "/home/elig/source/investigate/investigate.py", line 2, in <module>
    import os, sys
  File "/home/elig/source/investigate/investigate.py", line 2, in <module>
    import os, sys
  File "/usr/local/lib/python2.7/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/local/lib/python2.7/bdb.py", line 66, in dispatch_line
    self.user_line(frame)
  File "pudb/debugger.py", line 237, in user_line
    self.interaction(frame)
  File "pudb/debugger.py", line 206, in interaction
    self.ui.call_with_ui(self.ui.interaction, exc_tuple)
  File "pudb/debugger.py", line 1224, in call_with_ui
    return f(*args, **kwargs)
  File "pudb/debugger.py", line 1339, in interaction
    self.event_loop()
  File "pudb/debugger.py", line 1298, in event_loop
    toplevel.keypress(self.size, k)
  File "pudb/ui_tools.py", line 87, in keypress
    return handler(self, size, key)
  File "pudb/debugger.py", line 1070, in do_edit_config
    self.run_edit_config()
  File "pudb/debugger.py", line 1133, in run_edit_config
    edit_config(self, CONFIG)
  File "pudb/settings.py", line 293, in edit_config
    title="Edit Preferences"):
  File "pudb/debugger.py", line 1195, in dialog
    return self.event_loop(w)[0]
  File "pudb/debugger.py", line 1290, in event_loop
    canvas = toplevel.render(self.size, focus=True)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/decoration.py", line 219, in render
    canv = self._original_widget.render(size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/container.py", line 443, in render
    self.top_w_size(size, left, right, top, bottom), focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 1318, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/container.py", line 875, in render
    focus=focus and    item_focus )
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/container.py", line 1228, in render
    focus = focus and self.focus_col == i)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 1318, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/container.py", line 875, in render
    focus=focus and    item_focus )
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/container.py", line 1228, in render
    focus = focus and self.focus_col == i)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 132, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 1318, in render
    canv = get_delegate(self).render(size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/widget.py", line 170, in finalize_render
    canv = fn(self, size, focus=focus)
  File "/usr/local/lib/python2.7/site-packages/urwid/listbox.py", line 351, in render
    raise ListBoxError, "Focus Widget %r at position %r within listbox calculated cursor coords %r but rendered cursor coords %r!" %(focus_widget,focus_pos,cursor,c_cursor)
ListBoxError: Focus Widget <Padding selectable flow widget <AttrMap selectable flow widget <Edit selectable flow widget '' edit_pos=0> attr_map={None: 'value'}> left=4> at position 13 within listbox calculated cursor coords (3, 0) but rendered cursor coords None!

This seems to be caused by the "Padding" wrapper. Turning

    theme_edit_list_item = urwid.Padding(
                urwid.AttrMap(theme_edit, "value"),
                left=4)

into

theme_edit_list_item = urwid.AttrMap(theme_edit, "value")

resolves the issue (but looks less pretty).

You may reproduce this as follows:

$ git clone git://github.com/inducer/pudb
$ cd pudb
$ git checkout fb377a95d45cc3f74450a9d37406b34c1d2914f1
$ ./try-the-debugger.sh
(hit ctrl-p, then cursor down a few times)

Change History

Changed 17 months ago by ian

This is likely due to not specifying a width for the Padding widget and many widgets not yet implementing pack().

Some time ago the width parameter was made optional with a default value of 'pack', which was likely not the best choice. If you use width=('relative', 100) you may get the behaviour you were expecting.

Still, this looks like it's exposing another bug. There's a bit too much code for me to wade through there, though. Could you provide a smaller example?

Changed 16 months ago by ian

  • status changed from new to closed
  • resolution set to fixed

This should prevent the crash [755:9c16e374d342]

But the behaviour with width='pack' is probably not what you want currently. If you pack an empty Edit widget the size will be 0 and the cursor won't be shown. This is something that will take a while to fix properly because it brings up some pretty subtle issues with Edit.

I would suggest using width=('relative', 100) and min_width=4 or similar on your Padding widgets.

Note: See TracTickets for help on using tickets.