[Urwid] Tab focus changing, Radio buttons, Illuminating buttons
ian at excess.org
Wed Nov 9 21:56:45 EST 2005
antonio araujo wrote:
>Hello Ian. Thanks for your answer, but after change the line, it dont
>works for me.
>I will send you the pre-pre-alpha version of my RecordEditor.
>I have many problems with urwid, and I need some help.
>-I need to navigate the fields with the tab key by default.
If you want tab to move through items in a listbox then you need to call
get_focus and set_focus on the listbox when get_input includes 'tab' or
In your code that could be done in the same place you are handling 'f1',
'f2' etc. You are using a simple list as the body of your listbox, so
the positions are just integer values. You could move to the next field
with code like this:
old_widget, old_position = self.listbox.get_focus()
self.listbox.set_focus( (old_position +1) % len(self.listbox_contents) )
in the above code listbox_contents is the list that you pass into the
ListBox class. It is a good idea to assign this list to a variable so
that you can edit it later, with code like this when you construct the
self.listbox_contents = CONTENTS
self.listbox = urwid.ListBox(self.listbox_contents)
>-I need a simple component to do a RadioButton, something like:
> x = RadioButton("red", "green", "blue")
If you want to make 3 radio buttons in one group then you can use code
self.color_choices = 
red_radio = urwid.RadioButton( self.color_choices, "Red" )
green_radio = urwid.RadioButton( self.color_choices, "Green" )
blue_radio = urwid.RadioButton( self.color_choices, "Blue" )
self.list_contents += [ red_radio, green_radio, blue_radio ]
You can later find out which button is pressed by iterating through
self.color_choices and calling get_state and get_label on each element
to see which one is checked.
>-I dont understand (by now) how to make the buttons illuminate
>completely when in focus.
Illuminating buttons is done with the AttrWrap class. You can pass in
an attribute to use when the wrapped widget is in focus. There are
examples of this in the tour and dialog sample applications.
>-When I return from the record edition, I see some Ctrl+D in the
>screen when I move from one button to other. I dont know if my idea of
>changing screens is correct in urwid.
I'm not sure, what do you mean when you say return from the record edition?
>Sorry Ian. I am learning python, urwid and KirbyBase, and I come from Java.
>Your help will be very apreciatted for me.
>Thanks a lot.
More information about the Urwid