Add small interactive test scripts
This commit is contained in:
parent
32bc9af2d8
commit
1803a6676e
4 changed files with 91 additions and 0 deletions
31
test_scripts/display_pressed_keys.py
Normal file
31
test_scripts/display_pressed_keys.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import urwid
|
||||
import urwid.curses_display
|
||||
|
||||
class TestWidget(urwid.WidgetWrap):
|
||||
KEY_LIMIT = 10
|
||||
|
||||
def __init__(self):
|
||||
self.last_keys = []
|
||||
self.text = urwid.Text("No key pressed yet", align=urwid.CENTER)
|
||||
self.filler = urwid.Filler(self.text)
|
||||
super().__init__(self.filler)
|
||||
|
||||
def selectable(self):
|
||||
return True
|
||||
|
||||
def keypress(self, size, key):
|
||||
self.last_keys.append(repr(key))
|
||||
self.last_keys = self.last_keys[-self.KEY_LIMIT:]
|
||||
self.text.set_text("\n".join(self.last_keys))
|
||||
|
||||
def mouse_event(self, size, event, button, col, row, focus):
|
||||
self.last_keys.append(f"{size!r} {event!r} {button!r} ({row}, {col})")
|
||||
self.last_keys = self.last_keys[-self.KEY_LIMIT:]
|
||||
self.text.set_text("\n".join(self.last_keys))
|
||||
|
||||
def main():
|
||||
screen = urwid.curses_display.Screen()
|
||||
loop = urwid.MainLoop(TestWidget(), screen=screen)
|
||||
loop.run()
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue