4 def __init__(self, contexts = [ ], actions = { }, prio=0):
6 self.contexts = contexts
8 self.p = eActionMapPtr()
9 eActionMap.getInstance(self.p)
12 for ctx in self.contexts:
13 self.p.bindAction(ctx, self.prio, self.action)
16 for ctx in self.contexts:
17 self.p.unbindAction(ctx, self.action)
19 def action(self, context, action):
20 print " ".join(("action -> ", context, action))
21 if self.actions.has_key(action):
22 self.actions[action]()
25 print "unknown action %s/%s! typo in keymap?" % (context, action)
28 class NumberActionMap(ActionMap):
29 def action(self, contexts, action):
30 numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
31 if (action in numbers and self.actions.has_key(action)):
32 self.actions[action](int(action))
35 return ActionMap.action(self, contexts, action)
37 class HelpableActionMap(ActionMap):
38 """An Actionmap which automatically puts the actions into the helpList.
40 Note that you can only use ONE context here!"""
42 # sorry for this complicated code.
43 # it's not more than converting a "documented" actionmap
44 # (where the values are possibly (function, help)-tuples)
45 # into a "classic" actionmap, where values are just functions.
46 # the classic actionmap is then passed to the ActionMap constructor,
47 # the collected helpstrings (with correct context, action) is
48 # added to the screen's "helpList", which will be picked up by
49 # the "HelpableScreen".
50 def __init__(self, parent, context, actions = { }, prio=0):
53 for (action, funchelp) in actions.iteritems():
54 # check if this is a tuple
55 if type(funchelp) is type(()):
56 alist.append((action, funchelp[1]))
57 adict[action] = funchelp[0]
59 adict[action] = funchelp
61 ActionMap.__init__(self, [context], adict, prio)
63 parent.helpList.append((self, context, alist))