Test interactions for scrolling

This commit is contained in:
Joscha 2019-06-07 08:43:12 +00:00
parent dd6ad51077
commit 05809b0723

View file

@ -1,6 +1,8 @@
# TODO remove testing code and clean up
import datetime
import time
from typing import Tuple, TypeVar
from typing import Optional, Tuple, TypeVar
import urwid
@ -19,30 +21,50 @@ class CursorTreeWidget(urwid.WidgetWrap):
def __init__(self, tree: CursorTreeRenderer[E]) -> None:
self._tree = tree
self._lines_widget = AttributedLinesWidget()
super().__init__(self._lines_widget)
self._lines = AttributedLinesWidget()
super().__init__(self._lines)
self._tree._cursor_id = "->3->2->3"
def render(self, size: Tuple[int, int], focus: bool) -> None:
width, height = size
self._tree.render(width, height)
self._lines_widget.set_lines(self._tree.lines)
self._lines.set_lines(self._tree.lines)
return super().render(size, focus)
def selectable(self):
def selectable(self) -> bool:
return True
def keypress(self, size: Tuple[int, int], key: str):
def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]:
if key == "shift up":
self._tree.scroll(-1)
elif key == "shift down":
self._tree.scroll(1)
self._invalidate()
elif key == "shift down":
self._tree.scroll(-1)
self._invalidate()
elif key == "shift right":
self._tree.scroll_horizontally(1)
self.scroll_horizontally(1)
elif key == "shift left":
self._tree.scroll_horizontally(-1)
self.scroll_horizontally(-1)
elif key in {"home", "shift home"}:
self._lines.horizontal_offset = 0
self._invalidate()
else:
t = datetime.datetime(2019,5,7,13,25,6)
self._tree._supply.add(Message(str(time.time()), None, t, "key", key))
self._tree._supply.add(Message(
str(time.time()),
self._tree._cursor_id,
t,
"key",
key,
))
self._invalidate()
return None
def scroll_horizontally(self, offset: int) -> None:
self._lines.horizontal_offset = max(0,
self._lines.horizontal_offset + offset)
self._invalidate()