5d02e9bad269178c07dd374c77b8b54d23a075a1
[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                 # update all non-master targets
22                 for x in self.downstream_elements:
23                         if x is not self.master:
24                                 x.index = index
25
26         @cached
27         def getCurrent(self):
28                 if self.source is None or self.index >= len(self.source.list):
29                         return None
30                 return self.source.list[self.index]
31
32         current = property(getCurrent)
33
34         # pass through: getIndex / setIndex to master
35         @cached
36         def getIndex(self):
37                 if self.master is None:
38                         return None
39                 return self.master.index
40
41         def setIndex(self, index):
42                 if self.master is not None:
43                         self.master.index = index
44
45         index = property(getIndex, setIndex)