[theme] Fix cycling through widget styles

Cycled widget styles (such as the battery charging style) were broken
until now. The reason for this: They maintain state that represents the
current cycle position (i.e. what is the current icon that is being
displayed), but that is done in a way that uses repr() on the widget
object.

Since the widget objects are re-created each time the bar is drawn, this
is a deeply flawed design.

Instead, use the instance() of the widget for now.
This commit is contained in:
Tobi-wan Kenobi 2016-12-02 22:35:28 +01:00
parent 31067159d6
commit 20858991b9
2 changed files with 6 additions and 3 deletions

View file

@ -78,6 +78,10 @@ class Config(object):
return self._store.get(name, default)
def increase(self, name, limit, default):
if not name in self._store:
self._store[name] = default
return default
self._store[name] += 1
if self._store[name] >= limit:
self._store[name] = default

View file

@ -120,9 +120,8 @@ class Theme:
value = instance_state_theme.get(name, value)
if type(value) is list:
key = "{}{}".format(repr(widget), value)
idx = self._config.parameter(key, 0)
self._config.increase(key, len(value), 0)
key = "{}{}".format(widget.instance(), value)
idx = self._config.increase(key, len(value), 0)
value = value[idx]
return value if value else default