[Urwid] Shifting focus while using urwid.Columns

Abhinav Singh abhinavsingh at ymail.com
Wed Jul 31 07:35:13 EDT 2013


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.excess.org/pipermail/urwid/attachments/20130731/c6f595ca/attachment.htm 


More information about the Urwid mailing list