diff --git a/core/output.py b/core/output.py index e90ba69..c372586 100644 --- a/core/output.py +++ b/core/output.py @@ -49,6 +49,7 @@ class i3(object): 'background': self._theme.bg(widget), 'separator': self._theme.default_separators(), }) + core.event.trigger('next-widget') return widgets def update(self, affected_modules=None): diff --git a/core/theme.py b/core/theme.py index 7ef636b..36f3cc3 100644 --- a/core/theme.py +++ b/core/theme.py @@ -2,6 +2,8 @@ import os import io import json +import core.event + THEME_BASE_DIR=os.path.dirname(os.path.realpath(__file__)) PATHS=[ '.', @@ -12,10 +14,13 @@ PATHS=[ class Theme(object): def __init__(self, name='default', iconset=None, raw_data=None): self.name = name + self.__widget_count = 0 if raw_data: - self._data = raw_data + self.__data = raw_data else: - self._data = self.load(name) + self.__data = self.load(name) + core.event.register('start', self.__start) + core.event.register('next-widget', self.__next_widget) def load(self, name): for path in PATHS: @@ -34,14 +39,20 @@ class Theme(object): def default_separators(self, widget=None): return self.__get(widget, 'default-separators', True) + def __start(self): + self.__widget_count = 0 + + def __next_widget(self): + self.__widget_count = self.__widget_count + 1 + def __get(self, widget, key, default=None): value = default for option in ['defaults', 'cycle']: - if option in self._data: - tmp = self._data[option] + if option in self.__data: + tmp = self.__data[option] if isinstance(tmp, list): - tmp = tmp[0] + tmp = tmp[self.__widget_count % len(tmp)] value = tmp.get(key, value) return value diff --git a/tests/core/test_theme.py b/tests/core/test_theme.py index c132d43..ad8ee35 100644 --- a/tests/core/test_theme.py +++ b/tests/core/test_theme.py @@ -14,7 +14,8 @@ class theme(unittest.TestCase): self.cycleTheme = { 'cycle': [ { 'fg': 'red', 'bg': 'black' }, - { 'fg': 'black', 'bg': 'red' } + { 'fg': 'black', 'bg': 'red' }, + { 'fg': 'white', 'bg': 'blue' } ] } @@ -35,5 +36,12 @@ class theme(unittest.TestCase): 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()) + core.event.trigger('next-widget') + core.event.trigger('next-widget') + self.assertEqual(self.cycleTheme['cycle'][2]['fg'], theme.fg()) + self.assertEqual(self.cycleTheme['cycle'][2]['bg'], theme.bg()) + core.event.trigger('start') + 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