diff --git a/core/theme.py b/core/theme.py index cfaa142..1911742 100644 --- a/core/theme.py +++ b/core/theme.py @@ -34,6 +34,7 @@ class Theme(object): self.__previous = {} self.__current = {} self.__keywords = {} + self.__value_idx = {} self.__data = raw_data if raw_data else self.load(name) for icons in self.__data.get('icons', []): util.algorithm.merge(self.__data, self.load(icons, 'icons')) @@ -81,6 +82,9 @@ class Theme(object): self.__current.clear() self.__previous.clear() + for key, value in self.__value_idx.items(): + self.__value_idx[key] = value + 1 + def __next_widget(self): self.__widget_count = self.__widget_count + 1 self.__previous = dict(self.__current) @@ -119,9 +123,9 @@ class Theme(object): value = self.__keywords.get(value, value) if isinstance(value, list): - key = '__{}-idx__'.format(key) - idx = widget.get(key, 0) - widget.set(key, (idx + 1) % len(value)) + idx = self.__value_idx.get('{}::{}'.format(widget.id, key), 0) % len(value) + self.__value_idx['{}::{}'.format(widget.id, key)] = idx + widget.set(key, idx) value = value[idx] self.__current[key] = value return value diff --git a/tests/core/test_theme.py b/tests/core/test_theme.py index 324d892..41e57d8 100644 --- a/tests/core/test_theme.py +++ b/tests/core/test_theme.py @@ -63,7 +63,7 @@ class theme(unittest.TestCase): core.event.trigger('next-widget') self.assertEqual(self.cycleTheme['cycle'][2]['fg'], theme.get('fg')) self.assertEqual(self.cycleTheme['cycle'][2]['bg'], theme.get('bg')) - + with unittest.mock.patch('core.output.sys.stdout'): core.event.trigger('update') self.assertEqual(self.cycleTheme['cycle'][0]['fg'], theme.get('fg')) @@ -108,6 +108,8 @@ class theme(unittest.TestCase): for i in range(0, len(expected)*3): self.assertEqual(expected[i%len(expected)], theme.get('fg', widget)) + self.assertEqual(expected[i%len(expected)], theme.get('fg', widget)) # ensure multiple invocations are OK + core.event.trigger('update') def test_state(self): widget = core.widget.Widget()