[Urwid] ListBoxError - focus_canvas.rows() != focus_rows

Sitti Amarittapark sitti at pancetera.com
Wed Jul 7 19:54:55 EDT 2010


I think that found the answer.

It is in decoration.py. Padding.rows() causes this exception. Looks
like the calculation doesn't include the padding margin. I made the
following change and it works. I am not sure if this enough as a
general fix. It doesn't do anything with the CLIP case yet.

thanks,
Sitti
------------------- Detail --------------------------
class Padding

OLD:
    def rows(self, size, focus=False):
        """Return the rows needed for self.original_widget."""
        if self._width_type == PACK:
            pcols, prows = self._original_widget.pack(size, focus)
            return prows
        if self._width_type == CLIP:
            fcols, frows = self._original_widget.pack((), focus)
            return frows
        (maxcol,) = size
        left, right = self.padding_values(size, focus)
        return self._original_widget.rows((maxcol-left-right,), focus=focus)

NEW:
    def rows(self, size, focus=False):
        """Return the rows needed for self.original_widget."""
        (maxcol,) = size
        left, right = self.padding_values(size, focus)
        if self._width_type == PACK:
            pcols, prows =
self._original_widget.pack((maxcol-left-right,), focus)
            return prows
        if self._width_type == CLIP:
            fcols, frows = self._original_widget.pack((), focus)
            return frows
        return self._original_widget.rows((maxcol-left-right,), focus=focus)



On Wed, Jul 7, 2010 at 10:44 AM, Sitti Amarittapark <sitti at pancetera.com> wrote:
> Hi all,
>
> I got the following exception in urwid. I found that I can avoid the
> problem by resizing the ssh window. However I don't have that option
> when running the code in the 80 columns x 24 lines console. Is there
> anything I can do to avoid the problem? Did I do anything wrong? I am
> using v 0.9.9.1.
>
> Thanks very much,
> -Sitti
>
> Traceback (most recent call last):
>  File "./console.py", line 235, in <module>
>    main()
>  File "./console.py", line 230, in main
>    gSystem.run('welcome')
>  File "/d2/sm/console/pic/manage.py", line 92, in run
>    self.runOne(viewId, param)
>  File "/d2/sm/console/pic/manage.py", line 126, in runOne
>    self.replaceView(pop, viewId, param)
>  File "/d2/sm/console/pic/manage.py", line 159, in replaceView
>    self.loopController.run()
>  File "/d2/sm/console/pic/draw.py", line 311, in run
>    self.loop.run()
>  File "/usr/lib/python2.5/site-packages/urwid/main_loop.py", line 170, in run
>    self.screen.run_wrapper(self._run)
>  File "/usr/lib/python2.5/site-packages/urwid/raw_display.py", line
> 234, in run_wrapper
>    return fn()
>  File "/usr/lib/python2.5/site-packages/urwid/main_loop.py", line 188, in _run
>    self.event_loop.run()
>  File "/usr/lib/python2.5/site-packages/urwid/main_loop.py", line 498, in run
>    self._loop()
>  File "/usr/lib/python2.5/site-packages/urwid/main_loop.py", line 523, in _loop
>    self._watch_files[fd]()
>  File "/usr/lib/python2.5/site-packages/urwid/main_loop.py", line
> 238, in _update
>    self.draw_screen()
>  File "/usr/lib/python2.5/site-packages/urwid/main_loop.py", line
> 361, in draw_screen
>    canvas = self.widget.render(self.screen_size, focus=True)
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 1302, in render
>    canv = self._w.render(size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/container.py", line
> 1173, in render
>    focus = focus and self.focus_col == i)
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/decoration.py", line
> 202, in render
>    canv = self._original_widget.render(size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/container.py", line
> 569, in render
>    focus and self.focus_part == 'body')
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/container.py", line
> 569, in render
>    focus and self.focus_part == 'body')
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/decoration.py", line
> 202, in render
>    canv = self._original_widget.render(size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/widget.py", line 135,
> in cached_render
>    canv = fn(self, size, focus=focus)
>  File "/usr/lib/python2.5/site-packages/urwid/listbox.py", line 349, in render
>    raise ListBoxError, "Focus Widget %s at position %s within listbox
> calculated %d rows but rendered %d!"%
> (`focus_widget`,`focus_pos`,focus_rows, focus_canvas.rows())
> urwid.listbox.ListBoxError: Focus Widget <Padding flow widget <Text
> flow widget 'This virtual appliance is named rashid.'> left=1 right=1>
> at position 0 within listbox calculated 1 rows but rendered 2!
>



More information about the Urwid mailing list