[Urwid] ListBox, focus and colors

Bernardo Torres bernardojts at gmail.com
Fri Apr 28 16:08:37 EDT 2006


I used this and played with keypress, but got weird results. Using
solely the example doesn't seem to work. I made a mini example to test
it (attached).
Bernardo

On 4/28/06, Ian Ward <ian at excess.org> wrote:
> Bernardo Torres wrote:
> > In the tutorial, there's a ListBox that changes colors when focus
> > changes. I've used this:
> > urwid.AttrWrap(urwid.Text(mod), 'module', 'focustext') in the ListBox,
> > thinking 'focustext' would be used in focus, but none happened.
>
> I think the problem here is that Text widets are not selectable, so they
> won't become the focus.  You might try something like this:
>
> class ModuleWidget(urwid.WidgetWrap):
>      def __init__(self, mod):
>          w = urwid.Text(mod)
>          w = urwid.AttrWrap(w, 'module', 'focustext')
>          urwid.WidgetWrap.__init__(self, w)
>      def selectable(self):
>          return True
>
> and in your listbox use:
> ModuleWidget( mod )
>
> This is a custom widget that is selectable and will appear the way you
> intended.  You can also add a "keypress" method to this class to handle
> input on your widget.
>
> Regards,
> Ian
>
>
> _______________________________________________
> Urwid mailing list
> Urwid at lists.excess.org
> http://lists.excess.org/mailman/listinfo/urwid
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lista.py
Type: text/x-python
Size: 1557 bytes
Desc: not available
Url : http://lists.excess.org/pipermail/urwid/attachments/20060428/e87a64aa/lista.py


More information about the Urwid mailing list