Python PyQt5.QtCore.Qt.Key_A() Examples

The following are 29 code examples of PyQt5.QtCore.Qt.Key_A(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore.Qt , or try the search function .
Example #1
Source File: Area.py    From Python-Application with GNU General Public License v3.0 6 votes vote down vote up
def left(self):
        self.widget.switch_page(right=False)
        
        
        
    #def keyPressEvent(self, event):
        #这里event.key()显示的是按键的编码
        #print("按下:" + str(event.key()))
        # 举例,这里Qt.Key_A注意虽然字母大写,但按键事件对大小写不敏感
        #if (event.key() == Qt.Key_Left):
        #    self.widget.switch_page(right=False)
        #elif (event.key() == Qt.Key_Right):
        #    self.widget.switch_page(right=True)
        #elif (event.modifiers() == Qt.CTRL and event.key() == Qt.Key_Plus):
        #    self.widget.zoom_book(plus=True)
        #elif (event.modifiers() == Qt.CTRL and event.key() == Qt.Key_Minus):
        #    self.widget.zoom_book(plus=False) 
Example #2
Source File: test_panes.py    From mu with GNU General Public License v3.0 6 votes vote down vote up
def test_MicroPythonREPLPane_keyPressEvent_meta(qtapp):
    """
    Ensure backspaces in the REPL are handled correctly.
    """
    mock_serial = mock.MagicMock()
    rp = mu.interface.panes.MicroPythonREPLPane(mock_serial)
    data = mock.MagicMock
    data.key = mock.MagicMock(return_value=Qt.Key_M)
    data.text = mock.MagicMock(return_value="a")
    if platform.system() == "Darwin":
        data.modifiers = mock.MagicMock(return_value=Qt.MetaModifier)
    else:
        data.modifiers = mock.MagicMock(return_value=Qt.ControlModifier)
    rp.keyPressEvent(data)
    expected = 1 + Qt.Key_M - Qt.Key_A
    mock_serial.write.assert_called_once_with(bytes([expected])) 
Example #3
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_fake_mac(self, modifiers, expected):
        """Make sure Control/Meta are swapped with a simulated Mac."""
        seq = keyutils.KeySequence()
        info = keyutils.KeyInfo(key=Qt.Key_A, modifiers=modifiers)
        new = seq.append_event(info.to_event())
        assert new[0] == keyutils.KeyInfo(Qt.Key_A, expected) 
Example #4
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_PythonProcessPane_parse_input_non_ascii(qtapp):
    """
    Ensure a non-ascii printable character is inserted into the text area.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.insert = mock.MagicMock()
    key = Qt.Key_A
    text = "Å"
    modifiers = None
    ppp.parse_input(key, text, modifiers)
    ppp.insert.assert_called_once_with("Å".encode("utf-8")) 
Example #5
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_PythonProcessPane_parse_input_a(qtapp):
    """
    Ensure a regular printable character is inserted into the text area.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.insert = mock.MagicMock()
    key = Qt.Key_A
    text = "a"
    modifiers = None
    ppp.parse_input(key, text, modifiers)
    ppp.insert.assert_called_once_with(b"a") 
Example #6
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_PythonProcessPane_keyPressEvent_a(qtapp):
    """
    A character is typed and passed into parse_input in the expected manner.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.parse_input = mock.MagicMock()
    data = mock.MagicMock
    data.key = mock.MagicMock(return_value=Qt.Key_A)
    data.text = mock.MagicMock(return_value="a")
    data.modifiers = mock.MagicMock(return_value=None)
    ppp.keyPressEvent(data)
    ppp.parse_input.assert_called_once_with(Qt.Key_A, "a", None) 
Example #7
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_MicroPythonREPLPane_keyPressEvent(qtapp):
    """
    Ensure key presses in the REPL are handled correctly.
    """
    mock_serial = mock.MagicMock()
    rp = mu.interface.panes.MicroPythonREPLPane(mock_serial)
    data = mock.MagicMock
    data.key = mock.MagicMock(return_value=Qt.Key_A)
    data.text = mock.MagicMock(return_value="a")
    data.modifiers = mock.MagicMock(return_value=None)
    rp.keyPressEvent(data)
    mock_serial.write.assert_called_once_with(bytes("a", "utf-8")) 
Example #8
Source File: client.py    From SunFounder_PiCar-V with GNU General Public License v2.0 5 votes vote down vote up
def keyReleaseEvent(self, event):
		"""Keyboard released event

		Effective key: W,A,S,D, ↑,  ↓,  ←,  →
		Release a key on keyboard, the function will get an event, if the condition is met, call the function 
		run_action(). 

		Args:
			event, this argument will get when an event of keyboard release occured

		"""
		# don't need autorepeat, while haven't pressed, just run once
		key_release = event.key()
		if not event.isAutoRepeat():
			if key_release == Qt.Key_Up:		# up
				run_action('camready')
			elif key_release == Qt.Key_Right:	# right
				run_action('camready')
			elif key_release == Qt.Key_Down:	# down
				run_action('camready')
			elif key_release == Qt.Key_Left:	# left
				run_action('camready')
			elif key_release == Qt.Key_W:		# W
				run_action('stop')
			elif key_release == Qt.Key_A:		# A
				run_action('fwstraight')
			elif key_release == Qt.Key_S:		# S
				run_action('stop')
			elif key_release == Qt.Key_D:		# D
				run_action('fwstraight') 
Example #9
Source File: client.py    From SunFounder_PiCar-V with GNU General Public License v2.0 5 votes vote down vote up
def keyPressEvent(self, event):
		"""Keyboard press event

		Effective key: W, A, S, D, ↑,  ↓,  ←,  →
		Press a key on keyboard, the function will get an event, if the condition is met, call the function 
		run_action(). 

		Args:
			event, this argument will get when an event of keyboard pressed occured

		"""
		key_press = event.key()

		# don't need autorepeat, while haven't released, just run once
		if not event.isAutoRepeat():
			if key_press == Qt.Key_Up:			# up 
				run_action('camup')
			elif key_press == Qt.Key_Right:		# right
				run_action('camright')
			elif key_press == Qt.Key_Down:		# down
				run_action('camdown')
			elif key_press == Qt.Key_Left:		# left
				run_action('camleft')
			elif key_press == Qt.Key_W:			# W
				run_action('forward')
			elif key_press == Qt.Key_A:			# A
				run_action('fwleft')
			elif key_press == Qt.Key_S:			# S
				run_action('backward')
			elif key_press == Qt.Key_D:			# D
				run_action('fwright') 
Example #10
Source File: gui.py    From lanzou-gui with MIT License 5 votes vote down vote up
def keyPressEvent(self, e):
        if e.key() == Qt.Key_A:  # Ctrl/Alt + A 全选
            if e.modifiers() and Qt.ControlModifier:
                self.select_all_btn()
        elif e.key() == Qt.Key_F5:  # 刷新
            self.call_change_tab() 
Example #11
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_key_info_to_int():
    info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier)
    assert info.to_int() == Qt.Key_A | Qt.ShiftModifier 
Example #12
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_key_info_to_event():
    info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier)
    ev = info.to_event()
    assert ev.key() == Qt.Key_A
    assert ev.modifiers() == Qt.ShiftModifier
    assert ev.text() == 'A' 
Example #13
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_key_info_from_event():
    ev = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.ShiftModifier, 'A')
    info = keyutils.KeyInfo.from_event(ev)
    assert info.key == Qt.Key_A
    assert info.modifiers == Qt.ShiftModifier 
Example #14
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_valid_key(self, prompt_keyparser, handle_text):
        modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier

        infos = [
            keyutils.KeyInfo(Qt.Key_A, modifier),
            keyutils.KeyInfo(Qt.Key_X, modifier),
        ]
        for info in infos:
            prompt_keyparser.handle(info.to_event())

        prompt_keyparser.execute.assert_called_once_with(
            'message-info ctrla', None)
        assert not prompt_keyparser._sequence 
Example #15
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_repr(self):
        seq = keyutils.KeySequence(Qt.Key_A | Qt.ControlModifier,
                                   Qt.Key_B | Qt.ShiftModifier)
        assert repr(seq) == ("<qutebrowser.keyinput.keyutils.KeySequence "
                             "keys='<Ctrl+a>B'>") 
Example #16
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_iter(self):
        seq = keyutils.KeySequence(Qt.Key_A | Qt.ControlModifier,
                                   Qt.Key_B | Qt.ShiftModifier,
                                   Qt.Key_C,
                                   Qt.Key_D,
                                   Qt.Key_E)
        expected = [keyutils.KeyInfo(Qt.Key_A, Qt.ControlModifier),
                    keyutils.KeyInfo(Qt.Key_B, Qt.ShiftModifier),
                    keyutils.KeyInfo(Qt.Key_C, Qt.NoModifier),
                    keyutils.KeyInfo(Qt.Key_D, Qt.NoModifier),
                    keyutils.KeyInfo(Qt.Key_E, Qt.NoModifier)]
        assert list(seq) == expected 
Example #17
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_init(self):
        seq = keyutils.KeySequence(Qt.Key_A, Qt.Key_B, Qt.Key_C, Qt.Key_D,
                                   Qt.Key_E)
        assert len(seq._sequences) == 2
        assert len(seq._sequences[0]) == 4
        assert len(seq._sequences[1]) == 1 
Example #18
Source File: test_keyutils.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_missing(self, monkeypatch):
        monkeypatch.delattr(keyutils.Qt, 'Key_AltGr')
        # We don't want to test the key which is actually missing - we only
        # want to know if the mapping still behaves properly.
        assert keyutils._key_to_string(Qt.Key_A) == 'A' 
Example #19
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_numpad(self, prompt_keyparser):
        """Make sure we can enter a count via numpad."""
        for key, modifiers in [(Qt.Key_4, Qt.KeypadModifier),
                               (Qt.Key_2, Qt.KeypadModifier),
                               (Qt.Key_B, Qt.NoModifier),
                               (Qt.Key_A, Qt.NoModifier)]:
            info = keyutils.KeyInfo(key, modifiers)
            prompt_keyparser.handle(info.to_event())
        prompt_keyparser.execute.assert_called_once_with('message-info ba', 42) 
Example #20
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_superscript(self, handle_text, prompt_keyparser):
        # https://github.com/qutebrowser/qutebrowser/issues/3743
        handle_text(prompt_keyparser, Qt.Key_twosuperior, Qt.Key_B, Qt.Key_A) 
Example #21
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_count_42(self, handle_text, prompt_keyparser):
        handle_text(prompt_keyparser, Qt.Key_4, Qt.Key_2, Qt.Key_B, Qt.Key_A)
        prompt_keyparser.execute.assert_called_once_with('message-info ba', 42)
        assert not prompt_keyparser._sequence 
Example #22
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_count_0(self, handle_text, prompt_keyparser):
        handle_text(prompt_keyparser, Qt.Key_0, Qt.Key_B, Qt.Key_A)
        calls = [mock.call('message-info 0', None),
                 mock.call('message-info ba', None)]
        prompt_keyparser.execute.assert_has_calls(calls)
        assert not prompt_keyparser._sequence 
Example #23
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_no_count(self, handle_text, prompt_keyparser):
        """Test with no count added."""
        handle_text(prompt_keyparser, Qt.Key_B, Qt.Key_A)
        prompt_keyparser.execute.assert_called_once_with(
            'message-info ba', None)
        assert not prompt_keyparser._sequence 
Example #24
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_mapping_in_key_chain(self, config_stub, handle_text, keyparser):
        """A mapping should work even as part of a keychain."""
        config_stub.val.bindings.commands = {'normal':
                                             {'aa': 'message-info aa'}}
        handle_text(keyparser, Qt.Key_A, Qt.Key_X)
        keyparser.execute.assert_called_once_with('message-info aa', None) 
Example #25
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_valid_keychain(self, handle_text, prompt_keyparser):
        handle_text(prompt_keyparser,
                    # Press 'x' which is ignored because of no match
                    Qt.Key_X,
                    # Then start the real chain
                    Qt.Key_B, Qt.Key_A)
        prompt_keyparser.execute.assert_called_with('message-info ba', None)
        assert not prompt_keyparser._sequence 
Example #26
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_dry_run(self, prompt_keyparser):
        b_info = keyutils.KeyInfo(Qt.Key_B, Qt.NoModifier)
        prompt_keyparser.handle(b_info.to_event())

        a_info = keyutils.KeyInfo(Qt.Key_A, Qt.NoModifier)
        prompt_keyparser.handle(a_info.to_event(), dry_run=True)

        assert not prompt_keyparser.execute.called
        assert prompt_keyparser._sequence 
Example #27
Source File: test_basekeyparser.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def test_valid_key_count(self, prompt_keyparser):
        modifier = Qt.MetaModifier if utils.is_mac else Qt.ControlModifier

        infos = [
            keyutils.KeyInfo(Qt.Key_5, Qt.NoModifier),
            keyutils.KeyInfo(Qt.Key_A, modifier),
        ]
        for info in infos:
            prompt_keyparser.handle(info.to_event())
        prompt_keyparser.execute.assert_called_once_with(
            'message-info ctrla', 5) 
Example #28
Source File: client.py    From SunFounder_PiCar-V with GNU General Public License v2.0 4 votes vote down vote up
def keyPressEvent(self, event):
		"""Keyboard press event

		Press a key on keyboard, the function will get an event, if the condition is met, call the function 
		run_action(). 
		In camera calibration mode, Effective key: W,A,S,D, ↑,  ↓,  ←,  →, ESC
		In front wheel calibration mode, Effective key: A, D, ←,  →, ESC
		In back wheel calibration mode, Effective key: A, D, ←,  →, ESC
		
		Args:
			event, this argument will get when an event of keyboard pressed occured

		"""
		key_press = event.key()

		if key_press in (Qt.Key_Up, Qt.Key_W):    	# UP
			if   self.calibration_status == 1:
				cali_action('camcaliup')
			elif self.calibration_status == 2:
				pass
			elif self.calibration_status == 3:
				pass
		elif key_press in (Qt.Key_Right, Qt.Key_D):	# RIGHT
			if   self.calibration_status == 1:
				cali_action('camcaliright')
			elif self.calibration_status == 2:
				cali_action('fwcaliright')
			elif self.calibration_status == 3:
				cali_action('bwcaliright')
		elif key_press in (Qt.Key_Down, Qt.Key_S):	# DOWN
			if   self.calibration_status == 1:
				cali_action('camcalidown')
			elif self.calibration_status == 2:
				pass
			elif self.calibration_status == 3:
				pass
		elif key_press in (Qt.Key_Left, Qt.Key_A):	# LEFT
			if   self.calibration_status == 1:
				cali_action('camcalileft')
			elif self.calibration_status == 2:
				cali_action('fwcalileft')
			elif self.calibration_status == 3:
				cali_action('bwcalileft')
				cali_action('forward')
		elif key_press == Qt.Key_Escape:			# ESC
			run_action('stop')
			self.close() 
Example #29
Source File: forward_keyboard.py    From MaixPy_scripts with MIT License 4 votes vote down vote up
def keyPressEvent(self, event):
        print(event.key())
        if event.key() == Qt.Key_M:
            self.send_flag = False
            self.com.write(b"m")
            self.send_flag = False
        elif event.key() == Qt.Key_Return or event.key()==Qt.Key_Enter:
            self.send_flag = False
            self.com.write(b"m")
            self.send_flag = False
        elif event.key() == Qt.Key_N or event.key() == 92:
            self.send_flag = False
            self.com.write(b"n")
            self.send_flag = False
        elif event.key() == Qt.Key_Minus:
            self.send_flag = False
            self.com.write(b"-")
            self.send_flag = False
        elif event.key() == Qt.Key_Equal:
            self.send_flag = False
            self.com.write(b"=")
            self.send_flag = False
        elif event.key() == Qt.Key_W or event.key() == Qt.Key_Up:
            self.send_flag = True
            self.key.append(b"w")
        elif event.key() == Qt.Key_A or event.key() == Qt.Key_Left:
            self.send_flag = True
            self.key.append(b"a")
        elif event.key() == Qt.Key_S or event.key() == Qt.Key_Down:
            self.send_flag = True
            self.key.append(b"s")
        elif event.key() == Qt.Key_D or event.key() == Qt.Key_Right:
            self.send_flag = True
            self.key.append(b"d")
        elif event.key() == Qt.Key_J:
            self.send_flag = True
            self.key.append(b"j")
        elif event.key() == Qt.Key_K:
            self.send_flag = True
            self.key.append(b"k")
        elif event.key() == Qt.Key_Escape:
            self.send_flag = False
            self.com.write(b"\x03")
        elif event.key() == Qt.Key_Control:
            self.keyControlPressed = True
        elif event.key() == Qt.Key_C:
            if self.keyControlPressed:
                self.send_flag = False
                self.com.write(b"\x03")
        # self.key_label.setText(self.key.decode())