X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/3af66122574386a2856e83ba9c5d73d27a6f3710..040a8d3881183823ac69b86b5549ab8c22707b7e:/keymapparser.py?ds=sidebyside diff --git a/keymapparser.py b/keymapparser.py index 032805b3..7131276f 100644 --- a/keymapparser.py +++ b/keymapparser.py @@ -1,55 +1,49 @@ import xml.dom.minidom import enigma +from Tools.XMLTools import elementsWithTag from keyids import KEYIDS; -def readKeymap(): +# these are only informational (for help)... +from Tools.KeyBindings import addKeyBinding - p = enigma.eActionMapPtr() - enigma.eActionMap.getInstance(p) +def readKeymap(filename): + p = enigma.eActionMap.getInstance() assert p - - filename = "keymap.xml" - - try: - source = open(filename) - except: - raise "couldn't open keymap.xml!" - + + source = open(filename) + try: dom = xml.dom.minidom.parse(source) except: - raise "keymap not well-formed." - - try: - keymap = dom.getElementsByTagName("keymap")[0] - except: - raise "no keymap defined." - - maps = keymap.getElementsByTagName("map") - + raise "keymap %s not well-formed." % filename + + keymap = dom.childNodes[0] + + maps = elementsWithTag(keymap.childNodes, "map") + for cmap in maps: context = str(cmap.getAttribute("context")) assert context != "", "map must have context" - + def parseKeys(device, keys): - for x in keys.getElementsByTagName("key"): + for x in elementsWithTag(keys.childNodes, "key"): mapto = str(x.getAttribute("mapto")) id = x.getAttribute("id") flags = x.getAttribute("flags") - - flag_ascii_to_id = lambda x: {'m':1,'r':2,'b':4}[x] - + + flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x] + # try: flags = sum(map(flag_ascii_to_id, flags)) - print "-> " + str(flags) +# print "-> " + str(flags) # except: # raise str("%s: illegal flags '%s' specificed in context %s, id '%s'" % (filename, flags, context, id)) - + assert mapto != "", "%s: must specify mapto in context %s, id '%s'" % (filename, context, id) assert id != "", "%s: must specify id in context %s, mapto '%s'" % (filename, context, mapto) assert flags != 0, "%s: must specify at least one flag in context %s, id '%s'" % (filename, context, id) - + if len(id) == 1: keyid = ord(id) | 0x8000 elif id[0] == '\\': @@ -65,11 +59,15 @@ def readKeymap(): except: raise "key id '" + str(id) + "' is illegal" - print context + "::" + mapto + " -> " + device + "." + hex(keyid) - p.bindKey(device, keyid, 7, context, mapto) - - parseKeys("generic", cmap) - - for device in cmap.getElementsByTagName("device"): +# print context + "::" + mapto + " -> " + device + "." + hex(keyid) + p.bindKey(filename, device, keyid, flags, context, mapto) + addKeyBinding(filename, keyid, context, mapto, flags) + + for device in elementsWithTag(cmap.childNodes, "device"): parseKeys(str(device.getAttribute("name")), device) + parseKeys("generic", cmap) + +def removeKeymap(filename): + p = enigma.eActionMap.getInstance() + p.unbindKeyDomain(filename)