Merge branch 'bug_570_playback_skip_fixes_and_cleanup_ml_aholst' into experimental
[enigma2.git] / lib / python / Components / HelpMenuList.py
1 from GUIComponent import GUIComponent
2
3 from enigma import eListboxPythonMultiContent, eListbox, gFont
4 from Tools.KeyBindings import queryKeyBinding, getKeyDescription
5 #getKeyPositions
6
7 # [ ( actionmap, context, [(action, help), (action, help), ...] ), (actionmap, ... ), ... ]
8
9 class HelpMenuList(GUIComponent):
10         def __init__(self, helplist, callback):
11                 GUIComponent.__init__(self)
12                 self.onSelChanged = [ ]
13                 self.l = eListboxPythonMultiContent()
14                 self.callback = callback
15                 self.extendedHelp = False
16
17                 l = [ ]
18                 for (actionmap, context, actions) in helplist:
19                         for (action, help) in actions:
20                                 buttons = queryKeyBinding(context, action)
21
22                                 # do not display entries which are not accessible from keys
23                                 if not len(buttons):
24                                         continue
25
26                                 name = None
27                                 flags = 0
28
29                                 for n in buttons:
30                                         (name, flags) = (getKeyDescription(n[0]), n[1])
31                                         if name is not None:
32                                                 break
33
34                                 if flags & 8: # for long keypresses, prepend l_ into the key name.
35                                         name = (name[0], "long")
36                                         
37                                 entry = [ (actionmap, context, action, name ) ]
38
39                                 if isinstance(help, list):
40                                         self.extendedHelp = True
41                                         print "extendedHelpEntry found"
42                                         entry.extend((
43                                                 (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 400, 26, 0, 0, help[0]),
44                                                 (eListboxPythonMultiContent.TYPE_TEXT, 0, 28, 400, 20, 1, 0, help[1])
45                                         ))
46                                 else:
47                                         entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 400, 28, 0, 0, help) )
48                                         
49                                 l.append(entry)
50
51                 self.l.setList(l)
52                 if self.extendedHelp is True:
53                         self.l.setFont(0, gFont("Regular", 24))
54                         self.l.setFont(1, gFont("Regular", 18))
55                         self.l.setItemHeight(50)
56                 else:
57                         self.l.setFont(0, gFont("Regular", 24))
58                         self.l.setItemHeight(38)
59
60         def ok(self):
61                 # a list entry has a "private" tuple as first entry...
62                 l = self.getCurrent()
63                 if l is None:
64                         return
65                 # ...containing (Actionmap, Context, Action, keydata).
66                 # we returns this tuple to the callback.
67                 self.callback(l[0], l[1], l[2])
68
69         def getCurrent(self):
70                 sel = self.l.getCurrentSelection()
71                 return sel and sel[0]
72
73         GUI_WIDGET = eListbox
74
75         def postWidgetCreate(self, instance):
76                 instance.setContent(self.l)
77                 instance.selectionChanged.get().append(self.selectionChanged)
78
79         def preWidgetRemove(self, instance):
80                 instance.setContent(None)
81                 instance.selectionChanged.get().remove(self.selectionChanged)
82
83         def selectionChanged(self):
84                 for x in self.onSelChanged:
85                         x()