[Urwid] simple layout - howto?

Ian Ward ian at excess.org
Mon Jun 26 22:01:23 EDT 2006


markus espenhain wrote:
> what i would try to implement is a simple layout like this one:
> 
> +---------------------------------------+
> |[header]                |
> +---------------------------------------+
> |[content (just text)]            |
> |                    |
> |                    |
> |                    |
> |                    |
> |                    |
> |                    |
> |                    |
> |                    |
> |                    |
> |                    |
> +---------------------------------------+
> |[edit field (user inputs)]        |
> +---------------------------------------+
> |[status bar]                |
> +---------------------------------------+
> 
> i'd be very happy about a little hint that may leads towards the right 
> direction..

The best way to create a layout like that right now would be something like:

header = urwid.Text("Your header stuff goes here")
user_input = urwid.Edit("Type things here ->","")
status_bar = urwid.Text("Everything is just great")
footer = urwid.Pile( [user_input, status_bar], focus_item=0 )
content_list = [urwid.Text("content goes here")]
content = urwid.ListBox( content_list )
frame = urwid.Frame( content, header, footer, focus_part='footer' )

then you can use the frame widget as your top level widget -- Call its 
render function when you need to redraw the screen, call its keypress 
function when you need to send it user input.

you can read the user's input with user_input.get_edit_text(), modify 
the status bar with status_bar.set_text() and change the content by 
modifying the content_list (using in-place editing, not assignment).

Hope this helps.

Ian




More information about the Urwid mailing list