本文整理汇总了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)