From 6baae2818c0ba3fb8f972e00fc508deb1c32fc6b Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Mon, 16 Dec 2024 06:25:59 -0500 Subject: [PATCH] [script.keymap] v.1.3.0 - added option to enable long press mapping --- script.keymap/addon.xml | 8 +++----- script.keymap/changelog.txt | 3 +++ .../resource.language.en_gb/strings.po | 18 +++++++++++++++++- script.keymap/resources/lib/editor.py | 13 +++++++++++-- script.keymap/resources/lib/utils.py | 11 +++++++++-- script.keymap/resources/settings.xml | 5 +++++ 6 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 script.keymap/resources/settings.xml diff --git a/script.keymap/addon.xml b/script.keymap/addon.xml index 7cdb2a0f6..f49be4e4e 100644 --- a/script.keymap/addon.xml +++ b/script.keymap/addon.xml @@ -1,15 +1,13 @@ - + - v.1.2.1 -- added video versions and video extras windows -- replaced favourites (depreciated) with favouritesbrowser -- updated translation files + v.1.3.0 +- added option to enable long press mapping icon.png diff --git a/script.keymap/changelog.txt b/script.keymap/changelog.txt index c28459c5f..b49d0a078 100644 --- a/script.keymap/changelog.txt +++ b/script.keymap/changelog.txt @@ -1,3 +1,6 @@ +v.1.3.0 +- added option to enable long press mapping + v.1.2.1 - added video versions and video extras windows diff --git a/script.keymap/resources/language/resource.language.en_gb/strings.po b/script.keymap/resources/language/resource.language.en_gb/strings.po index f838760d6..acbfa8d18 100644 --- a/script.keymap/resources/language/resource.language.en_gb/strings.po +++ b/script.keymap/resources/language/resource.language.en_gb/strings.po @@ -76,7 +76,23 @@ msgctxt "#30012" msgid "Remove" msgstr "" -# empty strings from id 30013 to 30099 +msgctxt "#30013" +msgid "Long Press" +msgstr "" + +msgctxt "#30014" +msgid "Add mapping as long press?" +msgstr "" + +msgctxt "#30015" +msgid "Enable long press mapping" +msgstr "" + +msgctxt "#30016" +msgid "General" +msgstr "" + +# empty strings from id 30017 to 30099 # Window names diff --git a/script.keymap/resources/lib/editor.py b/script.keymap/resources/lib/editor.py index b351831a8..7e070fd34 100644 --- a/script.keymap/resources/lib/editor.py +++ b/script.keymap/resources/lib/editor.py @@ -21,11 +21,10 @@ from collections import OrderedDict from xbmcgui import Dialog, WindowXMLDialog from resources.lib.actions import ACTIONS, WINDOWS -from resources.lib.utils import tr +from resources.lib.utils import tr, settings KODIMONITOR = xbmc.Monitor() - class Editor(object): def __init__(self, defaultkeymap, userkeymap): """Create the editor object.""" @@ -73,6 +72,8 @@ def start(self): newkey = KeyListener.record_key() if newkey is None: continue + if self._long_press(): + newkey += ' + longpress' new_mapping = (window, action, newkey) if old_mapping in self.userkeymap: @@ -95,6 +96,14 @@ def _current_keymap(self, window, category): names = ACTIONS[category] return [(action, key, names[action]) for action, key in actions.items()] + def _long_press(self): + if settings('longpress') == 'true': + lp = Dialog().yesno(tr(30013), tr(30014)) + if lp: + return True + return False + + class KeyListener(WindowXMLDialog): TIMEOUT = 5 diff --git a/script.keymap/resources/lib/utils.py b/script.keymap/resources/lib/utils.py index 4349aae48..74eacbcb5 100644 --- a/script.keymap/resources/lib/utils.py +++ b/script.keymap/resources/lib/utils.py @@ -22,6 +22,7 @@ import xbmcaddon tr = xbmcaddon.Addon().getLocalizedString +settings = xbmcaddon.Addon().getSetting def rpc(method, **params): @@ -39,7 +40,9 @@ def read_keymap(filename): for context in keymap: for device in context: for mapping in device: - key = mapping.get('id') or mapping.tag + key1 = mapping.get('id') or mapping.tag + key2 = mapping.get('mod') + key = ' + '.join((key1, key2)) if key2 else key1 action = mapping.text if action: ret.append( @@ -57,7 +60,11 @@ def write_keymap(keymap, filename): builder.start("keyboard", {}) for c, a, k in keymap: if c == context: - builder.start("key", {"id": k}) + k = k.split(' + ') + if len(k) > 1: + builder.start("key", {"id":k[0], "mod":k[1]}) + else: + builder.start("key", {"id":k[0]}) builder.data(a) builder.end("key") builder.end("keyboard") diff --git a/script.keymap/resources/settings.xml b/script.keymap/resources/settings.xml new file mode 100644 index 000000000..84c09196f --- /dev/null +++ b/script.keymap/resources/settings.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file