0cd2fd2f6f516b692a9dbcb22653400cbf861688
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / HelpMenuList.py
1 from GUIComponent import *
2
3 from enigma import eListboxPythonMultiContent, eListbox, gFont
4
5 from Tools.KeyBindings import queryKeyBinding, getKeyDescription
6 #getKeyPositions
7
8 # [ ( actionmap, context, [(action, help), (action, help), ...] ), (actionmap, ... ), ... ]
9
10 class HelpMenuList(GUIComponent):
11         def __init__(self, list, callback):
12                 GUIComponent.__init__(self)
13                 self.onSelChanged = [ ]
14                 self.l = eListboxPythonMultiContent()
15                 self.callback = callback
16
17                 l = [ ]
18                 for (actionmap, context, actions) in list:
19                         for (action, help) in actions:
20                                 entry = [ ]
21
22                                 buttons = queryKeyBinding(context, action)
23
24                                 name = None
25
26                                 for n in buttons:
27                                         name = getKeyDescription(n)
28                                         if name is not None:
29                                                 break
30
31                                 entry.append( (actionmap, context, action, name ) )
32                                 entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 400, 28, 0, 0, help) )
33
34                                 l.append(entry)
35
36                 self.l.setList(l)
37
38                 self.l.setFont(0, gFont("Regular", 26))
39                 self.l.setItemHeight(42)
40
41         def ok(self):
42                 # a list entry has a "private" tuple as first entry...
43                 l = self.getCurrent()
44                 if l is None:
45                         return
46                 # ...containing (Actionmap, Context, Action, keydata).
47                 # we returns this tuple to the callback.
48                 self.callback(l[0], l[1], l[2])
49
50         def getCurrent(self):
51                 sel = self.l.getCurrentSelection()
52                 return sel and sel[0]
53
54         GUI_WIDGET = eListbox
55
56         def postWidgetCreate(self, instance):
57                 instance.setContent(self.l)
58
59                 instance.selectionChanged.get().append(self.selectionChanged)
60
61         def selectionChanged(self):
62                 for x in self.onSelChanged:
63                         x()