Support turbo2.
[vuplus_dvbapp] / lib / python / Components / SelectionList.py
1 from MenuList import MenuList
2 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
3 from enigma import eListboxPythonMultiContent, eListbox, gFont, RT_HALIGN_LEFT
4 from Tools.LoadPixmap import LoadPixmap
5 import skin
6
7 selectionpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/selectioncross.png"))
8
9 def SelectionEntryComponent(description, value, index, selected):
10         res = [
11                 (description, value, index, selected),
12                 (eListboxPythonMultiContent.TYPE_TEXT, 30, 3, 500, 30, 0, RT_HALIGN_LEFT, description)
13         ]
14         if selected:
15                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 0, 0, 30, 30, selectionpng))
16         return res
17
18 class SelectionList(MenuList):
19         def __init__(self, list = None, enableWrapAround = False):
20                 MenuList.__init__(self, list or [], enableWrapAround, content = eListboxPythonMultiContent)
21                 font = skin.fonts.get("SelectionList", ("Regular", 20, 30))
22                 self.l.setFont(0, gFont(font[0], font[1]))
23                 self.l.setItemHeight(font[2])
24
25         def addSelection(self, description, value, index, selected = True):
26                 self.list.append(SelectionEntryComponent(description, value, index, selected))
27                 self.setList(self.list)
28
29         def toggleSelection(self):
30                 idx = self.getSelectedIndex()
31                 item = self.list[idx][0]
32                 self.list[idx] = SelectionEntryComponent(item[0], item[1], item[2], not item[3])
33                 self.setList(self.list)
34
35         def getSelectionsList(self):
36                 return [ (item[0][0], item[0][1], item[0][2]) for item in self.list if item[0][3] ]
37