3 from Tools.XMLTools import elementsWithTag
5 from keyids import KEYIDS;
7 # these are only informational (for help)...
8 from Tools.KeyBindings import addKeyBinding
10 def readKeymap(filename = "/usr/share/enigma2/keymap.xml"):
12 p = enigma.eActionMap.getInstance()
15 source = open(filename)
18 dom = xml.dom.minidom.parse(source)
20 raise "keymap %s not well-formed." % filename
22 keymap = dom.childNodes[0]
24 maps = elementsWithTag(keymap.childNodes, "map")
27 context = str(cmap.getAttribute("context"))
28 assert context != "", "map must have context"
30 def parseKeys(device, keys):
31 for x in elementsWithTag(keys.childNodes, "key"):
32 mapto = str(x.getAttribute("mapto"))
33 id = x.getAttribute("id")
34 flags = x.getAttribute("flags")
36 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x]
39 flags = sum(map(flag_ascii_to_id, flags))
40 # print "-> " + str(flags)
42 # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id))
44 assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
45 assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
46 assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
49 keyid = ord(id) | 0x8000
52 keyid = int(id[2:], 0x10) | 0x8000
54 keyid = int(id[2:]) | 0x8000
56 raise "key id '" + str(id) + "' is neither hex nor dec"
61 raise "key id '" + str(id) + "' is illegal"
63 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
64 p.bindKey(filename, device, keyid, flags, context, mapto)
65 addKeyBinding(filename, keyid, context, mapto)
67 parseKeys("generic", cmap)
69 for device in elementsWithTag(cmap.childNodes, "device"):
70 parseKeys(str(device.getAttribute("name")), device)
72 def removeKeymap(filename):
73 p = enigma.eActionMap.getInstance()
74 p.unbindKeyDomain(filename)