Add basic cursor tree widget
This commit is contained in:
parent
ba2f64762f
commit
a4d33847e9
3 changed files with 85 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ from .attributed_lines import *
|
|||
from .attributed_lines_widget import *
|
||||
from .attributed_text_widget import *
|
||||
from .cursor_rendering import *
|
||||
from .cursor_tree_widget import *
|
||||
from .element import *
|
||||
from .element_supply import *
|
||||
from .markup import *
|
||||
|
|
@ -15,6 +16,7 @@ __all__ += attributed_lines.__all__
|
|||
__all__ += attributed_lines_widget.__all__
|
||||
__all__ += attributed_text_widget.__all__
|
||||
__all__ += cursor_rendering.__all__
|
||||
__all__ += cursor_tree_widget.__all__
|
||||
__all__ += element.__all__
|
||||
__all__ += element_supply.__all__
|
||||
__all__ += markup.__all__
|
||||
|
|
|
|||
48
cheuph/cursor_tree_widget.py
Normal file
48
cheuph/cursor_tree_widget.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import datetime
|
||||
import time
|
||||
from typing import Tuple, TypeVar
|
||||
|
||||
import urwid
|
||||
|
||||
from .attributed_lines_widget import AttributedLinesWidget
|
||||
from .cursor_rendering import CursorTreeRenderer
|
||||
from .element import Element, Message
|
||||
|
||||
__all__ = ["CursorTreeWidget"]
|
||||
|
||||
E = TypeVar("E", bound=Element)
|
||||
|
||||
class CursorTreeWidget(urwid.WidgetWrap):
|
||||
"""
|
||||
This widget draws a CursorTree and moves the cursor around.
|
||||
"""
|
||||
|
||||
def __init__(self, tree: CursorTreeRenderer[E]) -> None:
|
||||
self._tree = tree
|
||||
self._lines_widget = AttributedLinesWidget()
|
||||
super().__init__(self._lines_widget)
|
||||
|
||||
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)
|
||||
|
||||
return super().render(size, focus)
|
||||
|
||||
def selectable(self):
|
||||
return True
|
||||
|
||||
def keypress(self, size: Tuple[int, int], key: str):
|
||||
if key == "shift up":
|
||||
self._tree.scroll(-1)
|
||||
elif key == "shift down":
|
||||
self._tree.scroll(1)
|
||||
elif key == "shift right":
|
||||
self._tree.scroll_horizontally(1)
|
||||
elif key == "shift left":
|
||||
self._tree.scroll_horizontally(-1)
|
||||
else:
|
||||
t = datetime.datetime(2019,5,7,13,25,6)
|
||||
self._tree._supply.add(Message(str(time.time()), None, t, "key", key))
|
||||
self._invalidate()
|
||||
Loading…
Add table
Add a link
Reference in a new issue