2 import xml.etree.cElementTree
4 from keyids import KEYIDS
6 # these are only informational (for help)...
7 from Tools.KeyBindings import addKeyBinding
9 class KeymapError(Exception):
10 def __init__(self, message):
16 def parseKeys(context, filename, actionmap, device, keys):
17 for x in keys.findall("key"):
18 get_attr = x.attrib.get
19 mapto = get_attr("mapto")
21 flags = get_attr("flags")
23 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x]
25 flags = sum(map(flag_ascii_to_id, flags))
27 assert mapto, "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
28 assert id, "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
29 assert flags, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
32 keyid = ord(id) | 0x8000
35 keyid = int(id[2:], 0x10) | 0x8000
37 keyid = int(id[2:]) | 0x8000
39 raise KeymapError("key id '" + str(id) + "' is neither hex nor dec")
44 raise KeymapError("key id '" + str(id) + "' is illegal")
45 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
46 actionmap.bindKey(filename, device, keyid, flags, context, mapto)
47 addKeyBinding(filename, keyid, context, mapto, flags)
49 def readKeymap(filename):
50 p = enigma.eActionMap.getInstance()
53 source = open(filename)
56 dom = xml.etree.cElementTree.parse(source)
58 raise KeymapError("keymap %s not well-formed." % filename)
60 keymap = dom.getroot()
62 for cmap in keymap.findall("map"):
63 context = cmap.attrib.get("context")
64 assert context, "map must have context"
66 for device in cmap.findall("device"):
67 parseKeys(context, filename, p, device.attrib.get("name"), device)
69 parseKeys(context, filename, p, "generic", cmap)
71 def removeKeymap(filename):
72 p = enigma.eActionMap.getInstance()
73 p.unbindKeyDomain(filename)