[Urwid] Re: placing buttons and widgets

Ian Ward ian at excess.org
Sun Oct 8 10:54:57 EDT 2006

Fabian Braennstroem wrote:
> Hi,
> * Rebecca Breu <rebecca at rbreu.de> wrote:
>> buttom, put the "main view" inside a Frame or Pile widget. If you can live
>> without those fancy thin unicode lines, that's not so hard to do. Otherwise
>> the LineBox widget could help...

LineBox is easy, and vertical lines aren't too difficult:

vline = urwid.SolidFill(u'\u2502')

# put it between two box widgets
boxcol = urwid.Columns([boxwidget1, ('fixed',1,vline), boxwidget2])

# put it between two flow widgets
flowcol = urwid.Columns([flowwidget1, ('fixed',1,vline), flowwidget2],

> Thanks! When reading it, I get one more question in mind :-)
> For an urwid based lfm I would like to set my own
> keybindings in a vim-like way, e.g. I don't want to use the
> Up and Down key, but 'j' and 'k' for scrolling to the next
> line. Is there a urwid specific way to define those
> keybindings or would be similar to lfm, where I just define
> a function which goes to the next item in a 'list'!?

That depends on what you want.

Currently the "up", "down", "page up" and "page down" keys are hard 
coded into the ListBox widget and the "up" and "down" keys are hard 
coded into the Pile widget.

You can translate "j" and "k" to "down" and "up" if they aren't handled 
by an edit widget or similar with code like:

# ... part of your main loop
for k in self.ui.get_input():
	# (not shown) do urwid.is_mouse_event stuff..
	k = self.view.keypress(size, k)
	if k == "j":
		self.view.keypress(size, "down")
	if k == "k":
		self.view.keypress(size, "up")
# ...

If that's not what you're looking for, would you tell me what behaviour 
you want when the user presses the "up" and "down" keys?


More information about the Urwid mailing list