Merge branch 'master' into experimental
[enigma2.git] / lib / python / Components / MenuList.py
index 708757474af99034b9cefb72502e733fe314bd71..7fa1ae9776dbedce60814cdcda2ac5c6d1865644 100644 (file)
@@ -1,35 +1,39 @@
-from HTMLComponent import *
-from GUIComponent import *
+from HTMLComponent import HTMLComponent
+from GUIComponent import GUIComponent
 
 from enigma import eListboxPythonStringContent, eListbox
 
 class MenuList(HTMLComponent, GUIComponent):
-       def __init__(self, list, enableWrapAround=False):
+       def __init__(self, list, enableWrapAround=False, content=eListboxPythonStringContent):
                GUIComponent.__init__(self)
                self.list = list
-               self.l = eListboxPythonStringContent()
+               self.l = content()
                self.l.setList(self.list)
                self.onSelectionChanged = [ ]
                self.enableWrapAround = enableWrapAround
-       
+
        def getCurrent(self):
                return self.l.getCurrentSelection()
 
        GUI_WIDGET = eListbox
-       
+
        def postWidgetCreate(self, instance):
                instance.setContent(self.l)
                instance.selectionChanged.get().append(self.selectionChanged)
                if self.enableWrapAround:
                        self.instance.setWrapAround(True)
-       
+
        def preWidgetRemove(self, instance):
                instance.setContent(None)
+               instance.selectionChanged.get().remove(self.selectionChanged)
 
        def selectionChanged(self):
                for f in self.onSelectionChanged:
                        f()
 
+       def getSelectionIndex(self):
+               return self.l.getCurrentSelectionIndex()
+
        def getSelectedIndex(self):
                return self.l.getCurrentSelectionIndex()
 
@@ -38,24 +42,25 @@ class MenuList(HTMLComponent, GUIComponent):
                self.l.setList(self.list)
 
        def moveToIndex(self, idx):
-               self.instance.moveSelectionTo(idx)
+               if self.instance is not None:
+                       self.instance.moveSelectionTo(idx)
 
        def pageUp(self):
                if self.instance is not None:
                        self.instance.moveSelection(self.instance.pageUp)
-               
+
        def pageDown(self):
                if self.instance is not None:
                        self.instance.moveSelection(self.instance.pageDown)
-                       
+
        def up(self):
                if self.instance is not None:
                        self.instance.moveSelection(self.instance.moveUp)
-               
+
        def down(self):
                if self.instance is not None:
                        self.instance.moveSelection(self.instance.moveDown)
-                       
+
        def selectionEnabled(self, enabled):
                if self.instance is not None:
                        self.instance.setSelectionEnable(enabled)