Dominic LoBue wrote: > On Tue, Nov 24, 2009 at 9:17 AM, Ian Ward <[email protected]> wrote: >> You could try something like: >> >> listbox.set_focus(header_position) >> listbox.set_focus_valign('top') >> main_loop.process_input(['down']) >> >> That last line will cause the focus position change to actually happen, >> because the size information is passed along with the keypress method, >> and 'down' might move the focus back to the body. An alternative would >> be to pass some input that doesn't do anything (just use the focus >> setting side-effect) then call set_focus again on your listbox. >> > > Perfect! That worked! Thanks! > > Two questions though: > a. Why do I need to call the lsitbox's set_focus method instead of the > listwalker? > b. Is there any way to achieve the same effect as this without all the > extra overhead of redrawing the screen three times?
There's no screen redrawing there, the process_input just calls down through the widgets' keypress() methods once. The list walker is responsible for storing which widget is in focus, but the list box is responsible for remembering where to display that widget, usually how far from the top as a fraction of the list box height. The set_focus and set_focus_valign methods set flags in the list box telling it that the next time it knows its size it needs to recalculate the position of the focus widget (this can be complicated so doing it lazily isn't such a bad thing). So we're using the keypress side-effect of letting the list box set finish setting the position. Ian _______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
