1 from enigma import eActionMap
4 def __init__(self, contexts = [ ], actions = { }, prio=0):
6 self.contexts = contexts
8 self.p = eActionMap.getInstance()
10 self.exec_active = False
13 def setEnabled(self, enabled):
14 self.enabled = enabled
19 for ctx in self.contexts:
20 self.p.bindAction(ctx, self.prio, self.action)
25 for ctx in self.contexts:
26 self.p.unbindAction(ctx, self.action)
30 if self.exec_active and self.enabled:
36 self.exec_active = True
40 self.exec_active = False
43 def action(self, context, action):
44 print " ".join(("action -> ", context, action))
45 if self.actions.has_key(action):
46 res = self.actions[action]()
51 print "unknown action %s/%s! typo in keymap?" % (context, action)
57 class NumberActionMap(ActionMap):
58 def action(self, contexts, action):
59 numbers = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
60 if (action in numbers and self.actions.has_key(action)):
61 res = self.actions[action](int(action))
66 return ActionMap.action(self, contexts, action)
68 class HelpableActionMap(ActionMap):
69 """An Actionmap which automatically puts the actions into the helpList.
71 Note that you can only use ONE context here!"""
73 # sorry for this complicated code.
74 # it's not more than converting a "documented" actionmap
75 # (where the values are possibly (function, help)-tuples)
76 # into a "classic" actionmap, where values are just functions.
77 # the classic actionmap is then passed to the ActionMap constructor,
78 # the collected helpstrings (with correct context, action) is
79 # added to the screen's "helpList", which will be picked up by
80 # the "HelpableScreen".
81 def __init__(self, parent, context, actions = { }, prio=0):
84 for (action, funchelp) in actions.iteritems():
85 # check if this is a tuple
86 if isinstance(funchelp, tuple):
87 alist.append((action, funchelp[1]))
88 adict[action] = funchelp[0]
90 adict[action] = funchelp
92 ActionMap.__init__(self, [context], adict, prio)
94 parent.helpList.append((self, context, alist))