4 from keyids import KEYIDS;
6 # these are only informational (for help)...
7 from Tools.KeyBindings import addKeyBinding
11 p = enigma.eActionMapPtr()
12 enigma.eActionMap.getInstance(p)
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."
32 keymap = dom.getElementsByTagName("keymap")[0]
34 raise "no keymap defined."
36 maps = keymap.getElementsByTagName("map")
39 context = str(cmap.getAttribute("context"))
40 assert context != "", "map must have context"
42 def parseKeys(device, keys):
43 for x in keys.getElementsByTagName("key"):
44 mapto = str(x.getAttribute("mapto"))
45 id = x.getAttribute("id")
46 flags = x.getAttribute("flags")
48 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4}[x]
51 flags = sum(map(flag_ascii_to_id, flags))
52 # print "-> " + str(flags)
54 # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id))
56 assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
57 assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
58 assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
61 keyid = ord(id) | 0x8000
64 keyid = int(id[2:], 0x10) | 0x8000
66 keyid = int(id[2:]) | 0x8000
68 raise "key id '" + str(id) + "' is neither hex nor dec"
73 raise "key id '" + str(id) + "' is illegal"
75 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
76 p.bindKey(device, keyid, flags, context, mapto)
77 addKeyBinding(keyid, context, mapto)
79 parseKeys("generic", cmap)
81 for device in cmap.getElementsByTagName("device"):
82 parseKeys(str(device.getAttribute("name")), device)