Add the possibility to configure custom separators in the theme file. These will only be used if the default i3bar separators have been disabled. Background color will always be taken from the previous element (to work nicely with my long-term plan, a powerline-like status line).
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
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("{}/themes/{}.json".format(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 None
|
|
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 color(self, obj):
|
|
return self._gettheme(obj, "fg")
|
|
|
|
def background(self, obj):
|
|
return self._gettheme(obj, "bg")
|
|
|
|
def separator(self, obj):
|
|
return self._gettheme(obj, "separator")
|
|
|
|
def default_separators(self, obj):
|
|
return self._gettheme(obj, "default_separators")
|
|
|
|
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
|