Пример #1
0
    def handle(self, e, *, dry_run=False):
        """Handle a new keypress and call the respective handlers.

        Args:
            e: the KeyPressEvent from Qt
            dry_run: Don't actually execute anything, only check whether there
                     would be a match.

        Returns:
            True if the match has been handled, False otherwise.
        """
        dry_run_match = super().handle(e, dry_run=True)
        if dry_run:
            return dry_run_match

        if keyutils.is_special(e.key(), e.modifiers()):
            log.keyboard.debug("Got special key, clearing keychain")
            self.clear_keystring()

        assert not dry_run
        match = super().handle(e)

        if match == QKeySequence.PartialMatch:
            self._last_press = LastPress.keystring
        elif match == QKeySequence.ExactMatch:
            self._last_press = LastPress.none
        elif match == QKeySequence.NoMatch:
            # We couldn't find a keychain so we check if it's a special key.
            return self._handle_filter_key(e)
        else:
            raise ValueError("Got invalid match type {}!".format(match))

        return match
Пример #2
0
    def handle(self, e, *, dry_run=False):
        """Handle a new keypress and call the respective handlers.

        Args:
            e: the KeyPressEvent from Qt
            dry_run: Don't actually execute anything, only check whether there
                     would be a match.

        Returns:
            True if the match has been handled, False otherwise.
        """
        if dry_run:
            return super().handle(e, dry_run=True)

        if keyutils.is_special(e.key(), e.modifiers()):
            log.keyboard.debug("Got special key, clearing keychain")
            self.clear_keystring()

        assert not dry_run
        match = super().handle(e)

        if match == QKeySequence.PartialMatch:
            self._last_press = LastPress.keystring
        elif match == QKeySequence.ExactMatch:
            self._last_press = LastPress.none
        elif match == QKeySequence.NoMatch:
            # We couldn't find a keychain so we check if it's a special key.
            return self._handle_filter_key(e)
        else:
            raise ValueError("Got invalid match type {}!".format(match))

        return match
Пример #3
0
    def handle(self, e: QKeyEvent, *,
               dry_run: bool = False) -> QKeySequence.SequenceMatch:
        """Override to always match the next key and use the register."""
        match = super().handle(e, dry_run=dry_run)
        if match or dry_run:
            return match

        if keyutils.is_special(Qt.Key(e.key()), e.modifiers()):
            # this is not a proper register key, let it pass and keep going
            return QKeySequence.NoMatch

        key = e.text()

        tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                    window=self._win_id)

        try:
            if self._register_mode == usertypes.KeyMode.set_mark:
                tabbed_browser.set_mark(key)
            elif self._register_mode == usertypes.KeyMode.jump_mark:
                tabbed_browser.jump_mark(key)
            elif self._register_mode == usertypes.KeyMode.record_macro:
                macros.macro_recorder.record_macro(key)
            elif self._register_mode == usertypes.KeyMode.run_macro:
                macros.macro_recorder.run_macro(self._win_id, key)
            else:
                raise ValueError("{} is not a valid register mode".format(
                    self._register_mode))
        except cmdexc.Error as err:
            message.error(str(err), stack=traceback.format_exc())

        self.request_leave.emit(
            self._register_mode, "valid register key", True)
        return QKeySequence.ExactMatch
Пример #4
0
    def handle(self, e, *, dry_run=False):
        """Override handle to always match the next key and use the register.

        Args:
            e: the KeyPressEvent from Qt.
            dry_run: Don't actually execute anything, only check whether there
                     would be a match.

        Return:
            True if event has been handled, False otherwise.
        """
        match = super().handle(e, dry_run=dry_run)
        if match or dry_run:
            return match

        if keyutils.is_special(e.key(), e.modifiers()):
            # this is not a proper register key, let it pass and keep going
            return QKeySequence.NoMatch

        key = e.text()

        tabbed_browser = objreg.get('tabbed-browser',
                                    scope='window',
                                    window=self._win_id)
        macro_recorder = objreg.get('macro-recorder')

        try:
            if self._mode == usertypes.KeyMode.set_mark:
                tabbed_browser.set_mark(key)
            elif self._mode == usertypes.KeyMode.jump_mark:
                tabbed_browser.jump_mark(key)
            elif self._mode == usertypes.KeyMode.record_macro:
                macro_recorder.record_macro(key)
            elif self._mode == usertypes.KeyMode.run_macro:
                macro_recorder.run_macro(self._win_id, key)
            else:
                raise ValueError("{} is not a valid register mode".format(
                    self._mode))
        except cmdexc.Error as err:
            message.error(str(err), stack=traceback.format_exc())

        self.request_leave.emit(self._mode, "valid register key", True)
        return QKeySequence.ExactMatch
Пример #5
0
    def handle(self, e, *, dry_run=False):
        """Override handle to always match the next key and use the register.

        Args:
            e: the KeyPressEvent from Qt.
            dry_run: Don't actually execute anything, only check whether there
                     would be a match.

        Return:
            True if event has been handled, False otherwise.
        """
        match = super().handle(e, dry_run=dry_run)
        if match or dry_run:
            return match

        if keyutils.is_special(e.key(), e.modifiers()):
            # this is not a proper register key, let it pass and keep going
            return QKeySequence.NoMatch

        key = e.text()

        tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                    window=self._win_id)
        macro_recorder = objreg.get('macro-recorder')

        try:
            if self._mode == usertypes.KeyMode.set_mark:
                tabbed_browser.set_mark(key)
            elif self._mode == usertypes.KeyMode.jump_mark:
                tabbed_browser.jump_mark(key)
            elif self._mode == usertypes.KeyMode.record_macro:
                macro_recorder.record_macro(key)
            elif self._mode == usertypes.KeyMode.run_macro:
                macro_recorder.run_macro(self._win_id, key)
            else:
                raise ValueError(
                    "{} is not a valid register mode".format(self._mode))
        except cmdexc.Error as err:
            message.error(str(err), stack=traceback.format_exc())

        self.request_leave.emit(self._mode, "valid register key", True)
        return QKeySequence.ExactMatch
Пример #6
0
def test_is_special(key, modifiers, special):
    assert keyutils.is_special(key, modifiers) == special
Пример #7
0
def test_is_printable(key, printable):
    assert keyutils._is_printable(key) == printable
    assert keyutils.is_special(key, Qt.NoModifier) != printable
Пример #8
0
def test_is_special(key, modifiers, special):
    assert keyutils.is_special(key, modifiers) == special
Пример #9
0
def test_is_printable(key, printable):
    assert keyutils._is_printable(key) == printable
    assert keyutils.is_special(key, Qt.NoModifier) != printable