Discussion:
[Urwid] How to get position and total number of lines in ListBox?
ok100
2013-04-15 19:29:30 UTC
Permalink
Hello,

I have the following code:

http://bpaste.net/show/91579/

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?

Thanks in advance
O
Ian Ward
2013-04-15 22:08:51 UTC
Permalink
Post by ok100
Hello,
http://bpaste.net/show/91579/
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:

self.listbox.set_focus(2)
self.listbox.set_focus_valign('bottom')

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
content instead.

Ian

Loading...