4 def __init__(self, contexts = [ ], actions = { }, prio=0):
6 self.contexts = contexts
8 self.p = eActionMapPtr()
10 self.exec_active = False
12 eActionMap.getInstance(self.p)
14 def setEnabled(self, enabled):
15 self.enabled = enabled
20 for ctx in self.contexts:
21 self.p.bindAction(ctx, self.prio, self.action)
26 for ctx in self.contexts:
27 self.p.unbindAction(ctx, self.action)
31 if self.exec_active and self.enabled:
37 self.exec_active = True
41 self.exec_active = False
44 def action(self, context, action):
45 print " ".join(("action -> ", context, action))
46 if self.actions.has_key(action):
47 self.actions[action]()
50 print "unknown action %s/%s! typo in keymap?" % (context, action)
56 class NumberActionMap(ActionMap):
57 def action(self, contexts, action):
58 numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
59 if (action in numbers and self.actions.has_key(action)):
60 self.actions[action](int(action))
63 return ActionMap.action(self, contexts, action)
65 class HelpableActionMap(ActionMap):
66 """An Actionmap which automatically puts the actions into the helpList.
68 Note that you can only use ONE context here!"""
70 # sorry for this complicated code.
71 # it's not more than converting a "documented" actionmap
72 # (where the values are possibly (function, help)-tuples)
73 # into a "classic" actionmap, where values are just functions.
74 # the classic actionmap is then passed to the ActionMap constructor,
75 # the collected helpstrings (with correct context, action) is
76 # added to the screen's "helpList", which will be picked up by
77 # the "HelpableScreen".
78 def __init__(self, parent, context, actions = { }, prio=0):
81 for (action, funchelp) in actions.iteritems():
82 # check if this is a tuple
83 if type(funchelp) is type(()):
84 alist.append((action, funchelp[1]))
85 adict[action] = funchelp[0]
87 adict[action] = funchelp
89 ActionMap.__init__(self, [context], adict, prio)
91 parent.helpList.append((self, context, alist))