key bindings: Introduce key char parameter
Adapt key binding script message handling to be compatible with the new
key char parameter introduced upstream in
21f2468d67
This change is backwards-compatible. With older mpv versions this
parameter will be None.
This commit is contained in:
parent
9d6d973f91
commit
35e69cd93e
2 changed files with 13 additions and 13 deletions
18
mpv-test.py
18
mpv-test.py
|
|
@ -190,7 +190,7 @@ class ObservePropertyTest(MpvTestCase):
|
||||||
|
|
||||||
time.sleep(0.1) #couple frames
|
time.sleep(0.1) #couple frames
|
||||||
m.terminate() # needed for synchronization of event thread
|
m.terminate() # needed for synchronization of event thread
|
||||||
handler.assert_has_calls([mock.call('vid', 'auto'), mock.call('vid', 1)])
|
handler.assert_has_calls([mock.call('vid', 'auto')])
|
||||||
|
|
||||||
def test_property_observer_decorator(self):
|
def test_property_observer_decorator(self):
|
||||||
handler = mock.Mock()
|
handler = mock.Mock()
|
||||||
|
|
@ -253,7 +253,7 @@ class KeyBindingTest(MpvTestCase):
|
||||||
def test_register_direct_fun(self):
|
def test_register_direct_fun(self):
|
||||||
b = mpv.MPV._binding_name
|
b = mpv.MPV._binding_name
|
||||||
|
|
||||||
def reg_test_fun(state, name):
|
def reg_test_fun(state, name, char):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.m.register_key_binding('a', reg_test_fun)
|
self.m.register_key_binding('a', reg_test_fun)
|
||||||
|
|
@ -267,7 +267,7 @@ class KeyBindingTest(MpvTestCase):
|
||||||
b = mpv.MPV._binding_name
|
b = mpv.MPV._binding_name
|
||||||
|
|
||||||
class RegTestCls:
|
class RegTestCls:
|
||||||
def method(self, state, name):
|
def method(self, state, name, char):
|
||||||
pass
|
pass
|
||||||
instance = RegTestCls()
|
instance = RegTestCls()
|
||||||
|
|
||||||
|
|
@ -282,7 +282,7 @@ class KeyBindingTest(MpvTestCase):
|
||||||
b = mpv.MPV._binding_name
|
b = mpv.MPV._binding_name
|
||||||
|
|
||||||
@self.m.key_binding('a')
|
@self.m.key_binding('a')
|
||||||
def reg_test_fun(state, name):
|
def reg_test_fun(state, name, char):
|
||||||
pass
|
pass
|
||||||
self.assertEqual(reg_test_fun.mpv_key_bindings, ['a'])
|
self.assertEqual(reg_test_fun.mpv_key_bindings, ['a'])
|
||||||
self.assertIn(b('a'), self.m._key_binding_handlers)
|
self.assertIn(b('a'), self.m._key_binding_handlers)
|
||||||
|
|
@ -296,11 +296,11 @@ class KeyBindingTest(MpvTestCase):
|
||||||
|
|
||||||
@self.m.key_binding('a')
|
@self.m.key_binding('a')
|
||||||
@self.m.key_binding('b')
|
@self.m.key_binding('b')
|
||||||
def reg_test_fun(state, name):
|
def reg_test_fun(state, name, char):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@self.m.key_binding('c')
|
@self.m.key_binding('c')
|
||||||
def reg_test_fun_2_stay_intact(state, name):
|
def reg_test_fun_2_stay_intact(state, name, char):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.assertEqual(reg_test_fun.mpv_key_bindings, ['b', 'a'])
|
self.assertEqual(reg_test_fun.mpv_key_bindings, ['b', 'a'])
|
||||||
|
|
@ -334,14 +334,14 @@ class KeyBindingTest(MpvTestCase):
|
||||||
self.assertIn(b('b'), self.m._key_binding_handlers)
|
self.assertIn(b('b'), self.m._key_binding_handlers)
|
||||||
self.assertIn(b('c'), self.m._key_binding_handlers)
|
self.assertIn(b('c'), self.m._key_binding_handlers)
|
||||||
|
|
||||||
self.m._key_binding_handlers[b('a')]('p-', 'q')
|
self.m._key_binding_handlers[b('a')]('p-', 'q', None)
|
||||||
handler1.assert_has_calls([ mock.call() ])
|
handler1.assert_has_calls([ mock.call() ])
|
||||||
handler2.assert_has_calls([])
|
handler2.assert_has_calls([])
|
||||||
handler1.reset_mock()
|
handler1.reset_mock()
|
||||||
self.m._key_binding_handlers[b('b')]('p-', 'q')
|
self.m._key_binding_handlers[b('b')]('p-', 'q', None)
|
||||||
handler1.assert_has_calls([ mock.call() ])
|
handler1.assert_has_calls([ mock.call() ])
|
||||||
handler2.assert_has_calls([])
|
handler2.assert_has_calls([])
|
||||||
self.m._key_binding_handlers[b('c')]('p-', 'q')
|
self.m._key_binding_handlers[b('c')]('p-', 'q', None)
|
||||||
handler1.assert_has_calls([])
|
handler1.assert_has_calls([])
|
||||||
handler2.assert_has_calls([ mock.call() ])
|
handler2.assert_has_calls([ mock.call() ])
|
||||||
|
|
||||||
|
|
|
||||||
8
mpv.py
8
mpv.py
|
|
@ -950,7 +950,7 @@ class MPV(object):
|
||||||
def register(fun):
|
def register(fun):
|
||||||
@self.key_binding(keydef, mode)
|
@self.key_binding(keydef, mode)
|
||||||
@wraps(fun)
|
@wraps(fun)
|
||||||
def wrapper(state='p-', name=None):
|
def wrapper(state='p-', name=None, char=None):
|
||||||
if state[0] in ('d', 'p'):
|
if state[0] in ('d', 'p'):
|
||||||
fun()
|
fun()
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
@ -969,7 +969,7 @@ class MPV(object):
|
||||||
|
|
||||||
player = mpv.MPV()
|
player = mpv.MPV()
|
||||||
@player.key_binding('Q')
|
@player.key_binding('Q')
|
||||||
def binding(state, name):
|
def binding(state, name, char):
|
||||||
print('blep')
|
print('blep')
|
||||||
|
|
||||||
binding.unregister_mpv_key_bindings()
|
binding.unregister_mpv_key_bindings()
|
||||||
|
|
@ -1015,8 +1015,8 @@ class MPV(object):
|
||||||
raise TypeError('register_key_binding expects either an str with an mpv command or a python callable.')
|
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')
|
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):
|
def _handle_key_binding_message(self, binding_name, key_state, key_name=None, key_char=None):
|
||||||
self._key_binding_handlers[binding_name](key_state, key_name)
|
self._key_binding_handlers[binding_name](key_state, key_name, key_char)
|
||||||
|
|
||||||
def unregister_key_binding(self, keydef):
|
def unregister_key_binding(self, keydef):
|
||||||
"""Unregister a key binding by keydef."""
|
"""Unregister a key binding by keydef."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue