Skip to content

Fix qt key mods #20868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def CustomHandler(signum, frame):
('Key_Control', ['AltModifier'], 'alt+control'),
('Key_Alt', ['ControlModifier'], 'ctrl+alt'),
('Key_Aacute', ['ControlModifier', 'AltModifier', 'MetaModifier'],
'ctrl+alt+super+\N{LATIN SMALL LETTER A WITH ACUTE}'),
'ctrl+alt+meta+\N{LATIN SMALL LETTER A WITH ACUTE}'),
# We do not currently map the media keys, this may change in the
# future. This means the callback will never fire
('Key_Play', [], None),
('Key_Backspace', [], 'backspace'),
('Key_Backspace', ['ControlModifier'], 'ctrl+backspace'),
Expand Down Expand Up @@ -142,6 +144,7 @@ def test_correct_key(backend, qt_core, qt_key, qt_mods, answer):
Assert sent and caught keys are the same.
"""
from matplotlib.backends.qt_compat import _enum, _to_int
result = None
qt_mod = _enum("QtCore.Qt.KeyboardModifier").NoModifier
for mod in qt_mods:
qt_mod |= getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)
Expand All @@ -152,11 +155,13 @@ def key(self): return _to_int(getattr(_enum("QtCore.Qt.Key"), qt_key))
def modifiers(self): return qt_mod

def on_key_press(event):
assert event.key == answer
nonlocal result
result = event.key

qt_canvas = plt.figure().canvas
qt_canvas.mpl_connect('key_press_event', on_key_press)
qt_canvas.keyPressEvent(_Event())
assert result == answer


@pytest.mark.backend('QtAgg', skip_on_importerror=True)
Expand Down