[core/theme] Improve items that are lists
Until now, using a list as prefix/suffix didn't work as expected, because the corresponding method for retrieving the value was called multiple times, and each time, the next icon would be retrieved. Changed the logic inside the theme to only update the indices every time that an actual update was happening.
This commit is contained in:
parent
4b402438cc
commit
4cd6444bbf
2 changed files with 10 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue