From 998db40a2da30eb7fa110c74b2ede07ff4bc144d Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 5 Nov 2016 11:57:09 +0100 Subject: [PATCH] [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. --- bumblebee/config.py | 15 +++++++++++++++ bumblebee/theme.py | 16 ++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/bumblebee/config.py b/bumblebee/config.py index a494566..ef7a4c7 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -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 diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 0568260..90aeba4 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -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