def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") id = get_attr("id") flags = get_attr("flags") flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x] flags = sum(map(flag_ascii_to_id, flags)) 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, "%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] == '\\': if id[1] == 'x': keyid = int(id[2:], 0x10) | 0x8000 elif id[1] == 'd': keyid = int(id[2:]) | 0x8000 else: raise KeymapError("key id '" + str(id) + "' is neither hex nor dec") else: try: keyid = KEYIDS[id] except: raise KeymapError("key id '" + str(id) + "' is illegal") # print context + "::" + mapto + " -> " + device + "." + hex(keyid) actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") unmap = get_attr("unmap") id = get_attr("id") flags = get_attr("flags") if unmap is not None: assert id, "[keymapparser] %s: must specify id in context %s, unmap '%s'" % ( filename, context, unmap) keyid = getKeyId(id) actionmap.unbindPythonKey(context, keyid, unmap) unmapDict.update({(context, id, unmap): filename}) else: assert mapto, "[keymapparser] %s: must specify mapto (or unmap) in context %s, id '%s'" % ( filename, context, id) assert id, "[keymapparser] %s: must specify id in context %s, mapto '%s'" % ( filename, context, mapto) keyid = getKeyId(id) flag_ascii_to_id = lambda x: {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] flags = sum(map(flag_ascii_to_id, flags)) assert flags, "[keymapparser] %s: must specify at least one flag in context %s, id '%s'" % ( filename, context, id) # if a key was unmapped, it can only be assigned a new function in the same keymap file (avoid file parsing sequence dependency) if unmapDict.get((context, id, mapto)) in [filename, None]: # print("[keymapparser] " + context + "::" + mapto + " -> " + device + "." + hex(keyid)) actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall('key'): get_attr = x.attrib.get mapto = get_attr('mapto') id = get_attr('id') flags = get_attr('flags') flag_ascii_to_id = lambda x: {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] flags = sum(map(flag_ascii_to_id, flags)) if len(id) == 1: keyid = ord(id) | 32768 elif id[0] == '\\': if id[1] == 'x': keyid = int(id[2:], 16) | 32768 elif id[1] == 'd': keyid = int(id[2:]) | 32768 else: raise KeymapError("[Keymapparser] key id '" + str(id) + "' is neither hex nor dec") else: try: keyid = KEYIDS[id] except: raise KeymapError("[Keymapparser] key id '" + str(id) + "' is illegal") actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") unmap = get_attr("unmap") id = get_attr("id") flags = get_attr("flags") if unmap is not None: assert id, "[keymapparser] %s: must specify id in context %s, unmap '%s'" % ( filename, context, unmap) keyid = getKeyId(id) actionmap.unbindPythonKey(context, keyid, unmap) else: assert mapto, "[keymapparser] %s: must specify mapto (or unmap) in context %s, id '%s'" % ( filename, context, id) assert id, "[keymapparser] %s: must specify id in context %s, mapto '%s'" % ( filename, context, mapto) keyid = getKeyId(id) flag_ascii_to_id = lambda x: {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] flags = sum(map(flag_ascii_to_id, flags)) assert flags, "[keymapparser] %s: must specify at least one flag in context %s, id '%s'" % ( filename, context, id) # print "[keymapparser] " + context + "::" + mapto + " -> " + device + "." + hex(keyid) actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") unmap = get_attr("unmap") id = get_attr("id") flags = get_attr("flags") if unmap is not None: assert id, "[keymapparser] %s: must specify id in context %s, unmap '%s'" % (filename, context, unmap) keyid = getKeyId(id) actionmap.unbindPythonKey(context, keyid, unmap) unmapDict.update({(context, id, unmap):filename}) else: assert mapto, "[keymapparser] %s: must specify mapto (or unmap) in context %s, id '%s'" % (filename, context, id) assert id, "[keymapparser] %s: must specify id in context %s, mapto '%s'" % (filename, context, mapto) keyid = getKeyId(id) flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x] flags = sum(map(flag_ascii_to_id, flags)) assert flags, "[keymapparser] %s: must specify at least one flag in context %s, id '%s'" % (filename, context, id) # if a key was unmapped, it can only be assigned a new function in the same keymap file (avoid file parsing sequence dependency) if unmapDict.get((context, id, mapto)) in [filename, None]: # print "[keymapparser] " + context + "::" + mapto + " -> " + device + "." + hex(keyid) actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") unmap = get_attr("unmap") id = get_attr("id") flags = get_attr("flags") if unmap is not None: assert id, "[keymapparser] %s: must specify id in context %s, unmap '%s'" % (filename, context, unmap) keyid = getKeyId(id) actionmap.unbindPythonKey(context, keyid, unmap) else: assert mapto, "[keymapparser] %s: must specify mapto (or unmap) in context %s, id '%s'" % (filename, context, id) assert id, "[keymapparser] %s: must specify id in context %s, mapto '%s'" % (filename, context, mapto) keyid = getKeyId(id) flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x] flags = sum(map(flag_ascii_to_id, flags)) assert flags, "[keymapparser] %s: must specify at least one flag in context %s, id '%s'" % (filename, context, id) # print "[keymapparser] " + context + "::" + mapto + " -> " + device + "." + hex(keyid) actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall('key'): get_attr = x.attrib.get mapto = get_attr('mapto') id = get_attr('id') flags = get_attr('flags') flag_ascii_to_id = lambda x: {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] flags = sum(map(flag_ascii_to_id, flags)) if len(id) == 1: keyid = ord(id) | 32768 elif id[0] == '\\': if id[1] == 'x': keyid = int(id[2:], 16) | 32768 elif id[1] == 'd': keyid = int(id[2:]) | 32768 else: raise KeymapError("key id '" + str(id) + "' is neither hex nor dec") else: try: keyid = KEYIDS[id] except: raise KeymapError("key id '" + str(id) + "' is illegal") actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall('key'): get_attr = x.attrib.get mapto = get_attr('mapto') id = get_attr('id') flags = get_attr('flags') flag_ascii_to_id = lambda x: {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] flags = sum(map(flag_ascii_to_id, flags)) keyid = getKeyId(id) actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)
def parseKeys(context, filename, actionmap, device, keys): if context == "InfobarSeekActions": if device == "generic": for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") id = get_attr("id") if id == "KEY_LEFT": mapto = "seekbarLeft" if id == "KEY_RIGHT": mapto = "seekbarRight" flags = get_attr("flags") flag_ascii_to_id = lambda x: { 'm': 1, 'b': 2, 'r': 4, 'l': 8 }[x] flags = sum(map(flag_ascii_to_id, flags)) 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, "%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] == '\\': if id[1] == 'x': keyid = int(id[2:], 0x10) | 0x8000 elif id[1] == 'd': keyid = int(id[2:]) | 0x8000 else: raise KeymapError("key id '" + str(id) + "' is neither hex nor dec") else: try: keyid = KEYIDS[id] except: raise KeymapError("key id '" + str(id) + "' is illegal") actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags) else: ParseKeys(context, filename, actionmap, device, keys) else: ParseKeys(context, filename, actionmap, device, keys)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall('key'): get_attr = x.attrib.get mapto = get_attr('mapto') unmap = get_attr('unmap') id = get_attr('id') flags = get_attr('flags') if unmap is not None: keyid = getKeyId(id) actionmap.unbindPythonKey(context, keyid, unmap) unmapDict.update({(context, id, unmap): filename}) else: keyid = getKeyId(id) flag_ascii_to_id = lambda x: {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] flags = sum(map(flag_ascii_to_id, flags)) if unmapDict.get((context, id, mapto)) in [filename, None]: actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags) return
def parseKeys(context, filename, actionmap, device, keys): if context == "InfobarSeekActions": if device == "generic": for x in keys.findall("key"): get_attr = x.attrib.get mapto = get_attr("mapto") id = get_attr("id") if id == "KEY_LEFT": mapto = "seekbarLeft" if id == "KEY_RIGHT": mapto = "seekbarRight" flags = get_attr("flags") flag_ascii_to_id = lambda x: {'m':1,'b':2,'r':4,'l':8}[x] flags = sum(map(flag_ascii_to_id, flags)) 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, "%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] == '\\': if id[1] == 'x': keyid = int(id[2:], 0x10) | 0x8000 elif id[1] == 'd': keyid = int(id[2:]) | 0x8000 else: raise KeymapError("key id '" + str(id) + "' is neither hex nor dec") else: try: keyid = KEYIDS[id] except: raise KeymapError("key id '" + str(id) + "' is illegal") actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags) else: ParseKeys(context, filename, actionmap, device, keys) else: ParseKeys(context, filename, actionmap, device, keys)
def parseKeys(context, filename, actionmap, device, keys): for x in keys.findall("key"): get_attr = x.attrib.get kid = get_attr("id") unmapto = get_attr("unmapto") unmap = get_attr("unmap") mapto = get_attr("mapto") flags = get_attr("flags") if not kid: print "[keymapparser] %s: must specify id in context %s, %s '%s'" % ( filename, context, mapto and "mapto" or unmap and "unmap" or unmapto and "unmapto" or "<none>", mapto or unmap or unmapto or "<none>") continue if unmapto: if mapto or unmap: print "[keymapparser] %s: unmapto must not specify mapto or unmap in context %s, id '%s'" % ( filename, context, kid) continue unmap = '*' mapto = unmapto elif not mapto and not unmap: print "[keymapparser] %s: must specify mapto and/or unmap in context %s, id '%s'" % ( filename, context, kid) continue if mapto: def flag_ascii_to_id(x): try: return {'m': 1, 'b': 2, 'r': 4, 'l': 8}[x] except: print "[keymapparser] %s: ignoring unknown flag '%s' in context %s, id '%s'" % ( filename, x, context, kid) return 0 flags = flags and sum(map(flag_ascii_to_id, flags)) if not flags: print "[keymapparser] %s: must specify at least one flag in context %s, id '%s'" % ( filename, context, kid) continue elif flags: print "[keymapparser] %s: ignoring flags in context %s, id '%s'" % ( filename, context, kid) if len(kid) == 1: keyid = ord(kid) | 0x8000 elif kid[0] == '\\': try: if kid[1] == 'x': keyid = int(kid[2:], 0x10) | 0x8000 elif kid[1] == 'd': keyid = int(kid[2:]) | 0x8000 else: raise ValueError except: print "[keymapparser] %s: key id '%s' is neither hex nor dec" % ( filename, kid) continue else: try: keyid = KEYIDS[kid] except: print "[keymapparser] %s: unknown key id '%s'" % (filename, kid) continue if unmap: actionmap.unbindPythonKey(context, keyid, unmap) removeKeyBinding(keyid, context, unmap) unmapDict.update({(context, kid, unmap): filename}) if mapto and unmapDict.get( (context, kid, mapto), unmapDict.get( (context, kid, '*'))) in (filename, None): actionmap.bindKey(filename, device, keyid, flags, context, mapto) addKeyBinding(filename, keyid, context, mapto, flags)