如何指示一个urwid列表框当前所显示的项目多于当前显示的项目? [英] How to indicate that a urwid listbox has more items than displayed at the moment?

查看:108
本文介绍了如何指示一个urwid列表框当前所显示的项目多于当前显示的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以向用户显示urwid列表框在已分发部分的上方/下方有其他项目?

Is there a way to show a user that a urwid listbox has additional items above / below the dispalyed section?

我正在考虑类似滚动条的概念,它可以让您大致了解条目数.

I'm thinking of something like a scrollbar that gives an idea of the number of entries.

或列表框顶部/底部的单独栏.

Or a separate bar at the top / bottom of the list box.

如果无法实现此行为,有什么方法可以实现此通知?

If this behavior can not be implemented, what approaches are there to achieve this notification?

在研究过程中,我发现

During my research, I found this question, which tried to achieve eventually the same. The given answer seems to check if all elements are visible. Unfortunately, this loses its functionality if some elements are hidden at any time because the terminal is not resized.

推荐答案

我实现了一个列表框,该列表框默认情况下应用了第二个可视化概念(顶部和底部的条形图).

I've implemented a list box that applies the second visualization concept (bars at the top and bottom) by default.

它称为 additional_urwid_widgets.IndicativeListBox ,并且可以通过<一个href ="https://pypi.org/project/additional-urwid-widgets/" rel ="nofollow noreferrer"> pip .

It is called additional_urwid_widgets.IndicativeListBox and can be installed via pip.


有关说明小部件功能的独立示例,请参见此处.


For a stand alone example, which illustrates the functionality of the widget, see here.

有关更多(更简单)的示例,请参见此处.

For more (and simpler) examples, see here.

有关参数和选项的更多详细说明,请参见相应的github Wiki条目.

For a more detailed explanation of the parameters and options, see the corresponding github wiki entry.


#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from additional_urwid_widgets import IndicativeListBox    # installed via pip
import urwid                                              # installed via pip

# Color schemes that specify the appearance off focus and on focus.
PALETTE = [("reveal_focus", "black", "light cyan", "standout")]

# The list box is filled with buttons.
body = [urwid.Button(letter) for letter in "abcdefghijklmnopqrstuvwxyz"]

# Wrap the list items into an 'urwid.AttrMap', so that they have an other appearance when focused.
# Instead of an simple list-like object you can/should create a 'urwid.ListWalker'.
attr_body = [urwid.AttrMap(entry, None, "reveal_focus") for entry in body]

ilb = IndicativeListBox(attr_body)

loop = urwid.MainLoop(ilb,
                      PALETTE)
loop.run()


#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from additional_urwid_widgets import IndicativeListBox    # installed via pip
import urwid                                              # installed via pip

# Color schemes that specify the appearance off focus and on focus.
PALETTE = [("reveal_focus", "black", "light cyan", "standout")]

# The list box is filled with buttons.
body = [urwid.Button(letter) for letter in "abcdefghijklmnopqrstuvwxyz"]

# Wrap the list items into an 'urwid.AttrMap', so that they have an other appearance when focused.
# Instead of an simple list-like object you can/should create a 'urwid.ListWalker'.
attr_body = [urwid.AttrMap(entry, None, "reveal_focus") for entry in body]

ilb = IndicativeListBox(attr_body,
                        topBar_endCovered_prop=("{} above ...", None, None),
                        bottomBar_endCovered_prop=("{} below ...", None, None))

loop = urwid.MainLoop(ilb,
                      PALETTE)
loop.run()


在此示例中,必须另外按下 ctrl ,以便列表框响应输入.
这允许在垂直容器(例如 urwid.Pile )中使用窗口小部件.

In this example, ctrl must be additionally pressed so that the list box responds to the input.
This allows the widget to be used in vertical containers (such as urwid.Pile).

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from additional_urwid_widgets import IndicativeListBox, MODIFIER_KEY    # installed via pip
import urwid                                                            # installed via pip

# Color schemes that specify the appearance off focus and on focus.
PALETTE = [("reveal_focus",              "black",            "light cyan",   "standout"),
           ("ilb_barActive_focus",       "dark cyan",        "light gray"),
           ("ilb_barActive_offFocus",    "light gray",       "dark gray"),
           ("ilb_barInactive_focus",     "light cyan",       "dark gray"),
           ("ilb_barInactive_offFocus",  "black",            "dark gray"),
           ("ilb_highlight_offFocus",    "black",            "dark cyan")]

# The list box is filled with buttons.
body = [urwid.Button(letter) for letter in "abcdefghijklmnopqrstuvwxyz"]

# Wrap the list items into an 'urwid.AttrMap', so that they have an other appearance when focused.
# Instead of an simple list-like object you can/should create a 'urwid.ListWalker'.
attr_body = [urwid.AttrMap(entry, None, "reveal_focus") for entry in body]

ilb = ilb = IndicativeListBox(attr_body,
                              modifier_key=MODIFIER_KEY.CTRL,
                              return_unused_navigation_input=False,
                              topBar_endCovered_prop=("ᐃ", "ilb_barActive_focus", "ilb_barActive_offFocus"),
                              topBar_endExposed_prop=("───", "ilb_barInactive_focus", "ilb_barInactive_offFocus"), 
                              bottomBar_endCovered_prop=("ᐁ", "ilb_barActive_focus", "ilb_barActive_offFocus"), 
                              bottomBar_endExposed_prop=("───", "ilb_barInactive_focus", "ilb_barInactive_offFocus"),
                              highlight_offFocus="ilb_highlight_offFocus")

pile = urwid.Pile([urwid.Text("The listbox responds only if 'ctrl' is pressed."),
                   urwid.Divider(" "),
                   urwid.Button("a button"),
                   urwid.BoxAdapter(ilb, 6),         # Wrap flow widget in box adapter
                   urwid.Button("another button")])


loop = urwid.MainLoop(urwid.Filler(pile, "top"),
                      PALETTE)
loop.run()

这篇关于如何指示一个urwid列表框当前所显示的项目多于当前显示的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆