1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
From: jaseg <git@jaseg.de>
Subject: [PATCH] Add support for libmpv's new args to key binding handlers
This changes the API, check your code if you use key bindings.
Origin: upstream, https://github.com/jaseg/python-mpv/commit/12850b34bd3b64704f8abd30341a647a73719267
Bug-Debian: http://bugs.debian.org/1101765
---
mpv.py | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
Index: python-mpv/mpv.py
===================================================================
--- python-mpv.orig/mpv.py
+++ python-mpv/mpv.py
@@ -1672,9 +1672,10 @@ class MPV(object):
def _binding_name(callback_or_cmd):
return 'py_kb_{:016x}'.format(hash(callback_or_cmd)&0xffffffffffffffff)
- def on_key_press(self, keydef, mode='force'):
+ def on_key_press(self, keydef, mode='force', repetition=False):
"""Function decorator to register a simplified key binding. The callback is called whenever the key given is
- *pressed*.
+ *pressed*. When the ``repetition=True`` is passed, the callback is called again repeatedly while the key is held
+ down.
To unregister the callback function, you can call its ``unregister_mpv_key_bindings`` attribute::
@@ -1694,8 +1695,8 @@ class MPV(object):
def register(fun):
@self.key_binding(keydef, mode)
@wraps(fun)
- def wrapper(state='p-', name=None, char=None):
- if state[0] in ('d', 'p'):
+ def wrapper(state='p-', name=None, char=None, *_):
+ if state[0] in ('d', 'p') or (repetition and state[0] == 'r'):
fun()
return wrapper
return register
@@ -1703,8 +1704,11 @@ class MPV(object):
def key_binding(self, keydef, mode='force'):
"""Function decorator to register a low-level key binding.
- The callback function signature is ``fun(key_state, key_name)`` where ``key_state`` is either ``'U'`` for "key
- up" or ``'D'`` for "key down".
+ The callback function signature is ``fun(key_state, key_name, key_char, scale, arg)``.
+
+ The key_state contains up to three chars, corresponding to the regex ``[udr]([m-][c-]?)?``. ``[udr]`` means
+ "key up", "key down", or "repetition" for when the key is held down. "m" indicates mouse events, and "c"
+ indicates key up events resulting from a logical cancellation. For details check out the mpv man page.
The keydef format is: ``[Shift+][Ctrl+][Alt+][Meta+]<key>`` where ``<key>`` is either the literal character the
key produces (ASCII or Unicode character), or a symbolic name (as printed by ``mpv --input-keylist``).
@@ -1759,12 +1763,12 @@ class MPV(object):
raise TypeError('register_key_binding expects either an str with an mpv command or a python callable.')
self.command('enable-section', binding_name, 'allow-hide-cursor+allow-vo-dragging')
- def _handle_key_binding_message(self, binding_name, key_state, key_name=None, key_char=None):
+ def _handle_key_binding_message(self, binding_name, key_state, key_name=None, key_char=None, scale=None, arg=None, *_):
binding_name = binding_name.decode('utf-8')
key_state = key_state.decode('utf-8')
key_name = key_name.decode('utf-8') if key_name is not None else None
key_char = key_char.decode('utf-8') if key_char is not None else None
- self._key_binding_handlers[binding_name](key_state, key_name, key_char)
+ self._key_binding_handlers[binding_name](key_state, key_name, key_char, scale, arg)
def unregister_key_binding(self, keydef):
"""Unregister a key binding by keydef."""
|