@@ -107,6 +107,8 @@ def CustomHandler(signum, frame):
107107 ('Key_Alt' , ['ControlModifier' ], 'ctrl+alt' ),
108108 ('Key_Aacute' , ['ControlModifier' , 'AltModifier' , 'MetaModifier' ],
109109 'ctrl+alt+super+\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