2 import xml.etree.cElementTree
4 from keyids import KEYIDS;
6 # these are only informational (for help)...
7 from Tools.KeyBindings import addKeyBinding
9 def parseKeys(context, filename, actionmap, device, keys):
10 for x in keys.findall("key"):
11 get_attr = x.attrib.get
12 mapto = get_attr("mapto")
14 flags = get_attr("flags")
16 flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x]
18 flags = sum(map(flag_ascii_to_id, flags))
20 assert mapto, "%s: must specify mapto in context %s, id '%s'" % (filename, context, id)
21 assert id, "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto)
22 assert flags, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id)
25 keyid = ord(id) | 0x8000
28 keyid = int(id[2:], 0x10) | 0x8000
30 keyid = int(id[2:]) | 0x8000
32 raise "key id '" + str(id) + "' is neither hex nor dec"
37 raise "key id '" + str(id) + "' is illegal"
38 # print context + "::" + mapto + " -> " + device + "." + hex(keyid)
39 actionmap.bindKey(filename, device, keyid, flags, context, mapto)
40 addKeyBinding(filename, keyid, context, mapto, flags)
42 def readKeymap(filename):
43 p = enigma.eActionMap.getInstance()
46 source = open(filename)
49 dom = xml.etree.cElementTree.parse(source)
51 raise "keymap %s not well-formed." % filename
53 keymap = dom.getroot()
55 for cmap in keymap.findall("map"):
56 context = cmap.attrib.get("context")
57 assert context, "map must have context"
59 for device in cmap.findall("device"):
60 parseKeys(context, filename, p, device.attrib.get("name"), device)
62 parseKeys(context, filename, p, "generic", cmap)
64 def removeKeymap(filename):
65 p = enigma.eActionMap.getInstance()
66 p.unbindKeyDomain(filename)