[core/themes] Add theme merging from different locations

Theme files with the same name, but in different theme locations, are
now merged together.

see #203
This commit is contained in:
Tobias Witek 2017-11-18 14:56:44 +01:00
parent 9d7fc5c1d4
commit 15c78cd6a6

View file

@ -132,6 +132,7 @@ class Theme(object):
def load(self, name, path=theme_path()): def load(self, name, path=theme_path()):
"""Load and parse a theme file""" """Load and parse a theme file"""
result = None
if not isinstance(path, list): if not isinstance(path, list):
path = [path] path = [path]
for p in path: for p in path:
@ -140,11 +141,14 @@ class Theme(object):
if os.path.isfile(themefile): if os.path.isfile(themefile):
try: try:
with io.open(themefile, encoding="utf-8") as data: with io.open(themefile, encoding="utf-8") as data:
return json.load(data) if result is None:
result = json.load(data)
else:
self._merge(result, json.load(data))
except ValueError as exception: except ValueError as exception:
raise bumblebee.error.ThemeLoadError("JSON error: {}".format(exception)) raise bumblebee.error.ThemeLoadError("JSON error: {}".format(exception))
return {} return result
def _get(self, widget, name, default=None): def _get(self, widget, name, default=None):
"""Return the config value 'name' for 'widget'""" """Return the config value 'name' for 'widget'"""