From 6c2fed9d40bcbca5cefe2577a038f0f6650f1205 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 8 Nov 2018 10:45:27 +0100 Subject: [PATCH] ui: stylize scrollbar --- pqcli/ui/__init__.py | 4 ++++ pqcli/ui/scrollable.py | 35 +++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pqcli/ui/__init__.py b/pqcli/ui/__init__.py index 69b1615..53181fe 100644 --- a/pqcli/ui/__init__.py +++ b/pqcli/ui/__init__.py @@ -27,6 +27,10 @@ PALETTE: T.List[T.Tuple[str, ...]] = [ ("progressbar-normal", "", "", "standout"), ("progressbar-done", "black", "light red"), ("progressbar-smooth", "light red", ""), + ("scrollbar", "dark gray", ""), + ("scrollbar-focus", "light red", ""), + ("scrollable", "", ""), + ("scrollable-focus", "", ""), ] PALETTE_PATH = Path(xdg.XDG_CONFIG_HOME) / "pqcli" / "palette.json" diff --git a/pqcli/ui/scrollable.py b/pqcli/ui/scrollable.py index 91145cf..1ffc912 100644 --- a/pqcli/ui/scrollable.py +++ b/pqcli/ui/scrollable.py @@ -12,6 +12,7 @@ # Taken from stig (stig.tui.scroll). # Changes compared to upstream: # - reformatted the code +# - added AttrMap wrapping import urwid from urwid.widget import BOX, FLOW, FIXED @@ -29,7 +30,7 @@ SCROLLBAR_LEFT = "left" SCROLLBAR_RIGHT = "right" -class Scrollable(urwid.WidgetDecoration): +class _Scrollable(urwid.WidgetDecoration): def sizing(self): return frozenset([BOX]) @@ -54,7 +55,7 @@ class Scrollable(urwid.WidgetDecoration): self._forward_keypress = None self._old_cursor_coords = None self._rows_max_cached = 0 - self.__super.__init__(widget) + super().__init__(widget) def render(self, size, focus=False): maxcol, maxrow = size @@ -278,13 +279,7 @@ class Scrollable(urwid.WidgetDecoration): return self._rows_max_cached -class ScrollBar(urwid.WidgetDecoration): - def sizing(self): - return frozenset((BOX,)) - - def selectable(self): - return True - +class _ScrollBar(urwid.WidgetDecoration): def __init__( self, widget, @@ -310,13 +305,19 @@ class ScrollBar(urwid.WidgetDecoration): """ if BOX not in widget.sizing(): raise ValueError("Not a box widget: %r" % widget) - self.__super.__init__(widget) + super().__init__(widget) self._thumb_char = thumb_char self._trough_char = trough_char self.scrollbar_side = side self.scrollbar_width = max(1, width) self._original_widget_size = (0, 0) + def sizing(self): + return frozenset((BOX,)) + + def selectable(self): + return True + def render(self, size, focus=False): maxcol, maxrow = size @@ -430,3 +431,17 @@ class ScrollBar(urwid.WidgetDecoration): return True return False + + +class Scrollable(urwid.AttrWrap): + def __init__(self, *args, **kwargs): + super().__init__( + _Scrollable(*args, **kwargs), "scrollable", "scrollable-focus" + ) + + +class ScrollBar(urwid.AttrWrap): + def __init__(self, *args, **kwargs): + super().__init__( + _ScrollBar(*args, **kwargs), "scrollbar", "scrollbar-focus" + )