Merge branch 'master' into dvd_scale_test
[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, list, 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 list:
19                         for (action, help) in actions:
20                                 entry = [ ]
21
22                                 buttons = queryKeyBinding(context, action)
23
24                                 # do not display entries which are not accessible from keys
25                                 if not len(buttons):
26                                         continue
27
28                                 name = None
29                                 flags = 0
30
31                                 for n in buttons:
32                                         (name, flags) = (getKeyDescription(n[0]), n[1])
33                                         if name is not None:
34                                                 break
35
36                                 if flags & 8: # for long keypresses, prepend l_ into the key name.
37                                         name = (name[0], "long")
38                                         
39                                 entry.append( (actionmap, context, action, name ) )
40                                         
41                                 if type(help).__name__== 'list':
42                                         self.extendedHelp = True
43                                         print "extendedHelpEntry found"
44                                         entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 400, 26, 0, 0, help[0]) )
45                                         entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 28, 400, 20, 1, 0, help[1]) )
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()