From 97273b5a412000118a8cfaf3de0011e63024d1f7 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 31 Oct 2016 07:34:43 +0100 Subject: [PATCH] [themes] Add state-dependent themeing Module themes (only!) can now contain state-specific theme information - for example, the "battery" module has different states for charging and discharging, and those can have different prefix and postfix configurations to indicate what is going on. --- bumblebee/modules/battery.py | 9 +++++++-- bumblebee/theme.py | 6 ++++++ bumblebee/themes/default.json | 10 +++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index e5be816..7f5207e 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -11,9 +11,14 @@ class Module(bumblebee.module.Module): def data(self): with open("/sys/class/power_supply/%s/capacity" % self._battery) as f: self._capacity = int(f.read()) - with open("/sys/class/power_supply/%s/status" % self._battery) as f: - self._status = f.read().strip() return "%02d%%" % self._capacity + def state(self): + with open("/sys/class/power_supply/%s/status" % self._battery) as f: + self._status = f.read().strip() + if self._status == "Discharging": + return "discharging" + else: + return "charging" # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 8e095be..91100ba 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -17,6 +17,12 @@ class Theme: value = self._defaults.get(key, value) value = module_theme.get(key, value) + if hasattr(obj, "state"): + state = getattr(obj, "state")() + state_theme = module_theme.get("states", {}).get(state, {}) + + value = state_theme.get(key, value) + return value def prefix(self, obj): diff --git a/bumblebee/themes/default.json b/bumblebee/themes/default.json index d0e5e53..68040de 100644 --- a/bumblebee/themes/default.json +++ b/bumblebee/themes/default.json @@ -4,7 +4,15 @@ "suffix" : " " }, "battery": { - "prefix": "bat " + "prefix": "bat ", + "states": { + "charging": { + "suffix": "+" + }, + "discharging": { + "suffix": "-" + } + } }, "time": { }