[core/theme] Add preliminary cycling support
Add support for cycling values in a theme, for now as long as the cycle size is 0 :P
This commit is contained in:
parent
f05098a120
commit
26ae63b5ad
3 changed files with 25 additions and 6 deletions
|
@ -43,6 +43,7 @@ class i3(object):
|
||||||
'name': module.id(),
|
'name': module.id(),
|
||||||
'color': self._theme.fg(widget),
|
'color': self._theme.fg(widget),
|
||||||
'background': self._theme.bg(widget),
|
'background': self._theme.bg(widget),
|
||||||
|
'separator': self._theme.default_separators(),
|
||||||
})
|
})
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,18 @@ class Theme(object):
|
||||||
def bg(self, widget=None):
|
def bg(self, widget=None):
|
||||||
return self.__get(widget, 'bg')
|
return self.__get(widget, 'bg')
|
||||||
|
|
||||||
|
def default_separators(self, widget=None):
|
||||||
|
return self.__get(widget, 'default-separators', True)
|
||||||
|
|
||||||
def __get(self, widget, key, default=None):
|
def __get(self, widget, key, default=None):
|
||||||
value = default
|
value = default
|
||||||
if 'defaults' in self._data:
|
|
||||||
value = self._data['defaults'].get(key, value)
|
|
||||||
|
|
||||||
|
for option in ['defaults', 'cycle']:
|
||||||
|
if option in self._data:
|
||||||
|
tmp = self._data[option]
|
||||||
|
if isinstance(tmp, list):
|
||||||
|
tmp = tmp[0]
|
||||||
|
value = tmp.get(key, value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -6,11 +6,17 @@ class theme(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.invalidThemeName = 'this-theme-does-not-exist'
|
self.invalidThemeName = 'this-theme-does-not-exist'
|
||||||
self.validThemeName = 'default'
|
self.validThemeName = 'default'
|
||||||
self.defaults = {
|
self.defaultsTheme = {
|
||||||
'defaults': {
|
'defaults': {
|
||||||
'fg': 'red', 'bg': 'black'
|
'fg': 'red', 'bg': 'black'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.cycleTheme = {
|
||||||
|
'cycle': [
|
||||||
|
{ 'fg': 'red', 'bg': 'black' },
|
||||||
|
{ 'fg': 'black', 'bg': 'red' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
def test_invalid_theme(self):
|
def test_invalid_theme(self):
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
|
@ -21,8 +27,13 @@ class theme(unittest.TestCase):
|
||||||
self.assertEqual(self.validThemeName, theme.name)
|
self.assertEqual(self.validThemeName, theme.name)
|
||||||
|
|
||||||
def test_defaults(self):
|
def test_defaults(self):
|
||||||
theme = core.theme.Theme(raw_data=self.defaults)
|
theme = core.theme.Theme(raw_data=self.defaultsTheme)
|
||||||
self.assertEqual(self.defaults['defaults']['fg'], theme.fg())
|
self.assertEqual(self.defaultsTheme['defaults']['fg'], theme.fg())
|
||||||
self.assertEqual(self.defaults['defaults']['bg'], theme.bg())
|
self.assertEqual(self.defaultsTheme['defaults']['bg'], theme.bg())
|
||||||
|
|
||||||
|
def test_cycle(self):
|
||||||
|
theme = core.theme.Theme(raw_data=self.cycleTheme)
|
||||||
|
self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg())
|
||||||
|
self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg())
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue