[themes] Add "cycle" theme capability
It is now possible to add a list of theme configurations in the "default" section called "cycle". These configuration items will be cycled through module by module. to create "alternate style" effects. This is *only* possible in the "default" configuration part, but any module-specific configurations still take precedence. Also, removed the capability of per-widget themes. That simply complicates things and probably doesn't really bring any benefits.
This commit is contained in:
parent
656c499c95
commit
2a35905b89
8 changed files with 57 additions and 19 deletions
|
@ -1,13 +1,20 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
|
||||
|
||||
class Theme:
|
||||
_cycle_index = 0
|
||||
_cycle = None
|
||||
def __init__(self, name="default"):
|
||||
self._data = None
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
with open("{}/themes/{}.json".format(path, name)) as f:
|
||||
self._data = json.load(f)
|
||||
self._defaults = self._data.get("defaults", {})
|
||||
self._cycle = self._defaults.get("cycle", [])
|
||||
|
||||
self.reset()
|
||||
|
||||
def _gettheme(self, obj, key):
|
||||
module = obj.__module__.split(".")[-1]
|
||||
|
@ -17,6 +24,9 @@ class Theme:
|
|||
value = self._defaults.get(key, value)
|
||||
value = module_theme.get(key, value)
|
||||
|
||||
if len(self._cycle) > 0:
|
||||
value = self._defaults["cycle"][self._cycle_index].get(key, value)
|
||||
|
||||
if hasattr(obj, "state"):
|
||||
state = getattr(obj, "state")()
|
||||
state_theme = module_theme.get("states", {}).get(state, {})
|
||||
|
@ -25,11 +35,26 @@ class Theme:
|
|||
|
||||
return value
|
||||
|
||||
def reset(self):
|
||||
self._cycle_index = 0
|
||||
self._previous_background = None
|
||||
self._background = None
|
||||
|
||||
def next(self):
|
||||
self._cycle_index += 1
|
||||
self._previous_background = self._background
|
||||
if self._cycle_index >= len(self._cycle):
|
||||
self._cycle_index = 0
|
||||
|
||||
def color(self, obj):
|
||||
return self._gettheme(obj, "fg")
|
||||
|
||||
def background(self, obj):
|
||||
return self._gettheme(obj, "bg")
|
||||
self._background = self._gettheme(obj, "bg")
|
||||
return self._background
|
||||
|
||||
def previous_background(self):
|
||||
return self._previous_background
|
||||
|
||||
def separator(self, obj):
|
||||
return self._gettheme(obj, "separator")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue