diff --git a/bumblebee/module.py b/bumblebee/module.py index 8f005f6..e848ea4 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -6,4 +6,10 @@ class Module(object): def theme(self): return self._theme + def data(self): + pass + + def state(self): + return "default" + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/outputs/i3.py b/bumblebee/outputs/i3.py index b47bb73..a2cc3fb 100644 --- a/bumblebee/outputs/i3.py +++ b/bumblebee/outputs/i3.py @@ -9,8 +9,11 @@ class i3bar(bumblebee.output.Output): return json.dumps({ "version": 1 }) + "[" def add(self, obj): + theme = obj.theme() self._data.append({ - "full_text": obj.data() + "full_text": "%s%s%s" % (theme.prefix(obj), obj.data(), theme.suffix(obj)), + "separator": False, + "separator_block_width": 0, }) def get(self): diff --git a/bumblebee/theme.py b/bumblebee/theme.py new file mode 100644 index 0000000..8e095be --- /dev/null +++ b/bumblebee/theme.py @@ -0,0 +1,28 @@ +import os +import json + +class Theme: + def __init__(self, name="default"): + self._data = None + path = os.path.dirname(os.path.realpath(__file__)) + with open("%s/themes/%s.json" % (path, name)) as f: + self._data = json.load(f) + self._defaults = self._data.get("defaults", {}) + + def _gettheme(self, obj, key): + module = obj.__module__.split(".")[-1] + module_theme = self._data.get(module, {}) + + value = getattr(obj, key)() if hasattr(obj, key) else "" + value = self._defaults.get(key, value) + value = module_theme.get(key, value) + + return value + + def prefix(self, obj): + return self._gettheme(obj, "prefix") + + def suffix(self, obj): + return self._gettheme(obj, "suffix") + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/themes.py b/bumblebee/themes.py deleted file mode 100644 index 3e5f001..0000000 --- a/bumblebee/themes.py +++ /dev/null @@ -1,6 +0,0 @@ - -class Theme: - def __init__(self, name): - pass - -# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/themes/default.json b/bumblebee/themes/default.json new file mode 100644 index 0000000..d0e5e53 --- /dev/null +++ b/bumblebee/themes/default.json @@ -0,0 +1,11 @@ +{ + "defaults": { + "prefix": " ", + "suffix" : " " + }, + "battery": { + "prefix": "bat " + }, + "time": { + } +} diff --git a/bumblebee/themes/simple.json b/bumblebee/themes/simple.json deleted file mode 100644 index 0db3279..0000000 --- a/bumblebee/themes/simple.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} diff --git a/i3bumblebee b/i3bumblebee index 8b4602a..e74c12b 100755 --- a/i3bumblebee +++ b/i3bumblebee @@ -4,7 +4,7 @@ import sys import time import argparse import importlib -import bumblebee.themes +import bumblebee.theme import bumblebee.outputs.i3 def print_module_list(): @@ -24,7 +24,7 @@ def main(): sys.exit(0) modules = [] - theme = bumblebee.themes.Theme(args.theme) + theme = bumblebee.theme.Theme(args.theme) if args.theme else bumblebee.theme.Theme() for m in args.modules: # TODO: how to cleanly handle errors here? # (useful error messages)