[Urwid] Strange behaviour of ListBox
Ian Ward
ian at excess.org
Mon Jul 24 23:54:45 EDT 2006
jm at jm10.no-ip.com wrote:
> I don't want the body to lose the focus (once at the bottom at the body, the top
> listbox selects another widget on 'down') and I don't know how to solve that.
> Your answer seems to say it is possible... maybe like that (not yet committed) :
>
> http://hachoir.python-hosting.com/file/hachoir/trunk/src/hachoir/ui/urwid/urwid_ui.py
> --- src/hachoir/ui/urwid/urwid_ui.py (revision 449)
> +++ src/hachoir/ui/urwid/urwid_ui.py (working copy)
> @@ -408,2 +408,3 @@
> log = BoxAdapter(ListBox(msgs[1]), 0)
> + log.selectable = lambda: False
> top = ListBox((body, AttrWrap(sep, 'sep'), log))
> @@ -438,3 +439,3 @@
> else:
> - body.keypress(size[:1], e)
> + top.keypress(size, e)
> except AssertionError:
That works. You could also use:
log = BoxAdapter(ListBox(msgs[1]), 0)
foot = urwid.Pile([ AttrWrap(sep, 'sep'), log ])
top = Frame( body, footer = foot )
because a Frame won't change focus away from body unless you tell it to.
But if you support mouse events someone might still click to change
the focus, so you could use your lamba trick on "foot".
Another way to say "this widget should never be selectable" is to use
WidgetWrap:
class NeverSelectable(urwid.WidgetWrap):
def selectable(self):
return False
foot = NeverSelectable(foot)
Ian
More information about the Urwid
mailing list