4 from keyids import KEYIDS;
8 p = enigma.eActionMapPtr()
9 enigma.eActionMap.getInstance(p)
12 filename1 = "data/keymap.xml"
13 filename2 = "/usr/share/enigma2/keymap.xml"
16 source = open(filename1)
18 source = open(filename2)
19 # raise "couldn't open keymap.xml!"
22 dom = xml.dom.minidom.parse(source)
24 raise "keymap not well-formed."
27 keymap = dom.getElementsByTagName("keymap")[0]
29 raise "no keymap defined."
31 maps = keymap.getElementsByTagName("map")
34 context = str(cmap.getAttribute("context"))
35 assert context != "", "map must have context"
37 def parseKeys(device, keys):
38 for x in keys.getElementsByTagName("key"):
39 mapto = str(x.getAttribute("mapto"))
40 id = x.getAttribute("id")
41 flags = x.getAttribute("flags")
43 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4}[x]
46 flags = sum(map(flag_ascii_to_id, flags))
47 # print "-> " + str(flags)
49 # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id))
51 assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
52 assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
53 assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
56 keyid = ord(id) | 0x8000
59 keyid = int(id[2:], 0x10) | 0x8000
61 keyid = int(id[2:]) | 0x8000
63 raise "key id '" + str(id) + "' is neither hex nor dec"
68 raise "key id '" + str(id) + "' is illegal"
70 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
71 p.bindKey(device, keyid, flags, context, mapto)
73 parseKeys("generic", cmap)
75 for device in cmap.getElementsByTagName("device"):
76 parseKeys(str(device.getAttribute("name")), device)