diff --git a/bumblebee/module.py b/bumblebee/module.py index 823c830..8f005f6 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -1,6 +1,6 @@ class Module(object): - def __init__(self, theme): + def __init__(self, theme, args): self._theme = theme def theme(self): diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py new file mode 100644 index 0000000..e5be816 --- /dev/null +++ b/bumblebee/modules/battery.py @@ -0,0 +1,19 @@ +import datetime +import bumblebee.module + +class Module(bumblebee.module.Module): + def __init__(self, theme, args): + super(Module, self).__init__(theme, args) + self._battery = "BAT0" if not args else args[0] + self._capacity = 0 + self._status = "Unknown" + + 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 + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/modules/time.py b/bumblebee/modules/time.py index 4b6a1db..2259823 100644 --- a/bumblebee/modules/time.py +++ b/bumblebee/modules/time.py @@ -2,8 +2,8 @@ import datetime import bumblebee.module class Module(bumblebee.module.Module): - def __init__(self, theme): - super(Module, self).__init__(theme) + def __init__(self, theme, args): + super(Module, self).__init__(theme, args) def data(self): return datetime.datetime.now().strftime("%x %X") diff --git a/i3bumblebee b/i3bumblebee index 5ddcbbd..8b4602a 100755 --- a/i3bumblebee +++ b/i3bumblebee @@ -28,8 +28,10 @@ def main(): for m in args.modules: # TODO: how to cleanly handle errors here? # (useful error messages) - module = importlib.import_module("bumblebee.modules.%s" % m) - modules.append(getattr(module, "Module")(theme)) + module_name = m if not ":" in m else m.split(":")[0] + module_args = None if not ":" in m else m.split(":")[1:] + module = importlib.import_module("bumblebee.modules.%s" % module_name) + modules.append(getattr(module, "Module")(theme, module_args)) output = bumblebee.outputs.i3.i3bar()