actualize pot file
[enigma2.git] / keymapparser.py
index c7bbce1..f8aa07f 100644 (file)
@@ -1,39 +1,43 @@
 import xml.dom.minidom
 import enigma
+from Tools.XMLTools import elementsWithTag
 
 from keyids import KEYIDS;
 
+# these are only informational (for help)...
+from Tools.KeyBindings import addKeyBinding
+
 def readKeymap():
 
-       p = enigma.eActionMapPtr()
-       enigma.eActionMap.getInstance(p)
+       p = enigma.eActionMap.getInstance()
        assert p
        
-       filename = "keymap.xml"
-       
+       filename1 = "data/keymap.xml"
+       filename2 = "/usr/share/enigma2/keymap.xml"
+               
        try:
-               source = open(filename)
+               source = open(filename1)
+               filename = filename1
        except:
-               raise "couldn't open keymap.xml!"
+               source = open(filename2)
+               filename = filename2
+#              raise "couldn't open keymap.xml!"
        
        try:
                dom = xml.dom.minidom.parse(source)
        except:
                raise "keymap not well-formed."
        
-       try:    
-               keymap = dom.getElementsByTagName("keymap")[0]
-       except:
-               raise "no keymap defined."
+       keymap = dom.childNodes[0]
        
-       maps = keymap.getElementsByTagName("map")
+       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")
@@ -42,7 +46,7 @@ def readKeymap():
                                
 #                              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))
                                
@@ -65,11 +69,12 @@ def readKeymap():
                                        except:
                                                raise "key id '" + str(id) + "' is illegal"
 
-                               print context + "::" + mapto + " -> " + device + "." + hex(keyid)
+#                              print context + "::" + mapto + " -> " + device + "." + hex(keyid)
                                p.bindKey(device, keyid, flags, context, mapto)
+                               addKeyBinding(keyid, context, mapto)
                
                parseKeys("generic", cmap)
                
-               for device in cmap.getElementsByTagName("device"):
+               for device in elementsWithTag(cmap.childNodes, "device"):
                        parseKeys(str(device.getAttribute("name")), device)