return None (instead of crash) when list is empty, and getCurrent is called
[enigma2.git] / lib / python / Components / Converter / StringList.py
index ed2646519978415b1b14e02bdcd45f53ebe3781c..5d02e9bad269178c07dd374c77b8b54d23a075a1 100644 (file)
@@ -1,14 +1,17 @@
 from Converter import Converter
 from enigma import eListboxPythonStringContent
-
+from Components.Element import cached
 
 class StringList(Converter):
        """Turns a simple python list into a list which can be used in a listbox."""
        def __init__(self, type):
                Converter.__init__(self, type)
+               self.content = None
 
        def changed(self, what):
-               self.content = eListboxPythonStringContent()
+               if not self.content:
+                       self.content = eListboxPythonStringContent()
+
                if self.source:
                        self.content.setList(self.source.list)
                self.downstream_elements.changed(what)
@@ -20,14 +23,16 @@ class StringList(Converter):
                        if x is not self.master:
                                x.index = index
 
+       @cached
        def getCurrent(self):
-               if self.source is None:
+               if self.source is None or self.index >= len(self.source.list):
                        return None
                return self.source.list[self.index]
 
        current = property(getCurrent)
 
        # pass through: getIndex / setIndex to master
+       @cached
        def getIndex(self):
                if self.master is None:
                        return None
@@ -36,5 +41,5 @@ class StringList(Converter):
        def setIndex(self, index):
                if self.master is not None:
                        self.master.index = index
-       
+
        index = property(getIndex, setIndex)