Ejemplo n.º 1
0
    def handle(self,
               e: QKeyEvent,
               *,
               dry_run: bool = False) -> QKeySequence.SequenceMatch:
        """Handle a new keypress and call the respective handlers."""
        if dry_run:
            return super().handle(e, dry_run=True)

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

        if dry_run:
            raise AssertionError
        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
Ejemplo n.º 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_hint_mode(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
Ejemplo n.º 3
0
def test_is_special_hint_mode(key, modifiers, special):
    assert keyutils.is_special_hint_mode(key, modifiers) == special