From 84833dc7db95a099ca4460dd2147e01fb66d62a0 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 23 Feb 2020 21:13:49 +0100 Subject: [PATCH] [core] Add (partial) support for states Add states to the modules and widgets. Widgets are mostly just a pass-through (backwards compatibility, and ease of use - making states directly inside the widgets would require more code inside the modules to ensure that each widget is correctly updated). Still missing: - Separators during partial update (right now, it takes one interval until separators are drawn correctly) --- core/module.py | 5 +++++ core/output.py | 2 ++ core/theme.py | 9 ++++++++- core/widget.py | 10 ++++++++++ doc/NOTES.md | 4 ++-- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/module.py b/core/module.py index 8f159d6..46fd964 100644 --- a/core/module.py +++ b/core/module.py @@ -20,6 +20,8 @@ class Module(core.input.Object): super().__init__() self._config = config self._widgets = widgets if isinstance(widgets, list) else [ widgets ] + for widget in self._widgets: + widget.module(self) self._name = None def parameter(self, key, default=None): @@ -45,6 +47,9 @@ class Module(core.input.Object): def widgets(self): return self._widgets + def state(self, widget): + return [] + class Error(Module): def __init__(self, config, module, error): super().__init__(config, core.widget.Widget(self.full_text)) diff --git a/core/output.py b/core/output.py index 5c7f90c..20fae68 100644 --- a/core/output.py +++ b/core/output.py @@ -78,6 +78,8 @@ class i3(object): def update(self, affected_modules=None): for module in self._modules: + if affected_modules and not module.id() in affected_modules: + continue module.update() self._status[module] = self.widgets(module) diff --git a/core/theme.py b/core/theme.py index 6ceec32..a1d8a40 100644 --- a/core/theme.py +++ b/core/theme.py @@ -61,7 +61,9 @@ class Theme(object): self.__current.clear() def __get(self, widget, key, default=None): - if widget and isinstance(widget, str): + if not widget: + widget = core.widget.Widget('') + if isinstance(widget, str): # special handling if widget == 'previous': return self.__previous.get(key, None) @@ -75,6 +77,11 @@ class Theme(object): tmp = tmp[self.__widget_count % len(tmp)] value = tmp.get(key, value) + if not key in widget.state(): + for state in widget.state(): + theme = self.__get(widget, state, {}) + value = theme.get(key, value) + self.__current[key] = value return value diff --git a/core/widget.py b/core/widget.py index cd1d8bf..ab61d5c 100644 --- a/core/widget.py +++ b/core/widget.py @@ -5,6 +5,7 @@ class Widget(util.store.Store, core.input.Object): def __init__(self, full_text): super(Widget, self).__init__() self._full_text = full_text + self._module = None def full_text(self, value=None): if value: @@ -14,4 +15,13 @@ class Widget(util.store.Store, core.input.Object): return self._full_text(self) return self._full_text + def module(self, module): + self._module = module + + def state(self): + rv = [] + if self._module: + rv = self._module.state(self) + return rv if isinstance(rv, list) else [rv] + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/doc/NOTES.md b/doc/NOTES.md index 2bebd2e..6ff81f6 100644 --- a/doc/NOTES.md +++ b/doc/NOTES.md @@ -14,10 +14,10 @@ ## Backwards-compatibility - aliases -- charts (hbar, vbar, braille) +- charts (braille) - minimize modules - hide modules if not in warning/error state (-a) -- WAL support +- WAL support / colorscheme support - tkinter / popups - scrolling decorator (incl. minwidth, alignment) - states