Python源码示例:PyQt5.QtCore.Qt.Key_A()
示例1
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]))
示例2
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)
示例3
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
示例4
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)
示例5
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
示例6
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
示例7
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)
示例8
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
示例9
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
示例10
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
示例11
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)
示例12
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)
示例13
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'
示例14
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
示例15
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
示例16
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'>")
示例17
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)
示例18
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
示例19
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'
示例20
def test_key_info_to_int():
info = keyutils.KeyInfo(Qt.Key_A, Qt.ShiftModifier)
assert info.to_int() == Qt.Key_A | Qt.ShiftModifier
示例21
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()
示例22
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')
示例23
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')
示例24
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"))
示例25
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)
示例26
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")
示例27
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"))
示例28
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()
示例29
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())