4 from keyids import KEYIDS;
8 p = enigma.eActionMapPtr()
9 enigma.eActionMap.getInstance(p)
12 filename = "keymap.xml"
15 source = open(filename)
17 raise "couldn't open keymap.xml!"
20 dom = xml.dom.minidom.parse(source)
22 raise "keymap not well-formed."
25 keymap = dom.getElementsByTagName("keymap")[0]
27 raise "no keymap defined."
29 maps = keymap.getElementsByTagName("map")
32 context = str(cmap.getAttribute("context"))
33 assert context != "", "map must have context"
35 def parseKeys(device, keys):
36 for x in keys.getElementsByTagName("key"):
37 mapto = str(x.getAttribute("mapto"))
38 id = x.getAttribute("id")
39 flags = x.getAttribute("flags")
41 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4}[x]
44 flags = sum(map(flag_ascii_to_id, flags))
45 print "-> " + str(flags)
47 # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id))
49 assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
50 assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
51 assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
54 keyid = ord(id) | 0x8000
57 keyid = int(id[2:], 0x10) | 0x8000
59 keyid = int(id[2:]) | 0x8000
61 raise "key id '" + str(id) + "' is neither hex nor dec"
66 raise "key id '" + str(id) + "' is illegal"
68 print context + "::" + mapto + " -> " + device + "." + hex(keyid)
69 p.bindKey(device, keyid, flags, context, mapto)
71 parseKeys("generic", cmap)
73 for device in cmap.getElementsByTagName("device"):
74 parseKeys(str(device.getAttribute("name")), device)