From ba2f64762f80c6a945195b7f1a0e7ecc3fab386c Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 7 Jun 2019 04:49:45 +0000 Subject: [PATCH] Clean up and re-add attributed text widgets --- cheuph/__init__.py | 4 ++++ cheuph/attributed_lines_widget.py | 26 +++++++------------------- cheuph/attributed_text_widget.py | 1 - 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/cheuph/__init__.py b/cheuph/__init__.py index 130f0bc..130edd9 100644 --- a/cheuph/__init__.py +++ b/cheuph/__init__.py @@ -1,6 +1,8 @@ from typing import List from .attributed_lines import * +from .attributed_lines_widget import * +from .attributed_text_widget import * from .cursor_rendering import * from .element import * from .element_supply import * @@ -10,6 +12,8 @@ from .rendered_element_cache import * __all__: List[str] = [] __all__ += attributed_lines.__all__ +__all__ += attributed_lines_widget.__all__ +__all__ += attributed_text_widget.__all__ __all__ += cursor_rendering.__all__ __all__ += element.__all__ __all__ += element_supply.__all__ diff --git a/cheuph/attributed_lines_widget.py b/cheuph/attributed_lines_widget.py index 9b65737..0c3e2fb 100644 --- a/cheuph/attributed_lines_widget.py +++ b/cheuph/attributed_lines_widget.py @@ -1,40 +1,28 @@ # TODO send event on mouse click -from typing import Any, Optional, Tuple +from typing import Optional, Tuple import urwid from .attributed_lines import AttributedLines from .attributed_text_widget import AttributedTextWidget -from .markup import AT, AttributedText, Attributes +from .markup import AT __all__ = ["AttributedLinesWidget"] - class AttributedLinesWidget(urwid.WidgetWrap): """ - This widget draws lines of AttributedText with a horizontal and a vertical - offset. It can retrieve the attributes of any character by its (x, y) - coordinates. Line-wide attributes may be specified. - - When clicked, it sends an event containing the attributes of the character - that was just clicked. - - Uses the following config values: - - "filler_symbol" - - "overflow_symbol" + This widget draws an AttributedLines with a horizontal and a vertical + offset. """ - def __init__(self, - lines: Optional[AttributedLines] = None, - ) -> None: - - self._horizontal_offset = 0 - + def __init__(self, lines: Optional[AttributedLines] = None) -> None: self._text = AttributedTextWidget(AT()) self._filler = urwid.Filler(self._text, valign=urwid.TOP) super().__init__(self._filler) + self._horizontal_offset = 0 + self.set_lines(lines or AttributedLines()) @property diff --git a/cheuph/attributed_text_widget.py b/cheuph/attributed_text_widget.py index 10308c5..9261209 100644 --- a/cheuph/attributed_text_widget.py +++ b/cheuph/attributed_text_widget.py @@ -6,7 +6,6 @@ from .markup import AttributedText __all__ = ["AttributedTextWidget", "ATWidget"] - class AttributedTextWidget(urwid.Text): """ A widget that works like urwid.Text, but displays AttributedText.