[theme] Re-implement colorscheme cycling
Again, allow the "default" section to contain cycles that are used one after the other for each widget.
This commit is contained in:
parent
bab7821607
commit
98acd15edf
3 changed files with 37 additions and 119 deletions
|
@ -46,9 +46,9 @@ class Output(bumblebee.output.Output):
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
if theme.separator(widget):
|
if theme.separator(widget):
|
||||||
self._data.append({
|
self._data.append({
|
||||||
u"full_text": theme.separator(obj),
|
u"full_text": theme.separator(widget),
|
||||||
"color": theme.separator_color(obj),
|
"color": theme.separator_color(widget),
|
||||||
"background": theme.separator_background(),
|
"background": theme.separator_background(widget),
|
||||||
"separator": False,
|
"separator": False,
|
||||||
"separator_block_width": 0,
|
"separator_block_width": 0,
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,24 +10,30 @@ def themes():
|
||||||
return [ os.path.basename(f).replace(".json", "") for f in glob.iglob("{}/*.json".format(d)) ]
|
return [ os.path.basename(f).replace(".json", "") for f in glob.iglob("{}/*.json".format(d)) ]
|
||||||
|
|
||||||
class Theme:
|
class Theme:
|
||||||
# TODO: cycle handling
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
with open("{}/{}.json".format(getpath(), config.theme())) as f:
|
with open("{}/{}.json".format(getpath(), config.theme())) as f:
|
||||||
self._data = json.load(f)
|
self._data = json.load(f)
|
||||||
self._defaults = self._data.get("defaults", {})
|
self._defaults = self._data.get("defaults", {})
|
||||||
self._cycle = {}
|
self._cycles = self._defaults.get("cycle", [])
|
||||||
|
self.begin()
|
||||||
|
|
||||||
def begin(self):
|
def begin(self):
|
||||||
pass
|
self._cycleidx = 0
|
||||||
|
self._cycle = self._cycles[0] if len(self._cycles) > 0 else {}
|
||||||
|
self._background = [ None, None ]
|
||||||
|
|
||||||
def next_widget(self):
|
def next_widget(self):
|
||||||
pass
|
self._background[1] = self._background[0]
|
||||||
|
self._cycleidx += 1
|
||||||
|
if self._cycleidx >= len(self._cycles):
|
||||||
|
self._cycleidx = 0
|
||||||
|
self._cycle = self._cycles[self._cycleidx] if len(self._cycles) > self._cycleidx else {}
|
||||||
|
|
||||||
def prefix(self, widget):
|
def prefix(self, widget):
|
||||||
pass
|
return self._get(widget, "prefix")
|
||||||
|
|
||||||
def suffix(self, widget):
|
def suffix(self, widget):
|
||||||
pass
|
return self._get(widget, "suffix")
|
||||||
|
|
||||||
def color(self, widget):
|
def color(self, widget):
|
||||||
result = self._get(widget, "fg")
|
result = self._get(widget, "fg")
|
||||||
|
@ -38,22 +44,28 @@ class Theme:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def background(self, widget):
|
def background(self, widget):
|
||||||
pass
|
result = self._get(widget, "bg")
|
||||||
|
if widget.warning():
|
||||||
|
result = self._get(widget, "bg-warning")
|
||||||
|
if widget.critical():
|
||||||
|
result = self._get(widget, "bg-critical")
|
||||||
|
self._background[0] = result
|
||||||
|
return result
|
||||||
|
|
||||||
def separator(self, widget):
|
def separator(self, widget):
|
||||||
pass
|
return self._get(widget, "separator")
|
||||||
|
|
||||||
def separator_color(self, widget):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def separator_background(self, widget):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def default_separators(self, widget):
|
def default_separators(self, widget):
|
||||||
pass
|
return self._get(widget, "default-separators")
|
||||||
|
|
||||||
|
def separator_color(self, widget):
|
||||||
|
return self.background(widget)
|
||||||
|
|
||||||
|
def separator_background(self, widget):
|
||||||
|
return self._background[1]
|
||||||
|
|
||||||
def separator_block_width(self, widget):
|
def separator_block_width(self, widget):
|
||||||
pass
|
return 9
|
||||||
|
|
||||||
def _get(self, widget, name):
|
def _get(self, widget, name):
|
||||||
module = widget.module()
|
module = widget.module()
|
||||||
|
@ -74,98 +86,4 @@ class Theme:
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
#class Theme:
|
|
||||||
# _cycle_index = 0
|
|
||||||
# _cycle = None
|
|
||||||
# def __init__(self, config):
|
|
||||||
# self._data = None
|
|
||||||
# path = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
# with open("{}/{}.json".format(getpath(), config.theme())) as f:
|
|
||||||
# self._data = json.load(f)
|
|
||||||
# self._defaults = self._data.get("defaults", {})
|
|
||||||
# self._cycle = self._defaults.get("cycle", [])
|
|
||||||
# self._modules = {}
|
|
||||||
#
|
|
||||||
# self.reset()
|
|
||||||
#
|
|
||||||
# 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)
|
|
||||||
# if len(self._cycle) > 0:
|
|
||||||
# value = self._defaults["cycle"][self._cycle_index].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)
|
|
||||||
#
|
|
||||||
# if type(value) is list:
|
|
||||||
# # cycle through the values
|
|
||||||
# if not obj in self._modules:
|
|
||||||
# self._modules[obj] = { "idx": 0 }
|
|
||||||
# else:
|
|
||||||
# self._modules[obj]["idx"] += 1
|
|
||||||
# if self._modules[obj]["idx"] >= len(value):
|
|
||||||
# self._modules[obj]["idx"] = 0
|
|
||||||
# value = value[self._modules[obj]["idx"]]
|
|
||||||
#
|
|
||||||
# return value
|
|
||||||
#
|
|
||||||
# def reset(self):
|
|
||||||
# self._cycle_index = 0
|
|
||||||
# self._previous_background = None
|
|
||||||
# self._background = None
|
|
||||||
#
|
|
||||||
# def urgent(self, obj):
|
|
||||||
# self._gettheme(obj, "urgent")
|
|
||||||
#
|
|
||||||
# def next(self):
|
|
||||||
# self._cycle_index += 1
|
|
||||||
# self._previous_background = self._background
|
|
||||||
# if self._cycle_index >= len(self._cycle):
|
|
||||||
# self._cycle_index = 0
|
|
||||||
#
|
|
||||||
# def color(self, obj):
|
|
||||||
# fg = None
|
|
||||||
# if obj.warning():
|
|
||||||
# fg = self._gettheme(obj, "fg-warning")
|
|
||||||
# if obj.critical():
|
|
||||||
# fg = self._gettheme(obj, "fg-critical")
|
|
||||||
# if fg == None:
|
|
||||||
# fg = self._gettheme(obj, "fg")
|
|
||||||
# return fg
|
|
||||||
#
|
|
||||||
# def background(self, obj):
|
|
||||||
# self._background = None
|
|
||||||
# if obj.warning():
|
|
||||||
# self._background = self._gettheme(obj, "bg-warning")
|
|
||||||
# if obj.critical():
|
|
||||||
# self._background = self._gettheme(obj, "bg-critical")
|
|
||||||
#
|
|
||||||
# if self._background == None:
|
|
||||||
# self._background = self._gettheme(obj, "bg")
|
|
||||||
#
|
|
||||||
# return self._background
|
|
||||||
#
|
|
||||||
# def previous_background(self):
|
|
||||||
# return self._previous_background
|
|
||||||
#
|
|
||||||
# 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
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
"fg-warning": "#002b36",
|
"fg-warning": "#002b36",
|
||||||
"bg-warning": "#b58900",
|
"bg-warning": "#b58900",
|
||||||
|
|
||||||
"default_separators": false,
|
"default-separators": false,
|
||||||
"separator": ""
|
"separator": ""
|
||||||
},
|
},
|
||||||
"date": {
|
"date": {
|
||||||
|
@ -98,23 +98,23 @@
|
||||||
"prefix": [ " ", " ", " ", " ", " " ],
|
"prefix": [ " ", " ", " ", " ", " " ],
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging_critical": {
|
"discharging-critical": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging_low": {
|
"discharging-low": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging_medium": {
|
"discharging-medium": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging_high": {
|
"discharging-high": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging_full": {
|
"discharging-full": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue