An important usability aspect of an application is having focus set by
default to the widget where it is most useful, so the user can start
working right away without having to tab his way through the window's
widgets. If you pay attention, when you first start the faren.py
example, the GtkEntry for temperature starts with the cursor focus; I've
set the "Has focus" property to True for that widget in Glade.
When using a version of PyGTK greater than 0.6.8,
show*_and_loop()
checks your interface before running; if there
is an interactive widget attached to it, and none of the View's widgets
is focused, it prints a warning to standard error explaining the View
doesn't have an interactive widget focused:
Kiwi warning: no widget is focused in view <__main__.FarenView instance at 0x8335444> but you have an interactive widget in it: <Kiwi.Basic.Entry instance at 0x8774f14>
Setting the focused widget in Glade may seem unobvious; if so, you have alternatives to set focus programatically:
grab_focus()
on the specific widget you want to focus.
If you are using a subclassed View, I would recommend doing this at the
end of your View's constructor; otherwise, call it directly before
running show_and_loop()
.
view.focus_topmost()
. For most forms, it makes sense
to focus the form widget most to the top and left when starting up the
application; you can use this convenience function to accomplish that.
When using UI composition, remember that the slave view will lose its
focus state when the function attach_slave()
is run, so if you
wish to focus a widget that is part of the slave, you will need to do it
explicitly after that function call. If the widget to be focused is in
the parent view, you should have no problems (unless you are swapping
*that* particular widget for the slave, of course).