2016-10-31 07:18:57 +01:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
class Theme:
|
|
|
|
def __init__(self, name="default"):
|
|
|
|
self._data = None
|
|
|
|
path = os.path.dirname(os.path.realpath(__file__))
|
2016-10-31 07:46:21 +01:00
|
|
|
with open("{}/themes/{}.json".format(path, name)) as f:
|
2016-10-31 07:18:57 +01:00
|
|
|
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, {})
|
|
|
|
|
2016-10-31 07:54:18 +01:00
|
|
|
value = getattr(obj, key)() if hasattr(obj, key) else None
|
2016-10-31 07:18:57 +01:00
|
|
|
value = self._defaults.get(key, value)
|
|
|
|
value = module_theme.get(key, value)
|
|
|
|
|
2016-10-31 07:34:43 +01:00
|
|
|
if hasattr(obj, "state"):
|
|
|
|
state = getattr(obj, "state")()
|
|
|
|
state_theme = module_theme.get("states", {}).get(state, {})
|
|
|
|
|
|
|
|
value = state_theme.get(key, value)
|
|
|
|
|
2016-10-31 07:18:57 +01:00
|
|
|
return value
|
|
|
|
|
2016-10-31 07:54:18 +01:00
|
|
|
def color(self, obj):
|
|
|
|
return self._gettheme(obj, "fg")
|
|
|
|
|
|
|
|
def background(self, obj):
|
|
|
|
return self._gettheme(obj, "bg")
|
|
|
|
|
2016-10-31 07:39:26 +01:00
|
|
|
def default_separators(self, obj):
|
|
|
|
return self._gettheme(obj, "default_separators")
|
|
|
|
|
2016-10-31 07:18:57 +01:00
|
|
|
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
|