bumblebee-status/bumblebee/theme.py
Tobias Witek 3ca53dd0fa [themes] Make individual items theme-able (a bit)
Individual items in the bar can now be configured with a prefix and a
suffix. It works like this:

* If there is a specific module configuration in the theme
  configuration, use that (i.e. { "<modulename>": { "prefix: " a " } })
* Otherwise, if there is a configuration in the "default" section of the
  theme, use that
* Otherwise, if the module object itself has a method called like the
  required attribute (prefix, suffix), use that
* Otherwise, leave prefix/suffix empty ("")
2016-10-31 07:18:57 +01:00

28 lines
829 B
Python

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