[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

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