当前位置: 首页>>代码示例>>Python>>正文


Python Pile.keypress方法代码示例

本文整理汇总了Python中urwid.Pile.keypress方法的典型用法代码示例。如果您正苦于以下问题:Python Pile.keypress方法的具体用法?Python Pile.keypress怎么用?Python Pile.keypress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urwid.Pile的用法示例。


在下文中一共展示了Pile.keypress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TreePile

# 需要导入模块: from urwid import Pile [as 别名]
# 或者: from urwid.Pile import keypress [as 别名]
class TreePile(WidgetWrap):
    _selectable = True

    def __init__(self, walker, **kwargs):
        if not isinstance(walker, TreeListWalker):
            walker = TreeListWalker(walker)
        self._walker = walker
        self._lines = []
        self.loadlines()
        logging.debug('lines:\n\n%s' % str(self._lines))
        self._pile = Pile(self._lines)
        self.__super.__init__(self._pile)

    def loadlines(self):
        widget, pos = self._walker.get_focus()
        while pos is not None:
            self._lines.append(widget)
            widget, pos = self._walker.get_next(pos)

    # Widget API
    def get_focus(self):
        return self._pile.get_focus()

    def keypress(self, size, key):
        key = self._pile.keypress(size, key)
        if key in ['left', 'right', '[', ']', '-', '+', 'C', 'E']:
            if key == 'left':
                self.focus_parent()
            elif key == 'right':
                self.focus_first_child()
            elif key == '[':
                self.focus_prev_sibling()
            elif key == ']':
                self.focus_next_sibling()
            if isinstance(self._walker, CollapseMixin):
                if key == '-':
                    w, focuspos = self._walker.get_focus()
                    self._walker.collapse(focuspos)
                elif key == '+':
                    w, focuspos = self._walker.get_focus()
                    self._walker.expand(focuspos)
                elif key == 'C':
                    self._walker.collapse_all()
                elif key == 'E':
                    self._walker.expand_all()
            # This is a hack around ListBox misbehaving:
            # it seems impossible to set the focus without calling keypress as
            # otherwise the change becomes visible only after the next render()
            return self._pile.keypress(size, None)
        else:
            return self._pile.keypress(size, key)

    # Tree based focus movement
    def focus_parent(self):
        w, focuspos = self._walker.get_focus()
        parent = self._walker.parent_position(focuspos)
        if parent is not None:
            self._pile.set_focus(parent)

    def focus_first_child(self):
        w, focuspos = self._walker.get_focus()
        child = self._walker.first_child_position(focuspos)
        if child is not None:
            self._outer_list.set_focus(child)

    def focus_next_sibling(self):
        w, focuspos = self._walker.get_focus()
        sib = self._walker.next_sibling_position(focuspos)
        if sib is not None:
            self._outer_list.set_focus(sib)

    def focus_prev_sibling(self):
        w, focuspos = self._walker.get_focus()
        sib = self._walker.prev_sibling_position(focuspos)
        if sib is not None:
            self._outer_list.set_focus(sib)
开发者ID:pazz,项目名称:urwidtrees-V1,代码行数:78,代码来源:sandbox.treepile.py


注:本文中的urwid.Pile.keypress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。