[Urwid] How to get position and total number of lines in ListBox?
ian at excess.org
Mon Apr 15 18:08:51 EDT 2013
On Mon, Apr 15, 2013 at 3:29 PM, <ok100 at lavabit.com> wrote:
> I have the following code:
> My question is, how to get the current scroll position and total number
> of lines in the ui.listbox? I need this to implement scrolling to the
> end of listbox (e.g with G key) and to display current position in the
> statusbar (like in vim). Or is there some better way?
Scrolling to the end of the ListBox should be easy, just set the focus
to the last item in the list and align it with the bottom.
There does seem to be an issue with your huge text widget though, the
alignment isn't working:
But it should have :-) Maybe you could file a bug on the trac site or github?
Note that you should also be using a SimpleListWalker or similar for
your ListBox content.
For displaying your position the easiest might be to subclass ListBox
and override the render method. Within render() you can calculate the
rows displayed vs. total rows and update the status bar. That
calculation could get expensive for really long lists. You might want
to approximate it based on the position vs. the length of the ListBox
More information about the Urwid