Exemplo n.º 1
0
 def test_key_and_modifiers(self, fake_keyevent_factory):
     """Test with key and multiple modifier pressed."""
     evt = fake_keyevent_factory(
         key=Qt.Key_A, modifiers=(Qt.ControlModifier | Qt.AltModifier |
                                  Qt.MetaModifier | Qt.ShiftModifier))
     if sys.platform == 'darwin':
         assert utils.keyevent_to_string(evt) == 'Ctrl+Alt+Shift+A'
     else:
         assert utils.keyevent_to_string(evt) == 'Ctrl+Alt+Meta+Shift+A'
Exemplo n.º 2
0
 def test_key_and_modifiers(self, fake_keyevent_factory):
     """Test with key and multiple modifier pressed."""
     evt = fake_keyevent_factory(
         key=Qt.Key_A,
         modifiers=(Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier
                    | Qt.ShiftModifier))
     if sys.platform == 'darwin':
         assert utils.keyevent_to_string(evt) == 'Ctrl+Alt+Shift+A'
     else:
         assert utils.keyevent_to_string(evt) == 'Ctrl+Alt+Meta+Shift+A'
Exemplo n.º 3
0
 def test_key_and_modifiers(self):
     """Test with key and multiple modifier pressed."""
     evt = helpers.fake_keyevent(
         key=Qt.Key_A, modifiers=(Qt.ControlModifier | Qt.AltModifier |
                                  Qt.MetaModifier | Qt.ShiftModifier))
     if sys.platform == 'darwin':
         self.assertEqual(utils.keyevent_to_string(evt),
                          'Ctrl+Alt+Shift+A')
     else:
         self.assertEqual(utils.keyevent_to_string(evt),
                          'Ctrl+Alt+Meta+Shift+A')
Exemplo n.º 4
0
 def test_key_and_modifiers(self):
     """Test with key and multiple modifier pressed."""
     evt = helpers.fake_keyevent(
         key=Qt.Key_A,
         modifiers=(Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier
                    | Qt.ShiftModifier))
     if sys.platform == 'darwin':
         self.assertEqual(utils.keyevent_to_string(evt), 'Ctrl+Alt+Shift+A')
     else:
         self.assertEqual(utils.keyevent_to_string(evt),
                          'Ctrl+Alt+Meta+Shift+A')
Exemplo n.º 5
0
    def handle(self, e):
        """Override handle to always match the next key and create a mark.

        Args:
            e: the KeyPressEvent from Qt.

        Return:
            True if event has been handled, False otherwise.
        """
        if utils.keyevent_to_string(e) is None:
            # this is a modifier key, let it pass and keep going
            return False

        key = e.text()

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

        if self._mode == usertypes.KeyMode.set_mark:
            tabbed_browser.set_mark(key)
        elif self._mode == usertypes.KeyMode.jump_mark:
            tabbed_browser.jump_mark(key)
        else:
            raise ValueError("{} is not a valid mark mode".format(self._mode))

        self.request_leave.emit(self._mode, "valid mark key")

        return True
Exemplo n.º 6
0
    def _handle_special_key(self, e):
        """Handle a new keypress with special keys (<Foo>).

        Return True if the keypress has been handled, and False if not.

        Args:
            e: the KeyPressEvent from Qt.

        Return:
            True if event has been handled, False otherwise.
        """
        binding = utils.keyevent_to_string(e)
        if binding is None:
            self._debug_log("Ignoring only-modifier keyeevent.")
            return False
        binding = binding.lower()
        try:
            cmdstr = self.special_bindings[binding]
        except KeyError:
            self._debug_log("No special binding found for {}.".format(binding))
            return False
        count, _command = self._split_count()
        self.execute(cmdstr, self.Type.special, count)
        self.clear_keystring()
        return True
Exemplo n.º 7
0
    def handle(self, e):
        """Override handle to always match the next key and create a mark.

        Args:
            e: the KeyPressEvent from Qt.

        Return:
            True if event has been handled, False otherwise.
        """
        if utils.keyevent_to_string(e) is None:
            # this is a modifier key, let it pass and keep going
            return False

        key = e.text()

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

        if self._mode == usertypes.KeyMode.set_mark:
            tabbed_browser.set_mark(key)
        elif self._mode == usertypes.KeyMode.jump_mark:
            tabbed_browser.jump_mark(key)
        else:
            raise ValueError("{} is not a valid mark mode".format(self._mode))

        self.request_leave.emit(self._mode, "valid mark key")

        return True
Exemplo n.º 8
0
    def _handle_special_key(self, e):
        """Handle a new keypress with special keys (<Foo>).

        Return True if the keypress has been handled, and False if not.

        Args:
            e: the KeyPressEvent from Qt.

        Return:
            True if event has been handled, False otherwise.
        """
        binding = utils.keyevent_to_string(e)
        if binding is None:
            self._debug_log("Ignoring only-modifier keyeevent.")
            return False
        binding = binding.lower()
        try:
            cmdstr = self.special_bindings[binding]
        except KeyError:
            self._debug_log("No special binding found for {}.".format(binding))
            return False
        count, _command = self._split_count()
        self.execute(cmdstr, self.Type.special, count)
        self.clear_keystring()
        return True
Exemplo n.º 9
0
 def keyPressEvent(self, e):
     """Show pressed keys."""
     lines = [
         str(utils.keyevent_to_string(e)),
         '',
         'key: 0x{:x}'.format(int(e.key())),
         'modifiers: 0x{:x}'.format(int(e.modifiers())),
         'text: {!r}'.format(e.text()),
     ]
     self._label.setText('\n'.join(lines))
Exemplo n.º 10
0
    def handle(self, e):
        """Override handle to always match the next key and use the register.

        Args:
            e: the KeyPressEvent from Qt.

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

        key = e.text()

        if key == '' or utils.keyevent_to_string(e) is None:
            # this is not a proper register key, let it pass and keep going
            return False

        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 True
Exemplo n.º 11
0
    def handle(self, e):
        """Override handle to always match the next key and use the register.

        Args:
            e: the KeyPressEvent from Qt.

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

        if utils.keyevent_to_string(e) is None:
            # this is a modifier key, let it pass and keep going
            return False

        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.CommandMetaError, cmdexc.CommandError) as err:
            message.error(str(err), stack=traceback.format_exc())

        self.request_leave.emit(self._mode, "valid register key", True)

        return True
Exemplo n.º 12
0
 def test_key_and_modifier(self, fake_keyevent_factory):
     """Test with key and modifier pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     assert utils.keyevent_to_string(evt) == 'Ctrl+A'
Exemplo n.º 13
0
 def test_only_key(self, fake_keyevent_factory):
     """Test with a simple key pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_A)
     assert utils.keyevent_to_string(evt) == 'A'
Exemplo n.º 14
0
 def test_only_hyper_l(self, fake_keyevent_factory):
     """Test keyeevent when only Hyper_L is pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_Hyper_L,
                                 modifiers=Qt.MetaModifier)
     assert utils.keyevent_to_string(evt) is None
Exemplo n.º 15
0
 def test_only_control(self, fake_keyevent_factory):
     """Test keyeevent when only control is pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_Control,
                                 modifiers=Qt.ControlModifier)
     assert utils.keyevent_to_string(evt) is None
Exemplo n.º 16
0
 def test_key_and_modifier(self, fake_keyevent_factory):
     """Test with key and modifier pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     assert utils.keyevent_to_string(evt) == 'Ctrl+A'
Exemplo n.º 17
0
 def test_only_key(self):
     """Test with a simple key pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A)
     self.assertEqual(utils.keyevent_to_string(evt), 'A')
Exemplo n.º 18
0
 def test_only_hyper_l(self):
     """Test keyeevent when only Hyper_L is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Hyper_L,
                                 modifiers=Qt.MetaModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
Exemplo n.º 19
0
 def test_only_control(self):
     """Test keyeevent when only control is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Control,
                                 modifiers=Qt.ControlModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
Exemplo n.º 20
0
 def test_only_hyper_l(self, fake_keyevent_factory):
     """Test keyeevent when only Hyper_L is pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_Hyper_L,
                                 modifiers=Qt.MetaModifier)
     assert utils.keyevent_to_string(evt) is None
Exemplo n.º 21
0
 def test_key_and_modifier(self, fake_keyevent_factory):
     """Test with key and modifier pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     expected = 'Meta+A' if sys.platform == 'darwin' else 'Ctrl+A'
     assert utils.keyevent_to_string(evt) == expected
Exemplo n.º 22
0
 def test_only_control(self):
     """Test keyeevent when only control is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Control,
                                 modifiers=Qt.ControlModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
Exemplo n.º 23
0
 def test_only_hyper_l(self):
     """Test keyeevent when only Hyper_L is pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_Hyper_L,
                                 modifiers=Qt.MetaModifier)
     self.assertIsNone(utils.keyevent_to_string(evt))
Exemplo n.º 24
0
 def test_only_key(self, fake_keyevent_factory):
     """Test with a simple key pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_A)
     assert utils.keyevent_to_string(evt) == 'A'
Exemplo n.º 25
0
 def test_only_key(self):
     """Test with a simple key pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A)
     self.assertEqual(utils.keyevent_to_string(evt), 'A')
Exemplo n.º 26
0
 def test_key_and_modifier(self):
     """Test with key and modifier pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     self.assertEqual(utils.keyevent_to_string(evt), 'Ctrl+A')
Exemplo n.º 27
0
 def test_only_control(self, fake_keyevent_factory):
     """Test keyeevent when only control is pressed."""
     evt = fake_keyevent_factory(key=Qt.Key_Control,
                                 modifiers=Qt.ControlModifier)
     assert utils.keyevent_to_string(evt) is None
Exemplo n.º 28
0
 def test_key_and_modifier(self):
     """Test with key and modifier pressed."""
     evt = helpers.fake_keyevent(key=Qt.Key_A, modifiers=Qt.ControlModifier)
     self.assertEqual(utils.keyevent_to_string(evt), 'Ctrl+A')