[Urwid] Shifting focus while using urwid.Columns

Abhinav Singh abhinavsingh at ymail.com
Wed Jul 31 10:14:04 EDT 2013


Thanks Patrick.

Even using input_filter looks like an option here. However, I still remember reading in the documentation that these strategy might not be a good way to proceed as application gets complex. 

Would still love to hear about the official way to handle this. From docs I get an idea that we should extend keypress method, unfortunately that seems to break things for me.

--
Abhinav

On 31-Jul-2013, at 5:25 PM, Patrick Totzke <patricktotzke at gmail.com> wrote:

> I'm not sure how relavant this is, but I'm using the
> `input_filter` parameter to `urwid.MainLoop`.
> It's like the `unhandeled_input` but it is triggered *before*
> any widget sees the input key.
> I then manually interpret the keypresses and possibly
> let them do focus-changes on the widgets directly.
> 
> https://github.com/pazz/alot/blob/master/alot/ui.py#L74
> (beware: this is *not* a minimal working example!)
> 
> HTH,
> /p
> 
> Quoting Abhinav Singh (2013-07-31 12:35:13)
>> Was able to make it work by using following piece of code:
>> 
>> leftbox = RemotailListBox(RemotailWalker())
>> rightbox = RemotailListBox(RemotailWalker())
>> column = RemotailColumns([leftbox, rightbox])
>> header = urwid.AttrMap(urwid.Text(header_text), 'header')
>> footer = urwid.AttrMap(urwid.Text(footer_text), 'footer')
>> frame = urwid.Frame(column, header=header, footer=footer)
>> 
>> def unhandled_input(key):
>>    if key.lower() == 'q':
>>        raise urwid.ExitMainLoop()
>>    elif key in ('right', 'tab'):
>>        column.focus_position = column.focus_position + 1 if
>> column.focus_position < len(column.contents) - 1 else 0
>>    elif key == 'left':
>>        column.focus_position = column.focus_position - 1 if
>> column.focus_position > 0 else len(column.contents) - 1
>> 
>> loop = urwid.MainLoop(frame, palette, unhandled_input=unhandled_input)
>> 
>> However, I read that using unhanded_input for controlling application keys can
>> be a bad idea. I tried overriding keypress method inside RemotailColumns by
>> handling 'right', 'tab', 'left' keys and returning key for other cases. But
>> that stopped the scrolling using up/down arrow keys.
>> 
>> --
>> Abhinav
>> 
>> On 31-Jul-2013, at 4:18 PM, Abhinav Singh <abhinavsingh at ymail.com> wrote:
>> 
>> 
>>    Hi,
>> 
>>    I m new to urwid and here is  the layout I am currently using:
>> 
>>    leftbox = urwid.ListBox(RemotailWalker())
>>    rightbox = urwid.ListBox(RemotailWalker())
>>    column = urwid.Columns([leftbox, rightbox])
>>    header = urwid.AttrMap(urwid.Text(header_text), 'header')
>>    footer = urwid.AttrMap(urwid.Text(footer_text), 'footer')
>>    frame = urwid.Frame(column, header=header, footer=footer)
>>    loop = urwid.MainLoop(frame, palette, unhandled_input=exit_on_q)
>> 
>>    When I launch my console application focus is always set to leftbox. How
>>    can I use my mouse or probably arrows to shift focus to right box?
>> 
>>    Any pointers to relevant documentation or example will be of great help.
>> 
>>    --
>>    Abhinav
>>    _______________________________________________
>>    Urwid mailing list
>>    Urwid at lists.excess.org
>>    http://lists.excess.org/mailman/listinfo/urwid
> 
> _______________________________________________
> Urwid mailing list
> Urwid at lists.excess.org
> http://lists.excess.org/mailman/listinfo/urwid




More information about the Urwid mailing list