[themes] Add cycling for individual elements

Add functionality to provide lists of values for individual elements of
a theme (e.g. the prefix) and those will be cycled for each call.

This can be used, for example, to show a "charging" symbol for the
battery that continuously goes throw all the battery stages to "animate"
the charging icon.
This commit is contained in:
Tobias Witek 2016-10-31 11:46:07 +01:00
parent 14bce293eb
commit 83bb1deb52
2 changed files with 13 additions and 0 deletions

View file

@ -28,5 +28,7 @@ class Module(bumblebee.module.Module):
return "discharging_high"
return "discharging_full"
else:
if self._capacity > 95:
return "charged"
return "charging"
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -11,6 +11,7 @@ class Theme:
self._data = json.load(f)
self._defaults = self._data.get("defaults", {})
self._cycle = self._defaults.get("cycle", [])
self._modules = {}
self.reset()
@ -30,6 +31,16 @@ class Theme:
value = state_theme.get(key, value)
if type(value) is list:
# cycle through the values
if not obj in self._modules:
self._modules[obj] = { "idx": 0 }
else:
self._modules[obj]["idx"] += 1
if self._modules[obj]["idx"] >= len(value):
self._modules[obj]["idx"] = 0
value = value[self._modules[obj]["idx"]]
return value
def reset(self):