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):
11 p = enigma.eActionMap.getInstance()
14 source = open(filename)
17 dom = xml.dom.minidom.parse(source)
19 raise "keymap %s not well-formed." % filename
21 keymap = dom.childNodes[0]
23 maps = elementsWithTag(keymap.childNodes, "map")
26 context = str(cmap.getAttribute("context"))
27 assert context != "", "map must have context"
29 def parseKeys(device, keys):
30 for x in elementsWithTag(keys.childNodes, "key"):
31 mapto = str(x.getAttribute("mapto"))
32 id = x.getAttribute("id")
33 flags = x.getAttribute("flags")
35 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x]
38 flags = sum(map(flag_ascii_to_id, flags))
39 # print "-> " + str(flags)
41 # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id))
43 assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
44 assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
45 assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
48 keyid = ord(id) | 0x8000
51 keyid = int(id[2:], 0x10) | 0x8000
53 keyid = int(id[2:]) | 0x8000
55 raise "key id '" + str(id) + "' is neither hex nor dec"
60 raise "key id '" + str(id) + "' is illegal"
62 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
63 p.bindKey(filename, device, keyid, flags, context, mapto)
64 addKeyBinding(filename, keyid, context, mapto, flags)
66 parseKeys("generic", cmap)
68 for device in elementsWithTag(cmap.childNodes, "device"):
69 parseKeys(str(device.getAttribute("name")), device)
71 def removeKeymap(filename):
72 p = enigma.eActionMap.getInstance()
73 p.unbindKeyDomain(filename)