fix and simplify PluginList
[enigma2.git] / lib / python / Components / MenuList.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3
4 from enigma import eListboxPythonStringContent, eListbox
5
6 class MenuList(HTMLComponent, GUIComponent):
7         def __init__(self, list, enableWrapAround=False, content=eListboxPythonStringContent()):
8                 GUIComponent.__init__(self)
9                 self.list = list
10                 self.l = content
11                 self.l.setList(self.list)
12                 self.onSelectionChanged = [ ]
13                 self.enableWrapAround = enableWrapAround
14
15         def getCurrent(self):
16                 return self.l.getCurrentSelection()
17
18         GUI_WIDGET = eListbox
19
20         def postWidgetCreate(self, instance):
21                 instance.setContent(self.l)
22                 instance.selectionChanged.get().append(self.selectionChanged)
23                 if self.enableWrapAround:
24                         self.instance.setWrapAround(True)
25
26         def preWidgetRemove(self, instance):
27                 instance.setContent(None)
28                 instance.selectionChanged.get().remove(self.selectionChanged)
29
30         def selectionChanged(self):
31                 for f in self.onSelectionChanged:
32                         f()
33
34         def getSelectedIndex(self):
35                 return self.l.getCurrentSelectionIndex()
36
37         def setList(self, list):
38                 self.list = list
39                 self.l.setList(self.list)
40
41         def moveToIndex(self, idx):
42                 if self.instance is not None:
43                         self.instance.moveSelectionTo(idx)
44
45         def pageUp(self):
46                 if self.instance is not None:
47                         self.instance.moveSelection(self.instance.pageUp)
48
49         def pageDown(self):
50                 if self.instance is not None:
51                         self.instance.moveSelection(self.instance.pageDown)
52
53         def up(self):
54                 if self.instance is not None:
55                         self.instance.moveSelection(self.instance.moveUp)
56
57         def down(self):
58                 if self.instance is not None:
59                         self.instance.moveSelection(self.instance.moveDown)
60
61         def selectionEnabled(self, enabled):
62                 if self.instance is not None:
63                         self.instance.setSelectionEnable(enabled)