diff --git a/test_scripts/.gitignore b/test_scripts/.gitignore new file mode 100644 index 0000000..b1687c3 --- /dev/null +++ b/test_scripts/.gitignore @@ -0,0 +1,2 @@ +cheuph +yaboli diff --git a/test_scripts/display_attr_lines_wiget.py b/test_scripts/display_attr_lines_wiget.py new file mode 100644 index 0000000..885145b --- /dev/null +++ b/test_scripts/display_attr_lines_wiget.py @@ -0,0 +1,38 @@ +import urwid +import urwid.curses_display + +import cheuph +from cheuph import AT, AttributedLines, AttributedLinesWidget + + +class TestWidget(urwid.WidgetWrap): + def __init__(self): + lines = [ + ({}, AT("a")), + ({}, AT("Hello world")), + ({}, AT("super long line " * 20)), + ] + self.lines = AttributedLinesWidget(AttributedLines(lines)) + super().__init__(self.lines) + + def selectable(self): + return True + + def keypress(self, size, key): + if key == "left": + self.lines.horizontal_offset -= 1 + elif key == "right": + self.lines.horizontal_offset += 1 + elif key == "home": + self.lines.horizontal_offset = 0 + elif key == "up": + self.lines.upper_offset += 1 + elif key == "down": + self.lines.upper_offset -= 1 + +def main(): + screen = urwid.curses_display.Screen() + loop = urwid.MainLoop(TestWidget(), screen=screen) + loop.run() + +main() diff --git a/test_scripts/display_attr_text_widget.py b/test_scripts/display_attr_text_widget.py new file mode 100644 index 0000000..0357dab --- /dev/null +++ b/test_scripts/display_attr_text_widget.py @@ -0,0 +1,20 @@ +import urwid +import urwid.curses_display + +import cheuph +from cheuph import AT, AttributedTextWidget + + +class TestWidget(urwid.WidgetWrap): + def __init__(self): + text = AT("Hello world!\nThis is some text.\nThird line.") + self.text = AttributedTextWidget(text) + self.filler = urwid.Filler(self.text) + super().__init__(self.filler) + +def main(): + screen = urwid.curses_display.Screen() + loop = urwid.MainLoop(TestWidget(), screen=screen) + loop.run() + +main() diff --git a/test_scripts/display_pressed_keys.py b/test_scripts/display_pressed_keys.py new file mode 100644 index 0000000..2bab122 --- /dev/null +++ b/test_scripts/display_pressed_keys.py @@ -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()