[core/themes] Add separator customization
Add customized separators: * The default separators are automatically disabled if custom separators are used (to "just" disable the default, use empty custom separators) * Use previous background color as their background color and the current background color as foreground color * Allow the separator-block-width to be configured see #23
This commit is contained in:
parent
527489e0de
commit
c1f1e1a939
6 changed files with 66 additions and 5 deletions
|
@ -48,10 +48,21 @@ class I3BarOutput(object):
|
|||
full_text = u"{}{}".format(prefix, full_text)
|
||||
if suffix:
|
||||
full_text = u"{}{}".format(full_text, suffix)
|
||||
separator = self._theme.separator(widget)
|
||||
if separator:
|
||||
self._widgets.append({
|
||||
u"full_text": separator,
|
||||
"separator": False,
|
||||
"color": self._theme.separator_fg(widget),
|
||||
"background": self._theme.separator_bg(widget),
|
||||
"separator_block_width": self._theme.separator_block_width(widget),
|
||||
})
|
||||
self._widgets.append({
|
||||
u"full_text": u"{}".format(full_text),
|
||||
u"full_text": full_text,
|
||||
"color": self._theme.fg(widget),
|
||||
"background": self._theme.bg(widget),
|
||||
"separator_block_width": self._theme.separator_block_width(widget),
|
||||
"separator": True if separator is None else False,
|
||||
})
|
||||
|
||||
def begin(self):
|
||||
|
|
|
@ -36,6 +36,7 @@ class Theme(object):
|
|||
self._cycle = self._cycles[0] if len(self._cycles) > 0 else {}
|
||||
self._cycle_idx = 0
|
||||
self._widget = None
|
||||
self._prevbg = None
|
||||
|
||||
def prefix(self, widget):
|
||||
"""Return the theme prefix for a widget's full text"""
|
||||
|
@ -57,6 +58,20 @@ class Theme(object):
|
|||
"""Return the background color for this widget"""
|
||||
return self._get(widget, "bg", None)
|
||||
|
||||
def separator(self, widget):
|
||||
"""Return the separator between widgets"""
|
||||
return self._get(widget, "separator", None)
|
||||
|
||||
def separator_fg(self, widget):
|
||||
return self.bg(widget)
|
||||
|
||||
def separator_bg(self, widget):
|
||||
return self._prevbg
|
||||
|
||||
def separator_block_width(self, widget):
|
||||
"""Return the SBW"""
|
||||
return self._get(widget, "separator-block-width", None)
|
||||
|
||||
def loads(self, data):
|
||||
"""Initialize the theme from a JSON string"""
|
||||
theme = json.loads(data)
|
||||
|
@ -87,9 +102,11 @@ class Theme(object):
|
|||
self._widget = widget
|
||||
|
||||
if self._widget != widget:
|
||||
self._prevbg = self.bg(self._widget)
|
||||
self._widget = widget
|
||||
self._cycle_idx = (self._cycle_idx + 1) % len(self._cycles)
|
||||
self._cycle = self._cycles[self._cycle_idx]
|
||||
if len(self._cycles) > 0:
|
||||
self._cycle_idx = (self._cycle_idx + 1) % len(self._cycles)
|
||||
self._cycle = self._cycles[self._cycle_idx]
|
||||
|
||||
module_theme = self._theme.get(widget.module, {})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue