[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)
|
full_text = u"{}{}".format(prefix, full_text)
|
||||||
if suffix:
|
if suffix:
|
||||||
full_text = u"{}{}".format(full_text, 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({
|
self._widgets.append({
|
||||||
u"full_text": u"{}".format(full_text),
|
u"full_text": full_text,
|
||||||
"color": self._theme.fg(widget),
|
"color": self._theme.fg(widget),
|
||||||
"background": self._theme.bg(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):
|
def begin(self):
|
||||||
|
|
|
@ -36,6 +36,7 @@ class Theme(object):
|
||||||
self._cycle = self._cycles[0] if len(self._cycles) > 0 else {}
|
self._cycle = self._cycles[0] if len(self._cycles) > 0 else {}
|
||||||
self._cycle_idx = 0
|
self._cycle_idx = 0
|
||||||
self._widget = None
|
self._widget = None
|
||||||
|
self._prevbg = None
|
||||||
|
|
||||||
def prefix(self, widget):
|
def prefix(self, widget):
|
||||||
"""Return the theme prefix for a widget's full text"""
|
"""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 the background color for this widget"""
|
||||||
return self._get(widget, "bg", None)
|
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):
|
def loads(self, data):
|
||||||
"""Initialize the theme from a JSON string"""
|
"""Initialize the theme from a JSON string"""
|
||||||
theme = json.loads(data)
|
theme = json.loads(data)
|
||||||
|
@ -87,9 +102,11 @@ class Theme(object):
|
||||||
self._widget = widget
|
self._widget = widget
|
||||||
|
|
||||||
if self._widget != widget:
|
if self._widget != widget:
|
||||||
|
self._prevbg = self.bg(self._widget)
|
||||||
self._widget = widget
|
self._widget = widget
|
||||||
self._cycle_idx = (self._cycle_idx + 1) % len(self._cycles)
|
if len(self._cycles) > 0:
|
||||||
self._cycle = self._cycles[self._cycle_idx]
|
self._cycle_idx = (self._cycle_idx + 1) % len(self._cycles)
|
||||||
|
self._cycle = self._cycles[self._cycle_idx]
|
||||||
|
|
||||||
module_theme = self._theme.get(widget.module, {})
|
module_theme = self._theme.get(widget.module, {})
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,14 @@ class TestTheme(unittest.TestCase):
|
||||||
self.themedWidget.module = self.widgetTheme
|
self.themedWidget.module = self.widgetTheme
|
||||||
self.assertEquals(self.theme.bg(self.themedWidget), self.widgetBgColor)
|
self.assertEquals(self.theme.bg(self.themedWidget), self.widgetBgColor)
|
||||||
|
|
||||||
|
def test_absent_cycle(self):
|
||||||
|
theme = self.theme
|
||||||
|
try:
|
||||||
|
theme.fg(self.anyWidget)
|
||||||
|
theme.fg(self.anotherWidget)
|
||||||
|
except Exception as e:
|
||||||
|
self.fail(e)
|
||||||
|
|
||||||
def test_reset(self):
|
def test_reset(self):
|
||||||
theme = self.cycleTheme
|
theme = self.cycleTheme
|
||||||
data = theme.data()
|
data = theme.data()
|
||||||
|
@ -70,4 +78,20 @@ class TestTheme(unittest.TestCase):
|
||||||
theme.reset()
|
theme.reset()
|
||||||
self.assertEquals(theme.fg(self.anyWidget), data["cycle"][0]["fg"])
|
self.assertEquals(theme.fg(self.anyWidget), data["cycle"][0]["fg"])
|
||||||
|
|
||||||
|
def test_separator_block_width(self):
|
||||||
|
theme = self.theme
|
||||||
|
data = theme.data()
|
||||||
|
|
||||||
|
self.assertEquals(theme.separator_block_width(self.anyWidget), data["defaults"]["separator-block-width"])
|
||||||
|
|
||||||
|
def test_separator(self):
|
||||||
|
for theme in [self.theme, self.cycleTheme]:
|
||||||
|
data = theme.data()
|
||||||
|
theme.reset()
|
||||||
|
prev_bg = theme.bg(self.anyWidget)
|
||||||
|
theme.bg(self.anotherWidget)
|
||||||
|
|
||||||
|
self.assertEquals(theme.separator_fg(self.anotherWidget), theme.bg(self.anotherWidget))
|
||||||
|
self.assertEquals(theme.separator_bg(self.anotherWidget), prev_bg)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -45,10 +45,18 @@ class MockTheme(object):
|
||||||
self.attr_suffix = None
|
self.attr_suffix = None
|
||||||
self.attr_fg = None
|
self.attr_fg = None
|
||||||
self.attr_bg = None
|
self.attr_bg = None
|
||||||
|
self.attr_separator = None
|
||||||
|
self.attr_separator_block_width = 0
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def separator_block_width(self, widget):
|
||||||
|
return self.attr_separator_block_width
|
||||||
|
|
||||||
|
def separator(self, widget):
|
||||||
|
return self.attr_separator
|
||||||
|
|
||||||
def prefix(self, widget):
|
def prefix(self, widget):
|
||||||
return self.attr_prefix
|
return self.attr_prefix
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"icons": [ "awesome-fonts" ],
|
"icons": [ "awesome-fonts" ],
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"default-separators": false,
|
|
||||||
"separator-block-width": 0,
|
"separator-block-width": 0,
|
||||||
"warning": {
|
"warning": {
|
||||||
"fg": "#002b36",
|
"fg": "#002b36",
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
"prefix": "default-prefix",
|
"prefix": "default-prefix",
|
||||||
"suffix": "default-suffix",
|
"suffix": "default-suffix",
|
||||||
"fg": "#000000",
|
"fg": "#000000",
|
||||||
"bg": "#111111"
|
"bg": "#111111",
|
||||||
|
"separator": " * ",
|
||||||
|
"separator-block-width": 10
|
||||||
},
|
},
|
||||||
"test-widget": {
|
"test-widget": {
|
||||||
"fg": "#ababab",
|
"fg": "#ababab",
|
||||||
|
|
Loading…
Reference in a new issue