add FATAL: before error messages
[enigma2.git] / keymapparser.py
index f8aa07f..7131276 100644 (file)
@@ -7,53 +7,43 @@ from keyids import KEYIDS;
 # these are only informational (for help)...
 from Tools.KeyBindings import addKeyBinding
 
-def readKeymap():
-
+def readKeymap(filename):
        p = enigma.eActionMap.getInstance()
        assert p
-       
-       filename1 = "data/keymap.xml"
-       filename2 = "/usr/share/enigma2/keymap.xml"
-               
-       try:
-               source = open(filename1)
-               filename = filename1
-       except:
-               source = open(filename2)
-               filename = filename2
-#              raise "couldn't open keymap.xml!"
-       
+
+       source = open(filename)
+
        try:
                dom = xml.dom.minidom.parse(source)
        except:
-               raise "keymap not well-formed."
-       
+               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 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,'b':2,'r':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)
 #                              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] == '\\':
@@ -70,11 +60,14 @@ def readKeymap():
                                                raise "key id '" + str(id) + "' is illegal"
 
 #                              print context + "::" + mapto + " -> " + device + "." + hex(keyid)
-                               p.bindKey(device, keyid, flags, context, mapto)
-                               addKeyBinding(keyid, context, mapto)
-               
-               parseKeys("generic", cmap)
-               
+                               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)