Merge branch 'master' of /home/tmbinc/enigma2-git into tmbinc/FixTimingBugs
[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                 print "changed selection in listbox!"
25                 for x in self.downstream_elements:
26                         print "downstream element", x
27                         if x is not self.master:
28                                 print "is not master, so update to index", index
29                                 x.index = index
30
31         def getIndex(self, index):
32                 return None
33         
34         index = property(getIndex, setIndex)
35
36         @cached
37         def getCurrent(self):
38                 if self.source is None or self.index is None or self.index >= len(self.source.list):
39                         return None
40                 return self.source.list[self.index]
41
42         current = property(getCurrent)
43
44         # pass through: getIndex / setIndex to master
45         @cached
46         def getIndex(self):
47                 if self.master is None:
48                         return None
49                 return self.master.index
50
51         def setIndex(self, index):
52                 if self.master is not None:
53                         self.master.index = index
54
55         index = property(getIndex, setIndex)
56
57         def entry_changed(self, index):
58                 self.downstream_elements.entry_changed(index)