Get rid of BaseKeyparser.Type
This commit is contained in:
parent
72e30cc12c
commit
ba012c6ba8
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
"""Base class for vim-like key sequence parser."""
|
"""Base class for vim-like key sequence parser."""
|
||||||
|
|
||||||
import enum
|
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, QObject
|
from PyQt5.QtCore import pyqtSignal, QObject
|
||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QKeySequence
|
||||||
|
|
||||||
@ -43,10 +41,6 @@ class BaseKeyParser(QObject):
|
|||||||
definitive: Keychain matches exactly.
|
definitive: Keychain matches exactly.
|
||||||
none: No more matches possible.
|
none: No more matches possible.
|
||||||
|
|
||||||
Types: type of a key binding.
|
|
||||||
chain: execute() was called via a chain-like key binding
|
|
||||||
special: execute() was called via a special key binding
|
|
||||||
|
|
||||||
do_log: Whether to log keypresses or not.
|
do_log: Whether to log keypresses or not.
|
||||||
passthrough: Whether unbound keys should be passed through with this
|
passthrough: Whether unbound keys should be passed through with this
|
||||||
handler.
|
handler.
|
||||||
@ -76,8 +70,6 @@ class BaseKeyParser(QObject):
|
|||||||
do_log = True
|
do_log = True
|
||||||
passthrough = False
|
passthrough = False
|
||||||
|
|
||||||
Type = enum.Enum('Type', ['chain', 'special'])
|
|
||||||
|
|
||||||
def __init__(self, win_id, parent=None, supports_count=None,
|
def __init__(self, win_id, parent=None, supports_count=None,
|
||||||
supports_chains=False):
|
supports_chains=False):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -157,7 +149,7 @@ class BaseKeyParser(QObject):
|
|||||||
self._sequence))
|
self._sequence))
|
||||||
count = int(self._count) if self._count else None
|
count = int(self._count) if self._count else None
|
||||||
self.clear_keystring()
|
self.clear_keystring()
|
||||||
self.execute(binding, self.Type.chain, count)
|
self.execute(binding, count)
|
||||||
elif match == QKeySequence.PartialMatch:
|
elif match == QKeySequence.PartialMatch:
|
||||||
self._debug_log("No match for '{}' (added {})".format(
|
self._debug_log("No match for '{}' (added {})".format(
|
||||||
self._sequence, txt))
|
self._sequence, txt))
|
||||||
@ -248,13 +240,11 @@ class BaseKeyParser(QObject):
|
|||||||
# "because keychains are not supported there."
|
# "because keychains are not supported there."
|
||||||
# .format(key, modename))
|
# .format(key, modename))
|
||||||
|
|
||||||
def execute(self, cmdstr, keytype, count=None):
|
def execute(self, cmdstr, count=None):
|
||||||
"""Handle a completed keychain.
|
"""Handle a completed keychain.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmdstr: The command to execute as a string.
|
cmdstr: The command to execute as a string.
|
||||||
# FIXME do we still need this?
|
|
||||||
keytype: Type.chain or Type.special
|
|
||||||
count: The count if given.
|
count: The count if given.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -39,7 +39,7 @@ class CommandKeyParser(BaseKeyParser):
|
|||||||
super().__init__(win_id, parent, supports_count, supports_chains)
|
super().__init__(win_id, parent, supports_count, supports_chains)
|
||||||
self._commandrunner = runners.CommandRunner(win_id)
|
self._commandrunner = runners.CommandRunner(win_id)
|
||||||
|
|
||||||
def execute(self, cmdstr, _keytype, count=None):
|
def execute(self, cmdstr, count=None):
|
||||||
try:
|
try:
|
||||||
self._commandrunner.run(cmdstr, count)
|
self._commandrunner.run(cmdstr, count)
|
||||||
except cmdexc.Error as e:
|
except cmdexc.Error as e:
|
||||||
|
@ -232,19 +232,6 @@ class HintKeyParser(keyparser.CommandKeyParser):
|
|||||||
|
|
||||||
return match != QKeySequence.NoMatch
|
return match != QKeySequence.NoMatch
|
||||||
|
|
||||||
# FIXME why is this needed?
|
|
||||||
# def execute(self, cmdstr, keytype, count=None):
|
|
||||||
# """Handle a completed keychain."""
|
|
||||||
# if not isinstance(keytype, self.Type):
|
|
||||||
# raise TypeError("Type {} is no Type member!".format(keytype))
|
|
||||||
# if keytype == self.Type.chain:
|
|
||||||
# hintmanager = objreg.get('hintmanager', scope='tab',
|
|
||||||
# window=self._win_id, tab='current')
|
|
||||||
# hintmanager.handle_partial_key(cmdstr)
|
|
||||||
# else:
|
|
||||||
# # execute as command
|
|
||||||
# super().execute(cmdstr, keytype, count)
|
|
||||||
|
|
||||||
def update_bindings(self, strings, preserve_filter=False):
|
def update_bindings(self, strings, preserve_filter=False):
|
||||||
"""Update bindings when the hint strings changed.
|
"""Update bindings when the hint strings changed.
|
||||||
|
|
||||||
|
@ -181,15 +181,13 @@ class TestSpecialKeys:
|
|||||||
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier))
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_X, modifier))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_X, modifier))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ctrla', None)
|
||||||
'message-info ctrla', keyparser.Type.chain, None)
|
|
||||||
|
|
||||||
def test_valid_key_count(self, fake_keyevent_factory, keyparser):
|
def test_valid_key_count(self, fake_keyevent_factory, keyparser):
|
||||||
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_5, text='5'))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_5, text='5'))
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier, text='A'))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier, text='A'))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ctrla', 5)
|
||||||
'message-info ctrla', keyparser.Type.chain, 5)
|
|
||||||
|
|
||||||
def test_invalid_key(self, fake_keyevent_factory, keyparser):
|
def test_invalid_key(self, fake_keyevent_factory, keyparser):
|
||||||
keyparser.handle(fake_keyevent_factory(
|
keyparser.handle(fake_keyevent_factory(
|
||||||
@ -212,8 +210,7 @@ class TestSpecialKeys:
|
|||||||
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
||||||
|
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_B, modifier))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_B, modifier))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ctrla', None)
|
||||||
'message-info ctrla', keyparser.Type.chain, None)
|
|
||||||
|
|
||||||
def test_binding_and_mapping(self, config_stub, fake_keyevent_factory,
|
def test_binding_and_mapping(self, config_stub, fake_keyevent_factory,
|
||||||
keyparser):
|
keyparser):
|
||||||
@ -221,8 +218,7 @@ class TestSpecialKeys:
|
|||||||
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier
|
||||||
|
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ctrla', None)
|
||||||
'message-info ctrla', keyparser.Type.chain, None)
|
|
||||||
|
|
||||||
|
|
||||||
class TestKeyChain:
|
class TestKeyChain:
|
||||||
@ -240,8 +236,7 @@ class TestKeyChain:
|
|||||||
modifier = Qt.ControlModifier
|
modifier = Qt.ControlModifier
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_A, modifier))
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_X, modifier))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_X, modifier))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ctrla', None)
|
||||||
'message-info ctrla', keyparser.Type.chain, None)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_invalid_special_key(self, fake_keyevent_factory, keyparser):
|
def test_invalid_special_key(self, fake_keyevent_factory, keyparser):
|
||||||
@ -255,14 +250,12 @@ class TestKeyChain:
|
|||||||
handle_text((Qt.Key_X, 'x'),
|
handle_text((Qt.Key_X, 'x'),
|
||||||
# Then start the real chain
|
# Then start the real chain
|
||||||
(Qt.Key_B, 'b'), (Qt.Key_A, 'a'))
|
(Qt.Key_B, 'b'), (Qt.Key_A, 'a'))
|
||||||
keyparser.execute.assert_called_with(
|
keyparser.execute.assert_called_with('message-info ba', None)
|
||||||
'message-info ba', keyparser.Type.chain, None)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_0_press(self, handle_text, keyparser):
|
def test_0_press(self, handle_text, keyparser):
|
||||||
handle_text((Qt.Key_0, '0'))
|
handle_text((Qt.Key_0, '0'))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info 0', None)
|
||||||
'message-info 0', keyparser.Type.chain, None)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_ambiguous_keychain(self, handle_text, keyparser):
|
def test_ambiguous_keychain(self, handle_text, keyparser):
|
||||||
@ -276,8 +269,7 @@ class TestKeyChain:
|
|||||||
|
|
||||||
def test_mapping(self, config_stub, handle_text, keyparser):
|
def test_mapping(self, config_stub, handle_text, keyparser):
|
||||||
handle_text((Qt.Key_X, 'x'))
|
handle_text((Qt.Key_X, 'x'))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info a', None)
|
||||||
'message-info a', keyparser.Type.chain, None)
|
|
||||||
|
|
||||||
def test_binding_and_mapping(self, config_stub, handle_text, keyparser):
|
def test_binding_and_mapping(self, config_stub, handle_text, keyparser):
|
||||||
"""with a conflicting binding/mapping, the binding should win."""
|
"""with a conflicting binding/mapping, the binding should win."""
|
||||||
@ -296,22 +288,20 @@ class TestCount:
|
|||||||
def test_no_count(self, handle_text, keyparser):
|
def test_no_count(self, handle_text, keyparser):
|
||||||
"""Test with no count added."""
|
"""Test with no count added."""
|
||||||
handle_text((Qt.Key_B, 'b'), (Qt.Key_A, 'a'))
|
handle_text((Qt.Key_B, 'b'), (Qt.Key_A, 'a'))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ba', None)
|
||||||
'message-info ba', keyparser.Type.chain, None)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_count_0(self, handle_text, keyparser):
|
def test_count_0(self, handle_text, keyparser):
|
||||||
handle_text((Qt.Key_0, '0'), (Qt.Key_B, 'b'), (Qt.Key_A, 'a'))
|
handle_text((Qt.Key_0, '0'), (Qt.Key_B, 'b'), (Qt.Key_A, 'a'))
|
||||||
calls = [mock.call('message-info 0', keyparser.Type.chain, None),
|
calls = [mock.call('message-info 0', None),
|
||||||
mock.call('message-info ba', keyparser.Type.chain, None)]
|
mock.call('message-info ba', None)]
|
||||||
keyparser.execute.assert_has_calls(calls)
|
keyparser.execute.assert_has_calls(calls)
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_count_42(self, handle_text, keyparser):
|
def test_count_42(self, handle_text, keyparser):
|
||||||
handle_text((Qt.Key_4, '4'), (Qt.Key_2, '2'), (Qt.Key_B, 'b'),
|
handle_text((Qt.Key_4, '4'), (Qt.Key_2, '2'), (Qt.Key_B, 'b'),
|
||||||
(Qt.Key_A, 'a'))
|
(Qt.Key_A, 'a'))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ba', 42)
|
||||||
'message-info ba', keyparser.Type.chain, 42)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_count_42_invalid(self, handle_text, keyparser):
|
def test_count_42_invalid(self, handle_text, keyparser):
|
||||||
@ -323,8 +313,7 @@ class TestCount:
|
|||||||
# Valid call with ccc gets the correct count
|
# Valid call with ccc gets the correct count
|
||||||
handle_text((Qt.Key_2, '2'), (Qt.Key_3, '3'), (Qt.Key_C, 'c'),
|
handle_text((Qt.Key_2, '2'), (Qt.Key_3, '3'), (Qt.Key_C, 'c'),
|
||||||
(Qt.Key_C, 'c'), (Qt.Key_C, 'c'))
|
(Qt.Key_C, 'c'), (Qt.Key_C, 'c'))
|
||||||
keyparser.execute.assert_called_once_with(
|
keyparser.execute.assert_called_once_with('message-info ccc', 23)
|
||||||
'message-info ccc', keyparser.Type.chain, 23)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,8 +56,7 @@ class TestsNormalKeyParser:
|
|||||||
# Then start the real chain
|
# Then start the real chain
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_B, text='b'))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_B, text='b'))
|
||||||
keyparser.handle(fake_keyevent_factory(Qt.Key_A, text='a'))
|
keyparser.handle(fake_keyevent_factory(Qt.Key_A, text='a'))
|
||||||
keyparser.execute.assert_called_with(
|
keyparser.execute.assert_called_with('message-info ba', None)
|
||||||
'message-info ba', keyparser.Type.chain, None)
|
|
||||||
assert not keyparser._sequence
|
assert not keyparser._sequence
|
||||||
|
|
||||||
def test_partial_keychain_timeout(self, keyparser, config_stub,
|
def test_partial_keychain_timeout(self, keyparser, config_stub,
|
||||||
|
Loading…
Reference in New Issue
Block a user