diff --git a/core/output.py b/core/output.py index e089813..5c7f90c 100644 --- a/core/output.py +++ b/core/output.py @@ -44,7 +44,7 @@ class i3(object): return [{ 'full_text': self._theme.separator(), 'color': self._theme.bg(widget), - 'background': self._theme.prev_bg(widget), + 'background': self._theme.bg('previous'), 'separator': False, 'separator_block_width': self._theme.separator_block_width(), 'border_top': self._theme.border_top(), diff --git a/core/theme.py b/core/theme.py index 02619e8..6ceec32 100644 --- a/core/theme.py +++ b/core/theme.py @@ -16,6 +16,8 @@ class Theme(object): def __init__(self, name='default', iconset='auto', raw_data=None): self.name = name self.__widget_count = 0 + self.__previous = {} + self.__current = {} if raw_data: self.__data = raw_data else: @@ -50,19 +52,20 @@ class Theme(object): def __start(self): self.__widget_count = 0 - - def prev_bg(self, widget): - if self.__widget_count == 0: - return None - self.__widget_count = self.__widget_count - 1 - value = self.bg(widget) - self.__widget_count = self.__widget_count + 1 - return value + self.__current.clear() + self.__previous.clear() def __next_widget(self): self.__widget_count = self.__widget_count + 1 + self.__previous = dict(self.__current) + self.__current.clear() def __get(self, widget, key, default=None): + if widget and isinstance(widget, str): + # special handling + if widget == 'previous': + return self.__previous.get(key, None) + value = default for option in ['defaults', 'cycle']: @@ -71,6 +74,8 @@ class Theme(object): if isinstance(tmp, list): tmp = tmp[self.__widget_count % len(tmp)] value = tmp.get(key, value) + + self.__current[key] = value return value # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/core/test_theme.py b/tests/core/test_theme.py index eb9baad..1618461 100644 --- a/tests/core/test_theme.py +++ b/tests/core/test_theme.py @@ -36,11 +36,11 @@ class theme(unittest.TestCase): def test_cycle(self): theme = core.theme.Theme(raw_data=self.cycleTheme) - self.assertEqual(None, theme.prev_bg(None)) + self.assertEqual(None, theme.bg('previous')) self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.fg()) self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg()) core.event.trigger('next-widget') - self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.prev_bg(None)) + self.assertEqual(self.cycleTheme['cycle'][0]['bg'], theme.bg('previous')) core.event.trigger('next-widget') self.assertEqual(self.cycleTheme['cycle'][2]['fg'], theme.fg()) self.assertEqual(self.cycleTheme['cycle'][2]['bg'], theme.bg())