diff --git a/bumblebee/theme.py b/bumblebee/theme.py index ee6f330..a7c99cb 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -12,14 +12,18 @@ import bumblebee.error def theme_path(): """Return the path of the theme directory""" - return os.path.dirname("{}/../themes/".format(os.path.dirname(os.path.realpath(__file__)))) + return [ + os.path.dirname("{}/../themes/".format(os.path.dirname(os.path.realpath(__file__)))), + os.path.dirname(os.path.expanduser("~/.config/bumblebee-status/themes/")), + ] def themes(): result = [] - for filename in glob.iglob("{}/*.json".format(theme_path())): - if "test" not in filename: - result.append(os.path.basename(filename).replace(".json", "")) + for path in theme_path(): + for filename in glob.iglob("{}/*.json".format(path)): + if "test" not in filename: + result.append(os.path.basename(filename).replace(".json", "")) return result class Theme(object): @@ -119,21 +123,26 @@ class Theme(object): def _load_icons(self, name): """Load icons for a theme""" - path = "{}/icons/".format(theme_path()) - return self.load(name, path=path) + result = {} + for path in theme_path(): + self._merge(result, self.load(name, path="{}/icons/".format(path))) + return result def load(self, name, path=theme_path()): """Load and parse a theme file""" - themefile = "{}/{}.json".format(path, name) + if not isinstance(path, list): + path = [path] + for p in path: + themefile = "{}/{}.json".format(p, name) - if os.path.isfile(themefile): - try: - with io.open(themefile, encoding="utf-8") as data: - return json.load(data) - except ValueError as exception: - raise bumblebee.error.ThemeLoadError("JSON error: {}".format(exception)) - else: - raise bumblebee.error.ThemeLoadError("no such theme: {}".format(name)) + if os.path.isfile(themefile): + try: + with io.open(themefile, encoding="utf-8") as data: + return json.load(data) + except ValueError as exception: + raise bumblebee.error.ThemeLoadError("JSON error: {}".format(exception)) + + return {} def _get(self, widget, name, default=None): """Return the config value 'name' for 'widget'"""