我想实现一些提示,urwid.ListBox
当我向上或向下滚动时,在可见项目列表的下方或上方是否仍有项目。'向下滚动' 提示应该只在最后一个可见项目之后有剩余项目时出现,并且当最后一个可见项目是列表中的最后一个项目时它应该消失。反向适用于“向上滚动”提示。
然后我需要知道列表中有多少可见项目。有没有办法检索列表框中可见项目的数量,我想它等于列表框的高度,对吧?
这是我要检查的起点:
# This example is based on https://cmsdk.com/python/is-there-a-focus-changed-event-in-urwid.html
import urwid
def callback():
index = str(listbox.get_focus()[1])
debug.set_text("Index of selected item: " + index)
captions = "A B C D E F".split()
debug = urwid.Text("Debug")
items = [urwid.Button(caption) for caption in captions]
walker = urwid.SimpleListWalker(items)
listbox = urwid.ListBox(walker)
urwid.connect_signal(walker, "modified", callback)
frame = urwid.Frame(body=listbox, header=debug)
urwid.MainLoop(frame).run()
这个想法是要知道当终端窗口缩小或不够高以显示所有内容时,列表框是否在框架内完全可见,即frame.height >= listbox.height
.