[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)
This commit is contained in:
Tobias Witek 2020-02-23 21:13:49 +01:00
parent fd57af9325
commit 84833dc7db
5 changed files with 27 additions and 3 deletions

View file

@ -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))

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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