def init(win_id, parent): """Initialize the mode manager and the keyparsers for the given win_id.""" KM = usertypes.KeyMode # pylint: disable=invalid-name modeman = ModeManager(win_id, parent) objreg.register('mode-manager', modeman, scope='window', window=win_id) keyparsers = { KM.normal: modeparsers.NormalKeyParser(win_id, modeman), KM.hint: modeparsers.HintKeyParser(win_id, modeman), KM.insert: keyparser.PassthroughKeyParser(win_id, 'insert', modeman), KM.passthrough: keyparser.PassthroughKeyParser(win_id, 'passthrough', modeman), KM.command: keyparser.PassthroughKeyParser(win_id, 'command', modeman), KM.prompt: keyparser.PassthroughKeyParser(win_id, 'prompt', modeman, warn=False), KM.yesno: modeparsers.PromptKeyParser(win_id, modeman), KM.caret: modeparsers.CaretKeyParser(win_id, modeman), KM.set_mark: modeparsers.RegisterKeyParser(win_id, KM.set_mark, modeman), KM.jump_mark: modeparsers.RegisterKeyParser(win_id, KM.jump_mark, modeman), KM.record_macro: modeparsers.RegisterKeyParser(win_id, KM.record_macro, modeman), KM.run_macro: modeparsers.RegisterKeyParser(win_id, KM.run_macro, modeman), } objreg.register('keyparsers', keyparsers, scope='window', window=win_id) modeman.destroyed.connect( functools.partial(objreg.delete, 'keyparsers', scope='window', window=win_id)) for mode, parser in keyparsers.items(): modeman.register(mode, parser) return modeman
def init(win_id, parent): """Initialize the mode manager and the keyparsers for the given win_id.""" KM = usertypes.KeyMode # pylint: disable=invalid-name modeman = ModeManager(win_id, parent) objreg.register('mode-manager', modeman, scope='window', window=win_id) keyparsers = { KM.normal: modeparsers.NormalKeyParser(win_id, modeman), KM.hint: modeparsers.HintKeyParser(win_id, modeman), KM.insert: keyparser.PassthroughKeyParser(win_id, 'insert', modeman), KM.passthrough: keyparser.PassthroughKeyParser(win_id, 'passthrough', modeman), KM.command: keyparser.PassthroughKeyParser(win_id, 'command', modeman), KM.prompt: keyparser.PassthroughKeyParser(win_id, 'prompt', modeman, warn=False), KM.yesno: modeparsers.PromptKeyParser(win_id, modeman), } objreg.register('keyparsers', keyparsers, scope='window', window=win_id) modeman.destroyed.connect( functools.partial(objreg.delete, 'keyparsers', scope='window', window=win_id)) modeman.register(KM.normal, keyparsers[KM.normal].handle) modeman.register(KM.hint, keyparsers[KM.hint].handle) modeman.register(KM.insert, keyparsers[KM.insert].handle, passthrough=True) modeman.register(KM.passthrough, keyparsers[KM.passthrough].handle, passthrough=True) modeman.register(KM.command, keyparsers[KM.command].handle, passthrough=True) modeman.register(KM.prompt, keyparsers[KM.prompt].handle, passthrough=True) modeman.register(KM.yesno, keyparsers[KM.yesno].handle) return modeman
def setup(self, monkeypatch, stubs, config_stub, fake_keyconfig): """Set up mocks and read the test config.""" monkeypatch.setattr( 'qutebrowser.keyinput.basekeyparser.usertypes.Timer', stubs.FakeTimer) config_stub.data = CONFIG monkeypatch.setattr('qutebrowser.keyinput.modeparsers.config', config_stub) self.kp = modeparsers.NormalKeyParser(0) self.kp.execute = mock.Mock() yield
def setup(self, mocker, stubs, config_stub): """Set up mocks and read the test config.""" mocker.patch('qutebrowser.keyinput.basekeyparser.usertypes.Timer', new=stubs.FakeTimer) config_stub.data = CONFIG mocker.patch('qutebrowser.keyinput.modeparsers.config', new=config_stub) objreg.register('key-config', fake_keyconfig) self.kp = modeparsers.NormalKeyParser(0) self.kp.execute = mock.Mock() yield objreg.delete('key-config')
def keyparser(self): kp = modeparsers.NormalKeyParser(0) kp.execute = mock.Mock() return kp
def init(win_id: int, parent: QObject) -> 'ModeManager': """Initialize the mode manager and the keyparsers for the given win_id.""" modeman = ModeManager(win_id, parent) objreg.register('mode-manager', modeman, scope='window', window=win_id) commandrunner = runners.CommandRunner(win_id) hintmanager = hints.HintManager(win_id, parent=parent) objreg.register('hintmanager', hintmanager, scope='window', window=win_id, command_only=True) keyparsers = { usertypes.KeyMode.normal: modeparsers.NormalKeyParser(win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.hint: modeparsers.HintKeyParser(win_id=win_id, commandrunner=commandrunner, hintmanager=hintmanager, parent=modeman), usertypes.KeyMode.insert: modeparsers.PassthroughKeyParser(win_id=win_id, mode=usertypes.KeyMode.insert, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.passthrough: modeparsers.PassthroughKeyParser(win_id=win_id, mode=usertypes.KeyMode.passthrough, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.command: modeparsers.PassthroughKeyParser(win_id=win_id, mode=usertypes.KeyMode.command, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.prompt: modeparsers.PassthroughKeyParser(win_id=win_id, mode=usertypes.KeyMode.prompt, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.yesno: modeparsers.PromptKeyParser(win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.caret: modeparsers.CaretKeyParser(win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.set_mark: modeparsers.RegisterKeyParser(win_id=win_id, mode=usertypes.KeyMode.set_mark, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.jump_mark: modeparsers.RegisterKeyParser(win_id=win_id, mode=usertypes.KeyMode.jump_mark, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.record_macro: modeparsers.RegisterKeyParser(win_id=win_id, mode=usertypes.KeyMode.record_macro, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.run_macro: modeparsers.RegisterKeyParser(win_id=win_id, mode=usertypes.KeyMode.run_macro, commandrunner=commandrunner, parent=modeman), } # type: _ParserDictType objreg.register('keyparsers', keyparsers, scope='window', window=win_id) modeman.destroyed.connect( # type: ignore functools.partial(objreg.delete, 'keyparsers', scope='window', window=win_id)) for mode, parser in keyparsers.items(): modeman.register(mode, parser) return modeman
def init(win_id: int, parent: QObject) -> 'ModeManager': """Initialize the mode manager and the keyparsers for the given win_id.""" modeman = ModeManager(win_id, parent) objreg.register('mode-manager', modeman, scope='window', window=win_id) commandrunner = runners.CommandRunner(win_id) hintmanager = hints.HintManager(win_id, parent=parent) objreg.register('hintmanager', hintmanager, scope='window', window=win_id, command_only=True) keyparsers = { usertypes.KeyMode.normal: modeparsers.NormalKeyParser(win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.hint: modeparsers.HintKeyParser(win_id=win_id, commandrunner=commandrunner, hintmanager=hintmanager, parent=modeman), usertypes.KeyMode.insert: modeparsers.CommandKeyParser(mode=usertypes.KeyMode.insert, win_id=win_id, commandrunner=commandrunner, parent=modeman, passthrough=True, do_log=False, supports_count=False), usertypes.KeyMode.passthrough: modeparsers.CommandKeyParser(mode=usertypes.KeyMode.passthrough, win_id=win_id, commandrunner=commandrunner, parent=modeman, passthrough=True, do_log=False, supports_count=False), usertypes.KeyMode.command: modeparsers.CommandKeyParser(mode=usertypes.KeyMode.command, win_id=win_id, commandrunner=commandrunner, parent=modeman, passthrough=True, do_log=False, supports_count=False), usertypes.KeyMode.prompt: modeparsers.CommandKeyParser(mode=usertypes.KeyMode.prompt, win_id=win_id, commandrunner=commandrunner, parent=modeman, passthrough=True, do_log=False, supports_count=False), usertypes.KeyMode.yesno: modeparsers.CommandKeyParser(mode=usertypes.KeyMode.yesno, win_id=win_id, commandrunner=commandrunner, parent=modeman, supports_count=False), usertypes.KeyMode.caret: modeparsers.CommandKeyParser(mode=usertypes.KeyMode.caret, win_id=win_id, commandrunner=commandrunner, parent=modeman, passthrough=True), usertypes.KeyMode.set_mark: modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.set_mark, win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.jump_mark: modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.jump_mark, win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.record_macro: modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.record_macro, win_id=win_id, commandrunner=commandrunner, parent=modeman), usertypes.KeyMode.run_macro: modeparsers.RegisterKeyParser(mode=usertypes.KeyMode.run_macro, win_id=win_id, commandrunner=commandrunner, parent=modeman), } # type: ParserDictType for mode, parser in keyparsers.items(): modeman.register(mode, parser) return modeman
def keyparser(self, commandrunner): kp = modeparsers.NormalKeyParser(win_id=0, commandrunner=commandrunner) return kp