[theme] Re-implement rotation of values for theme entries

Allow theme entries to be lists that are then iterated. For this
purpose, extend the Config class so that it can serve as generic store
for data items. That makes it easy to centralize code used for rotation
etc. in a single place.
This commit is contained in:
Tobias Witek 2016-11-05 11:57:09 +01:00
parent 98acd15edf
commit 998db40a2d
2 changed files with 23 additions and 8 deletions

View file

@ -10,6 +10,7 @@ class Config(object):
self._raw = args
self._parser = self._parser()
self._indent = " "*4
self._store = {}
if len(args) == 0:
self._parser.print_help()
@ -24,6 +25,20 @@ class Config(object):
if self._args.list:
self._parser.exit()
def getstore(self, name, default=None):
if not name in self._store:
self._store[name] = default
return self._store.get(name, default)
def store(self, name, value):
self._store[name] = value
def increase(self, name, limit, default):
self._store[name] += 1
if self._store[name] >= limit:
self._store[name] = default
return self._store[name]
def parameter(self, name, default):
# TODO
return default

View file

@ -11,6 +11,7 @@ def themes():
class Theme:
def __init__(self, config):
self._config = config
with open("{}/{}.json".format(getpath(), config.theme())) as f:
self._data = json.load(f)
self._defaults = self._data.get("defaults", {})
@ -18,16 +19,14 @@ class Theme:
self.begin()
def begin(self):
self._cycleidx = 0
self._config.store("theme.cycleidx", 0)
self._cycle = self._cycles[0] if len(self._cycles) > 0 else {}
self._background = [ None, None ]
def next_widget(self):
self._background[1] = self._background[0]
self._cycleidx += 1
if self._cycleidx >= len(self._cycles):
self._cycleidx = 0
self._cycle = self._cycles[self._cycleidx] if len(self._cycles) > self._cycleidx else {}
idx = self._config.increase("theme.cycleidx", len(self._cycles), 0)
self._cycle = self._cycles[idx] if len(self._cycles) > idx else {}
def prefix(self, widget):
return self._get(widget, "prefix")
@ -80,9 +79,10 @@ class Theme:
value = state_theme.get(name, value)
if type(value) is list:
# if the value is a list, cycle through it
# TODO
pass
key = "{}{}".format(repr(widget), value)
idx = self._config.getstore(key, 0)
self._config.increase(key, len(value), 0)
value = value[idx]
return value