[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:
parent
64f5fc100e
commit
394ef61760
5 changed files with 45 additions and 15 deletions
|
@ -33,10 +33,12 @@ class I3BarOutput(object):
|
|||
def draw_widget(self, result, widget):
|
||||
"""Draw a single widget"""
|
||||
full_text = widget.full_text()
|
||||
if self._theme.prefix():
|
||||
full_text = "{}{}".format(self._theme.prefix(), full_text)
|
||||
if self._theme.suffix():
|
||||
full_text = "{}{}".format(full_text, self._theme.suffix())
|
||||
prefix = self._theme.prefix(widget)
|
||||
suffix = self._theme.suffix(widget)
|
||||
if prefix:
|
||||
full_text = "{}{}".format(prefix, full_text)
|
||||
if suffix:
|
||||
full_text = "{}{}".format(full_text, suffix)
|
||||
result.append({
|
||||
u"full_text": "{}".format(full_text)
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue