Skip to content

Commit 54b105b

Browse files
authored
Merge pull request matplotlib#20868 from tacaswell/fix_qt_key_mods
2 parents af68218 + 86be6bc commit 54b105b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/tests/test_backend_qt.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def CustomHandler(signum, frame):
106106
('Key_Control', ['AltModifier'], 'alt+control'),
107107
('Key_Alt', ['ControlModifier'], 'ctrl+alt'),
108108
('Key_Aacute', ['ControlModifier', 'AltModifier', 'MetaModifier'],
109-
'ctrl+alt+super+\N{LATIN SMALL LETTER A WITH ACUTE}'),
109+
'ctrl+alt+meta+\N{LATIN SMALL LETTER A WITH ACUTE}'),
110+
# We do not currently map the media keys, this may change in the
111+
# future. This means the callback will never fire
110112
('Key_Play', [], None),
111113
('Key_Backspace', [], 'backspace'),
112114
('Key_Backspace', ['ControlModifier'], 'ctrl+backspace'),
@@ -142,6 +144,7 @@ def test_correct_key(backend, qt_core, qt_key, qt_mods, answer):
142144
Assert sent and caught keys are the same.
143145
"""
144146
from matplotlib.backends.qt_compat import _enum, _to_int
147+
result = None
145148
qt_mod = _enum("QtCore.Qt.KeyboardModifier").NoModifier
146149
for mod in qt_mods:
147150
qt_mod |= getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)
@@ -152,11 +155,13 @@ def key(self): return _to_int(getattr(_enum("QtCore.Qt.Key"), qt_key))
152155
def modifiers(self): return qt_mod
153156

154157
def on_key_press(event):
155-
assert event.key == answer
158+
nonlocal result
159+
result = event.key
156160

157161
qt_canvas = plt.figure().canvas
158162
qt_canvas.mpl_connect('key_press_event', on_key_press)
159163
qt_canvas.keyPressEvent(_Event())
164+
assert result == answer
160165

161166

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

0 commit comments

Comments
 (0)