Urwid ListBox:如何获得流畅的焦点移动?
我有以下代码片段,显示数字列表,并突出显示当前焦点项目:
import urwid
palette = [('header', 'white', 'black'),
('reveal focus', 'black', 'dark cyan', 'standout'),]
items = map(lambda x: urwid.Text(`x`), range(500))
items = map(lambda x: urwid.AttrMap(x, None, 'reveal focus'), items)
walker = urwid.SimpleListWalker(items)
listbox = urwid.ListBox(walker)
loop = urwid.MainLoop(listbox, palette)
loop.run()
当我启动程序时,终端看起来像:
0 <-- highlighted
1
2
3
...
如果我按 down
按钮,则视图将更改为:
1
2
3
4 <-- highlighted
...
我想要一种在屏幕向下滚动之前突出显示并聚焦 0-3
的行为。实现这一目标的最佳方法是什么?
I have the following code snippet that shows a list of numbers, and highlights the currently in-focus item:
import urwid
palette = [('header', 'white', 'black'),
('reveal focus', 'black', 'dark cyan', 'standout'),]
items = map(lambda x: urwid.Text(`x`), range(500))
items = map(lambda x: urwid.AttrMap(x, None, 'reveal focus'), items)
walker = urwid.SimpleListWalker(items)
listbox = urwid.ListBox(walker)
loop = urwid.MainLoop(listbox, palette)
loop.run()
When I start the program the terminal looks like:
0 <-- highlighted
1
2
3
...
If I press the down
button then the view changes to:
1
2
3
4 <-- highlighted
...
I would like a behavior in which 0-3
are highlighted and in-focus before the screen scrolls downward. What is the best way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
接受的解决方案在第一次按键时失败:
注入我自己的实现,该实现不执行任何操作会使错误消失,但它也完全破坏了所有按键绑定。
我发现了这个,它似乎工作得很好:
The accepted solution fails on first key press:
Injecting my own implementation that does nothing makes the error go away, but it also completely borks all keybindings.
I found this and it seems to work just fine:
列表框中的项目必须是可选择的。这是一种方法:
The items in the list box need to be selectable. Here is one approach: