remove unneeded del...
[enigma2.git] / lib / python / Components / HelpMenuList.py
1 from GUIComponent import GUIComponent
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                                 # 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                                 print "name:", name
40
41                                 entry.append( (actionmap, context, action, name ) )
42                                 entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 400, 28, 0, 0, help) )
43
44                                 l.append(entry)
45
46                 self.l.setList(l)
47
48                 self.l.setFont(0, gFont("Regular", 24))
49                 self.l.setItemHeight(38)
50
51         def ok(self):
52                 # a list entry has a "private" tuple as first entry...
53                 l = self.getCurrent()
54                 if l is None:
55                         return
56                 # ...containing (Actionmap, Context, Action, keydata).
57                 # we returns this tuple to the callback.
58                 self.callback(l[0], l[1], l[2])
59
60         def getCurrent(self):
61                 sel = self.l.getCurrentSelection()
62                 return sel and sel[0]
63
64         GUI_WIDGET = eListbox
65
66         def postWidgetCreate(self, instance):
67                 instance.setContent(self.l)
68                 instance.selectionChanged.get().append(self.selectionChanged)
69
70         def preWidgetRemove(self, instance):
71                 instance.setContent(None)
72                 instance.selectionChanged.get().remove(self.selectionChanged)
73
74         def selectionChanged(self):
75                 for x in self.onSelChanged:
76                         x()