update all non-master listboxes when any listbox changes
[enigma2.git] / lib / python / Components / Converter / StringList.py
1 from Converter import Converter
2 from enigma import eListboxPythonStringContent
3 from Components.Element import cached
4
5 class StringList(Converter):
6         """Turns a simple python list into a list which can be used in a listbox."""
7         def __init__(self, type):
8                 Converter.__init__(self, type)
9                 self.content = None
10
11         def changed(self, what):
12                 if not self.content:
13                         self.content = eListboxPythonStringContent()
14
15                 if self.source:
16                         self.content.setList(self.source.list)
17                 self.downstream_elements.changed(what)
18
19         def selectionChanged(self, index):
20                 self.source.selectionChanged(index)
21
22         def setIndex(self, index):
23                 # update all non-master targets
24                 for x in self.downstream_elements:
25                         if x is not self.master:
26                                 x.index = index
27
28         def getIndex(self, index):
29                 return None
30         
31         index = property(getIndex, setIndex)
32
33         @cached
34         def getCurrent(self):
35                 if self.source is None or self.index is None or self.index >= len(self.source.list):
36                         return None
37                 return self.source.list[self.index]
38
39         current = property(getCurrent)
40
41         # pass through: getIndex / setIndex to master
42         @cached
43         def getIndex(self):
44                 if self.master is None:
45                         return None
46                 return self.master.index
47
48         def setIndex(self, index):
49                 if self.master is not None:
50                         self.master.index = index
51
52         index = property(getIndex, setIndex)
53
54         def entry_changed(self, index):
55                 self.downstream_elements.entry_changed(index)