[core/theme] Add support for default -> prefix/suffix in themes

Themes can now define default prefix and suffix strings.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-08 11:52:47 +01:00
parent 64f5fc100e
commit 394ef61760
5 changed files with 45 additions and 15 deletions

View file

@ -12,15 +12,24 @@ def theme_path():
class Theme(object):
"""Represents a collection of icons and colors"""
def __init__(self, name):
self._theme = self.load(name)
theme = self.load(name)
self._init(self.load(name))
def prefix(self):
def _init(self, data):
"""Initialize theme from data structure"""
self._defaults = data.get("defaults", {})
def prefix(self, widget):
"""Return the theme prefix for a widget's full text"""
return None
return self._get(widget, "prefix", None)
def suffix(self):
def suffix(self, widget):
"""Return the theme suffix for a widget's full text"""
return None
return self._get(widget, "suffix", None)
def loads(self, data):
theme = json.loads(data)
self._init(theme)
def load(self, name):
"""Load and parse a theme file"""
@ -35,4 +44,10 @@ class Theme(object):
else:
raise bumblebee.error.ThemeLoadError("no such theme: {}".format(name))
def _get(self, widget, name,default=None):
value = default
value = self._defaults.get(name, value)
return value
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4