3 from Tools.XMLTools import elementsWithTag
5 from keyids import KEYIDS;
7 # these are only informational (for help)...
8 from Tools.KeyBindings import addKeyBinding
12 p = enigma.eActionMap.getInstance()
15 filename1 = "data/keymap.xml"
16 filename2 = "/usr/share/enigma2/keymap.xml"
19 source = open(filename1)
22 source = open(filename2)
24 # raise "couldn't open keymap.xml!"
27 dom = xml.dom.minidom.parse(source)
29 raise "keymap not well-formed."
31 keymap = dom.childNodes[0]
33 maps = elementsWithTag(keymap.childNodes, "map")
36 context = str(cmap.getAttribute("context"))
37 assert context != "", "map must have context"
39 def parseKeys(device, keys):
40 for x in elementsWithTag(keys.childNodes, "key"):
41 mapto = str(x.getAttribute("mapto"))
42 id = x.getAttribute("id")
43 flags = x.getAttribute("flags")
45 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4}[x]
48 flags = sum(map(flag_ascii_to_id, flags))
49 # print "-> " + str(flags)
51 # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id))
53 assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
54 assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
55 assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
58 keyid = ord(id) | 0x8000
61 keyid = int(id[2:], 0x10) | 0x8000
63 keyid = int(id[2:]) | 0x8000
65 raise "key id '" + str(id) + "' is neither hex nor dec"
70 raise "key id '" + str(id) + "' is illegal"
72 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
73 p.bindKey(device, keyid, flags, context, mapto)
74 addKeyBinding(keyid, context, mapto)
76 parseKeys("generic", cmap)
78 for device in elementsWithTag(cmap.childNodes, "device"):
79 parseKeys(str(device.getAttribute("name")), device)