Skip to content

Commit

Permalink
[ActionMap]
Browse files Browse the repository at this point in the history
* re-introduce keymap translate feature.

Note! The keytranslation.xml will never come back but the custom user keymap xml can be used for translate.

(cherry picked from commit 0f4cbf5)
  • Loading branch information
jbleyel committed Apr 27, 2024
1 parent db67430 commit 64cd085
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/python/Components/ActionMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def parseKeymap(filename, context, actionMapInstance, device, domKeys):
unmapDict.update({(context, keyName, unmap): filename})


def getKeyId(id): # FIME Remove keytranslation.xml.
def getKeyId(id):
if len(id) == 1:
keyid = ord(id) | 0x8000
elif id[0] == "\\":
Expand All @@ -145,6 +145,25 @@ def getKeyId(id): # FIME Remove keytranslation.xml.
return keyid


def parseTrans(filename, actionmap, device, keys):
for toggle in keys.findall("toggle"):
get_attr = toggle.attrib.get
toggle_key = get_attr("from")
toggle_key = getKeyId(toggle_key)
actionmap.bindToggle(filename, device, toggle_key)
for key in keys.findall("key"):
get_attr = key.attrib.get
keyin = get_attr("from")
keyout = get_attr("to")
toggle = get_attr("toggle") or "0"
assert keyin, f"[ActionMap] {filename}: must specify key to translate from '{keyin}'"
assert keyout, f"[ActionMap] {filename}: must specify key to translate to '{keyout}'"
keyin = getKeyId(keyin)
keyout = getKeyId(keyout)
toggle = int(toggle)
actionmap.bindTranslation(filename, device, keyin, keyout, toggle)


def loadKeymap(filename, replace=False):
actionMapInstance = eActionMap.getInstance()
domKeymap = fileReadXML(filename, source=MODULE_NAME)
Expand All @@ -160,6 +179,9 @@ def loadKeymap(filename, replace=False):
parseKeymap(filename, context, actionMapInstance, "generic", domMap)
for domDevice in domMap.findall("device"):
parseKeymap(filename, context, actionMapInstance, domDevice.attrib.get("name"), domDevice)
for domMap in domKeymap.findall("translate"):
for domDevice in domMap.findall("device"):
parseTrans(filename, actionMapInstance, domDevice.attrib.get("name"), domDevice)


def removeKeymap(filename):
Expand Down

0 comments on commit 64cd085

Please sign in to comment.