Skip to content

Commit

Permalink
[script.keymap] v.1.3.0
Browse files Browse the repository at this point in the history
- added option to enable long press mapping
  • Loading branch information
pkscout committed Dec 16, 2024
1 parent 30673e6 commit 6baae28
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
8 changes: 3 additions & 5 deletions script.keymap/addon.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.keymap" name="Keymap Editor" version="1.2.1" provider-name="takoi,pkscout">
<addon id="script.keymap" name="Keymap Editor" version="1.3.0" provider-name="takoi,pkscout">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.defusedxml" version="0.6.0+matrix.1" />
</requires>
<extension point="xbmc.python.script" library="default.py"/>
<extension point="xbmc.addon.metadata">
<news>v.1.2.1
- added video versions and video extras windows
- replaced favourites (depreciated) with favouritesbrowser
- updated translation files
<news>v.1.3.0
- added option to enable long press mapping
</news>
<assets>
<icon>icon.png</icon>
Expand Down
3 changes: 3 additions & 0 deletions script.keymap/changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions script.keymap/resources/lib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions script.keymap/resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import xbmcaddon

tr = xbmcaddon.Addon().getLocalizedString
settings = xbmcaddon.Addon().getSetting


def rpc(method, **params):
Expand All @@ -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(
Expand All @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions script.keymap/resources/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<settings>
<category label="30016">
<setting id="longpress" type="bool" label="30015" default="false" />
</category>
</settings>

0 comments on commit 6baae28

Please sign in to comment.