diff --git a/bumblebee/outputs/i3.py b/bumblebee/outputs/i3.py index ac72855..e6e42b0 100644 --- a/bumblebee/outputs/i3.py +++ b/bumblebee/outputs/i3.py @@ -52,7 +52,7 @@ class Output(bumblebee.output.Output): }) self._data.append({ - u"full_text": "{}{}{}".format( + u"full_text": " {} {} {} ".format( theme.prefix(widget), widget.text(), theme.suffix(widget) diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 88b27cd..047a9ff 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -1,4 +1,5 @@ import os +import copy import json import yaml import glob @@ -14,16 +15,44 @@ class Theme: def __init__(self, config): self._config = config - if os.path.isfile("{}/{}.yaml".format(getpath(), config.theme())): - with open("{}/{}.yaml".format(getpath(), config.theme())) as f: - self._data = yaml.load(f) - else: - with open("{}/{}.json".format(getpath(), config.theme())) as f: - self._data = json.load(f) + self._data = self.get_theme(config.theme()) + + for iconset in self._data.get("icons", []): + self.merge(self._data, self.get_theme(iconset)) + self._defaults = self._data.get("defaults", {}) self._cycles = self._defaults.get("cycle", []) self.begin() + def get_theme(self, name): + for path in [ getpath(), "{}/icons/".format(getpath()) ]: + if os.path.isfile("{}/{}.yaml".format(path, name)): + with open("{}/{}.yaml".format(path, name)) as f: + return yaml.load(f) + if os.path.isfile("{}/{}.json".format(path, name)): + with open("{}/{}.json".format(path, name)) as f: + return json.load(f) + return None + + # algorithm copied from + # http://blog.impressiver.com/post/31434674390/deep-merge-multiple-python-dicts + # nicely done :) + def merge(self, target, *args): + if len(args) > 1: + for item in args: + self.merge(item) + return target + + item = args[0] + if not isinstance(item, dict): + return item + for key, value in item.iteritems(): + if key in target and isinstance(target[key], dict): + self.merge(target[key], value) + else: + target[key] = copy.deepcopy(value) + return target + def begin(self): self._config.set("theme.cycleidx", 0) self._cycle = self._cycles[0] if len(self._cycles) > 0 else {} diff --git a/themes/default.json b/themes/default.json index 32a23ea..ddda5fe 100644 --- a/themes/default.json +++ b/themes/default.json @@ -1,128 +1,7 @@ { + "icons": [ "ascii" ], "defaults": { - "prefix": " ", - "suffix" : " ", "urgent": true, "fg": "#aabbcc" - }, - "date": { - "prefix": " " - }, - "time": { - "prefix": " " - }, - "memory": { - "prefix": " ram " - }, - "cpu": { - "prefix": " cpu " - }, - "disk": { - "prefix": " hdd " - }, - "dnf": { - "prefix": " dnf " - }, - "brightness": { - "prefix": " o " - }, - "cmus": { - "states": { - "playing": { - "prefix": " > " - }, - "paused": { - "prefix": " || " - }, - "stopped": { - "prefix": " [] " - } - }, - "prev": { - "prefix": " |< " - }, - "next": { - "prefix": " >| " - }, - "shuffle": { - "states": { "on": { "prefix": " S " }, "off": { "prefix": " [s] " } } - }, - "repeat": { - "states": { "on": { "prefix": " R " }, "off": { "prefix": " [r] " } } - } - }, - "pasink": { - "states": { - "muted": { - "prefix": " audio(mute) " - }, - "unmuted": { - "prefix": " audio " - } - } - }, - "pasource": { - "states": { - "muted": { - "prefix": " mic(mute) " - }, - "unmuted": { - "prefix": " mic " - } - } - }, - "nic": { - "states": { - "wireless-up": { - "prefix": " wifi " - }, - "wireless-down": { - "prefix": " wifi " - }, - "wired-up": { - "prefix": " lan " - }, - "wired-down": { - "prefix": " lan " - }, - "tunnel-up": { - "prefix": " tun " - }, - "tunnel-down": { - "prefix": " tun " - } - } - }, - "battery": { - "states": { - "charged": { - "suffix": " full " - }, - "charging": { - "suffix": " chr " - }, - "AC": { - "suffix": " ac " - }, - "discharging-10": { - "prefix": " ! ", - "suffix": " dis " - }, - "discharging-25": { - "suffix": " dis " - }, - "discharging-50": { - "suffix": " dis " - }, - "discharging-80": { - "suffix": " dis " - }, - "discharging-100": { - "suffix": " dis " - } - } - }, - "caffeine": { - "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/themes/gruvbox-powerline.json b/themes/gruvbox-powerline.json index 1f3271b..f04bbc7 100644 --- a/themes/gruvbox-powerline.json +++ b/themes/gruvbox-powerline.json @@ -1,4 +1,5 @@ { + "icons": [ "paxy97", "awesome-fonts" ], "defaults": { "prefix": " ", "suffix" : " ", @@ -18,26 +19,9 @@ "bg-warning": "#d79921", "default-separators": false, - "separator-block-width": 0, - "separator": "" - }, - "date": { - "prefix": "  " - }, - "time": { - "prefix": "  " - }, - "memory": { - "prefix": "  " - }, - "cpu": { - "prefix": "  " - }, - "disk": { - "prefix": "  " + "separator-block-width": 0 }, "dnf": { - "prefix": "  ", "states": { "good": { "fg": "#002b36", @@ -45,116 +29,16 @@ } } }, - "pasink": { - "states": { - "muted": { - "prefix": "  " - }, - "unmuted": { - "prefix": "  " - } - } - }, - "pasource": { - "states": { - "muted": { - "prefix": "  " - }, - "unmuted": { - "prefix": "  " - } - } - }, - "nic": { - "states": { - "wireless-up": { - "prefix": "  " - }, - "wireless-down": { - "prefix": "  " - }, - "wired-up": { - "prefix": "  " - }, - "wired-down": { - "prefix": "  " - }, - "tunnel-up": { - "prefix": "  " - }, - "tunnel-down": { - "prefix": "  " - } - } - }, "battery": { "states": { "charged": { - "prefix": "  ", - "suffix": "  ", "fg": "#1d2021", "bg": "#b8bb26" }, "AC": { - "suffix": "  ", "fg": "#1d2021", "bg": "#b8bb26" - }, - "charging": { - "prefix": [ "  ", "  ", "  ", "  ", "  " ], - "suffix": "  " - }, - "discharging-10": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-25": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-50": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-80": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-100": { - "prefix": "  ", - "suffix": "  " } } - }, - "cmus": { - "states": { - "playing": { - "prefix": "  " - }, - "paused": { - "prefix": "  " - }, - "stopped": { - "prefix": "  " - } - }, - "prev": { - "prefix": "  " - }, - "next": { - "prefix": "  " - }, - "shuffle": { - "states": { "on": { "prefix": "  " }, "off": { "prefix": "  " } } - }, - "repeat": { - "states": { "on": { "prefix": "  " }, "off": { "prefix": "  " } } - } - }, - "brightness": { - "prefix": "  " - }, - "caffeine": { - "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json new file mode 100644 index 0000000..aa94461 --- /dev/null +++ b/themes/icons/ascii.json @@ -0,0 +1,116 @@ +{ + "memory": { + "prefix": "ram" + }, + "cpu": { + "prefix": "cpu" + }, + "disk": { + "prefix": "hdd" + }, + "dnf": { + "prefix": "dnf" + }, + "brightness": { + "prefix": "o" + }, + "cmus": { + "states": { + "playing": { + "prefix": ">" + }, + "paused": { + "prefix": "||" + }, + "stopped": { + "prefix": "[]" + } + }, + "prev": { + "prefix": "|<" + }, + "next": { + "prefix": ">|" + }, + "shuffle": { + "states": { "on": { "prefix": "S" }, "off": { "prefix": "[s]" } } + }, + "repeat": { + "states": { "on": { "prefix": "R" }, "off": { "prefix": "[r]" } } + } + }, + "pasink": { + "states": { + "muted": { + "prefix": "audio(mute)" + }, + "unmuted": { + "prefix": "audio" + } + } + }, + "pasource": { + "states": { + "muted": { + "prefix": "mic(mute)" + }, + "unmuted": { + "prefix": "mic" + } + } + }, + "nic": { + "states": { + "wireless-up": { + "prefix": "wifi" + }, + "wireless-down": { + "prefix": "wifi" + }, + "wired-up": { + "prefix": "lan" + }, + "wired-down": { + "prefix": "lan" + }, + "tunnel-up": { + "prefix": "tun" + }, + "tunnel-down": { + "prefix": "tun" + } + } + }, + "battery": { + "states": { + "charged": { + "suffix": "full" + }, + "charging": { + "suffix": "chr" + }, + "AC": { + "suffix": "ac" + }, + "discharging-10": { + "prefix": "!", + "suffix": "dis" + }, + "discharging-25": { + "suffix": "dis" + }, + "discharging-50": { + "suffix": "dis" + }, + "discharging-80": { + "suffix": "dis" + }, + "discharging-100": { + "suffix": "dis" + } + } + }, + "caffeine": { + "states": { "activated": {"prefix": "caf-on" }, "deactivated": { "prefix": "caf-off " } } + } +} diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json new file mode 100644 index 0000000..9ba437f --- /dev/null +++ b/themes/icons/awesome-fonts.json @@ -0,0 +1,131 @@ +{ + "defaults": { + "separator": "" + }, + "date": { + "prefix": "" + }, + "time": { + "prefix": "" + }, + "memory": { + "prefix": "" + }, + "cpu": { + "prefix": "" + }, + "disk": { + "prefix": "" + }, + "dnf": { + "prefix": "" + }, + "brightness": { + "prefix": "" + }, + "cmus": { + "states": { + "playing": { + "prefix": "" + }, + "paused": { + "prefix": "" + }, + "stopped": { + "prefix": "" + } + }, + "prev": { + "prefix": "" + }, + "next": { + "prefix": "" + }, + "shuffle": { + "states": { "on": { "prefix": "" }, "off": { "prefix": "" } } + }, + "repeat": { + "states": { "on": { "prefix": "" }, "off": { "prefix": "" } } + } + }, + "pasink": { + "states": { + "muted": { + "prefix": "" + }, + "unmuted": { + "prefix": "" + } + } + }, + "pasource": { + "states": { + "muted": { + "prefix": "" + }, + "unmuted": { + "prefix": "" + } + } + }, + "nic": { + "states": { + "wireless-up": { + "prefix": "" + }, + "wireless-down": { + "prefix": "" + }, + "wired-up": { + "prefix": "" + }, + "wired-down": { + "prefix": "" + }, + "tunnel-up": { + "prefix": "" + }, + "tunnel-down": { + "prefix": "" + } + } + }, + "battery": { + "states": { + "charged": { + "prefix": "", + "suffix": "" + }, + "AC": { + "suffix": "" + }, + "charging": { + "prefix": [ "", "", "", "", "" ], + "suffix": "" + }, + "discharging-10": { + "prefix": "", + "suffix": "" + }, + "discharging-25": { + "prefix": "", + "suffix": "" + }, + "discharging-50": { + "prefix": "", + "suffix": "" + }, + "discharging-80": { + "prefix": "", + "suffix": "" + }, + "discharging-100": { + "prefix": "", + "suffix": "" + } + } + }, + "caffeine": { + "states": { "activated": {"prefix": " " }, "deactivated": { "prefix": " " } } + } +} diff --git a/themes/icons/paxy97.json b/themes/icons/paxy97.json new file mode 100644 index 0000000..9a889ab --- /dev/null +++ b/themes/icons/paxy97.json @@ -0,0 +1,5 @@ +{ + "memory": { + "prefix": "  " + } +} diff --git a/themes/powerline.json b/themes/powerline.json index 84fb73a..bfec776 100644 --- a/themes/powerline.json +++ b/themes/powerline.json @@ -1,7 +1,6 @@ { + "icons": [ "awesome-fonts" ], "defaults": { - "prefix": " ", - "suffix" : " ", "cycle": [ { "fg": "#ffd700", @@ -17,26 +16,9 @@ "fg-warning": "#d75f00", "bg-warning": "#ffd700", - "default_separators": false, - "separator": "" - }, - "date": { - "prefix": "  " - }, - "time": { - "prefix": "  " - }, - "memory": { - "prefix": "  " - }, - "cpu": { - "prefix": "  " - }, - "disk": { - "prefix": "  " + "default_separators": false }, "dnf": { - "prefix": "  ", "states": { "good": { "fg": "#494949", @@ -44,116 +26,16 @@ } } }, - "brightness": { - "prefix": "  " - }, - "cmus": { - "states": { - "playing": { - "prefix": "  " - }, - "paused": { - "prefix": "  " - }, - "stopped": { - "prefix": "  " - } - }, - "prev": { - "prefix": "  " - }, - "next": { - "prefix": "  " - }, - "shuffle": { - "states": { "on": { "prefix": "  " }, "off": { "prefix": "  " } } - }, - "repeat": { - "states": { "on": { "prefix": "  " }, "off": { "prefix": "  " } } - } - }, - "pasink": { - "states": { - "muted": { - "prefix": "  " - }, - "unmuted": { - "prefix": "  " - } - } - }, - "pasource": { - "states": { - "muted": { - "prefix": "  " - }, - "unmuted": { - "prefix": "  " - } - } - }, - "nic": { - "states": { - "wireless-up": { - "prefix": "  " - }, - "wireless-down": { - "prefix": "  " - }, - "wired-up": { - "prefix": "  " - }, - "wired-down": { - "prefix": "  " - }, - "tunnel-up": { - "prefix": "  " - }, - "tunnel-down": { - "prefix": "  " - } - } - }, "battery": { "states": { "charged": { - "prefix": "  ", - "suffix": "  ", "fg": "#494949", "bg": "#41db00" }, "AC": { - "suffix": "  ", "fg": "#494949", "bg": "#41db00" - }, - "charging": { - "prefix": [ "  ", "  ", "  ", "  ", "  " ], - "suffix": "  " - }, - "discharging-10": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-25": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-50": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-80": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-100": { - "prefix": "  ", - "suffix": "  " } } - }, - "caffeine": { - "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/themes/solarized-powerline.json b/themes/solarized-powerline.json index 5cbd561..998b7f4 100644 --- a/themes/solarized-powerline.json +++ b/themes/solarized-powerline.json @@ -1,7 +1,6 @@ { + "icons": [ "awesome-fonts" ], "defaults": { - "prefix": " ", - "suffix" : " ", "cycle": [ { "fg": "#93a1a1", @@ -18,26 +17,9 @@ "bg-warning": "#b58900", "default-separators": false, - "separator-block-width": 0, - "separator": "" - }, - "date": { - "prefix": "  " - }, - "time": { - "prefix": "  " - }, - "memory": { - "prefix": "  " - }, - "cpu": { - "prefix": "  " - }, - "disk": { - "prefix": "  " + "separator-block-width": 0 }, "dnf": { - "prefix": "  ", "states": { "good": { "fg": "#002b36", @@ -45,116 +27,16 @@ } } }, - "brightness": { - "prefix": "  " - }, - "cmus": { - "states": { - "playing": { - "prefix": "  " - }, - "paused": { - "prefix": "  " - }, - "stopped": { - "prefix": "  " - } - }, - "prev": { - "prefix": "  " - }, - "next": { - "prefix": "  " - }, - "shuffle": { - "states": { "on": { "prefix": "  " }, "off": { "prefix": "  " } } - }, - "repeat": { - "states": { "on": { "prefix": "  " }, "off": { "prefix": "  " } } - } - }, - "pasink": { - "states": { - "muted": { - "prefix": "  " - }, - "unmuted": { - "prefix": "  " - } - } - }, - "pasource": { - "states": { - "muted": { - "prefix": "  " - }, - "unmuted": { - "prefix": "  " - } - } - }, - "nic": { - "states": { - "wireless-up": { - "prefix": "  " - }, - "wireless-down": { - "prefix": "  " - }, - "wired-up": { - "prefix": "  " - }, - "wired-down": { - "prefix": "  " - }, - "tunnel-up": { - "prefix": "  " - }, - "tunnel-down": { - "prefix": "  " - } - } - }, "battery": { "states": { "charged": { - "prefix": "  ", - "suffix": "  ", "fg": "#002b36", "bg": "#859900" }, "AC": { - "suffix": "  ", "fg": "#002b36", "bg": "#859900" - }, - "charging": { - "prefix": [ "  ", "  ", "  ", "  ", "  " ], - "suffix": "  " - }, - "discharging-10": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-25": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-50": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-80": { - "prefix": "  ", - "suffix": "  " - }, - "discharging-100": { - "prefix": "  ", - "suffix": "  " } } - }, - "caffeine": { - "states": { "activated": {"prefix": "   " }, "deactivated": { "prefix": "   " } } } } diff --git a/themes/solarized.json b/themes/solarized.json index af6d876..6da0c7a 100644 --- a/themes/solarized.json +++ b/themes/solarized.json @@ -1,7 +1,6 @@ { + "icons": [ "ascii" ], "defaults": { - "prefix": " ", - "suffix" : " ", "cycle": [ { "fg": "#93a1a1", @@ -20,23 +19,7 @@ "default_separators": false, "separator": "|" }, - "date": { - "prefix": " " - }, - "time": { - "prefix": " " - }, - "memory": { - "prefix": " ram " - }, - "cpu": { - "prefix": " cpu " - }, - "disk": { - "prefix": " hdd " - }, "dnf": { - "prefix": " dnf ", "states": { "good": { "fg": "#002b36", @@ -44,110 +27,15 @@ } } }, - "brightness": { - "prefix": " o " - }, - "cmus": { - "states": { - "playing": { - "prefix": " > " - }, - "paused": { - "prefix": " || " - }, - "stopped": { - "prefix": " [] " - } - }, - "prev": { - "prefix": " |< " - }, - "next": { - "prefix": " >| " - }, - "shuffle": { - "states": { "on": { "prefix": " S " }, "off": { "prefix": " [s] " } } - }, - "repeat": { - "states": { "on": { "prefix": " R " }, "off": { "prefix": " [r] " } } - } - }, - "pasink": { - "states": { - "muted": { - "prefix": " audio(mute) " - }, - "unmuted": { - "prefix": " audio " - } - } - }, - "pasource": { - "states": { - "muted": { - "prefix": " mic(mute) " - }, - "unmuted": { - "prefix": " mic " - } - } - }, - "nic": { - "states": { - "wireless-up": { - "prefix": " wifi " - }, - "wireless-down": { - "prefix": " wifi " - }, - "wired-up": { - "prefix": " lan " - }, - "wired-down": { - "prefix": " lan " - }, - "tunnel-up": { - "prefix": " tun " - }, - "tunnel-down": { - "prefix": " tun " - } - } - }, "battery": { "states": { "charged": { - "suffix": " full ", "fg": "#002b36", "bg": "#859900" }, "AC": { - "suffix": " ac ", "fg": "#002b36", "bg": "#859900" - }, - "charging": { - "suffix": " chr " - }, - "discharging-10": { - "prefix": " ! ", - "suffix": " dis " - }, - "discharging-25": { - "suffix": " dis " - }, - "discharging-50": { - "suffix": " dis " - }, - "discharging-80": { - "suffix": " dis " - }, - "discharging-100": { - "suffix": " dis " } - } - }, - "caffeine": { - "states": { "activated": {"prefix": " caf on " }, "deactivated": { "prefix": " caf off " } } } }