[英]Python Urwid Keystrokes
晚上好大家,
我有一個使用Python Urwid庫構建的應用程序。 它具有多個字段,因此使用“ Page Down”或“ Down”鍵進入應用程序底部需要花費大量時間。 我只是想知道是否有任何直接將光標移到底部的擊鍵操作。 類似於以下內容:
class SimulationView(urwid.WidgetWrap): (line 6)
{
def get_main_frame(self): (line 127)
buttons_box = urwid.ListBox(buttons_walker) (line 148)
errors_box = urwid.ListBox(self.errors_content) (line 155)
sim_listbox = urwid.ListBox(self.sim_list_content)(line 158)
body = urwid.Pile([(6, buttons_box),('weight', 4, sim_listbox),
('weight', 1, errors_box)])
frame = urwid.Frame(body, header=header)
return frame
def keypress(self, size, key):
If key is "a":
# command to take the cursor to the bottom of the application
}
提前致謝。
對於默認小部件,似乎沒有任何等效的映射,僅是因為每個應用程序可能對“底層”有不同的概念。
您所說的“底部”到底是什么意思? 是否有一個始終需要您關注的小部件?
容器窗口小部件具有可寫的focus_position
屬性,可用於更改焦點,這里是一個示例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, division
import urwid
def global_input(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
elif key == 'page down':
# "bottom" is last button, which is before footer
pile.focus_position = len(pile.contents) - 2
elif key == 'page up':
# "top" is the first button, which is after footer
pile.focus_position = 1
elif key in ('1', '2', '3', '4'):
pile.focus_position = int(key)
if __name__ == '__main__':
footer = urwid.Text('Footer')
pile = urwid.Pile([
urwid.Padding(urwid.Text('Header'), 'center', width=('relative', 6)),
urwid.Button('Button 1'),
urwid.Button('Button 2'),
urwid.Button('Button 3'),
urwid.Button('Button 4'),
urwid.Padding(footer, 'center', width=('relative', 20)),
])
widget = urwid.Filler(pile, 'top')
loop = urwid.MainLoop(widget, unhandled_input=global_input)
loop.run()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.