Skip to content

Commit

Permalink
Merge pull request matplotlib#20868 from tacaswell/fix_qt_key_mods
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm authored Aug 20, 2021
2 parents af68218 + 86be6bc commit 54b105b
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 54b105b

Please sign in to comment.