-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #19128: webagg reports incorrect values for non-alphanumeric key events on non-qwerty keyboards #19146
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
Fix #19128: webagg reports incorrect values for non-alphanumeric key events on non-qwerty keyboards #19146
Changes from all commits
9a75c33
49db5c4
da8790a
89ce223
8682cf6
cfe86cc
f2c65cd
0da9d1e
0f9ab5e
ec45ae6
6a0ea71
3d97ec6
10f0d33
d469a24
16adba8
2227748
57d4c8a
84cdf22
a545253
87012a5
d19bdd7
d4ab1b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,35 @@ Event name Class Description | |
'axes_leave_event' `.LocationEvent` mouse leaves an axes | ||
====================== ================ ====================================== | ||
|
||
.. note:: | ||
When connecting to 'key_press_event' and 'key_release_event' events, | ||
you may encounter inconsistencies between the different user interface | ||
toolkits that Matplotlib works with. This is due to inconsistencies/limitations | ||
of the user interface toolkit. The following table shows some basic examples of | ||
what you may expect to receive as key(s) from the different user interface toolkits, | ||
where a comma separates different keys: | ||
|
||
============== ============================= ============================== ============================= ============================== ============================== | ||
Key(s) Pressed WxPython Qt WebAgg Gtk Tkinter | ||
============== ============================= ============================== ============================= ============================== ============================== | ||
Shift+2 shift, shift+2 shift, " shift, " shift, " shift, " | ||
Shift+F1 shift, shift+f1 shift, shift+f1 shift, shift+f1 shift, shift+f1 shift, shift+f1 | ||
Shift shift shift shift shift shift | ||
Control control control control control control | ||
Alt alt alt alt alt alt | ||
AltGr Nothing Nothing alt iso_level3_shift iso_level3_shift | ||
CapsLock caps_lock caps_lock caps_lock caps_lock caps_lock | ||
A a a A A A | ||
a a a a a a | ||
Shift+a shift, A shift, A shift, A shift, A shift, A | ||
Shift+A shift, A shift, A shift, a shift, a shift, a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What keyboard has a capital A already? Do you mean with caps lock on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I mean with caps lock on. |
||
Ctrl+Shift+Alt control, ctrl+shift, ctrl+alt control, ctrl+shift, ctrl+meta control, ctrl+shit, ctrl+meta control, ctrl+shift, ctrl+meta control, ctrl+shift, ctrl+meta | ||
Ctrl+Shift+a control, ctrl+shift, ctrl+A control, ctrl+shift, ctrl+A control, ctrl+shit, ctrl+A control, ctrl+shift, ctrl+A control, ctrl+shift, ctrl+a | ||
Ctrl+Shift+A control, ctrl+shift, ctrl+A control, ctrl+shift, ctrl+A control, ctrl+shit, ctrl+a control, ctrl+shift, ctrl+a control, ctrl+shift, ctrl+a | ||
F1 f1 f1 f1 f1 f1 | ||
Ctrl+F1 control, ctrl+f1 control, ctrl+f1 control, ctrl+f1 control, ctrl+f1 control, ctrl+f1 | ||
============== ============================= ============================== ============================= ============================== ============================== | ||
|
||
Matplotlib attaches some keypress callbacks by default for interactivity; they | ||
are documented in the :ref:`key-event-handling` section. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,6 +439,7 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel): | |
wx.WXK_CONTROL: 'control', | ||
wx.WXK_SHIFT: 'shift', | ||
wx.WXK_ALT: 'alt', | ||
wx.WXK_CAPITAL: 'caps_lock', | ||
wx.WXK_LEFT: 'left', | ||
wx.WXK_UP: 'up', | ||
wx.WXK_RIGHT: 'right', | ||
|
@@ -718,11 +719,13 @@ def _get_key(self, event): | |
else: | ||
key = None | ||
|
||
for meth, prefix in ( | ||
[event.AltDown, 'alt'], | ||
[event.ControlDown, 'ctrl'], ): | ||
if meth(): | ||
key = '{0}+{1}'.format(prefix, key) | ||
for meth, prefix, key_name in ( | ||
[event.ControlDown, 'ctrl', 'control'], | ||
[event.AltDown, 'alt', 'alt'], | ||
[event.ShiftDown, 'shift', 'shift'],): | ||
if meth() and key_name != key: | ||
if not (key_name == 'shift' and key.isupper()): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it just gives up on non-ascii (?!) base on the I think fixing that is out of scope for this PR (to keep it from getting to big, small PRs are easier to review and get in). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key = chr(keyval)
# wx always returns an uppercase, so make it lowercase if the shift
# key is not depressed (NOTE: this will not handle Caps Lock)
if not event.ShiftDown():
key = key.lower() Thanks to this fragment of code, we get a lowercase letter if shift is not pressed. If it's, then we get an uppercase letter. if not (key_name == 'shift' and key.isupper()): How ever we are still interested on getting |
||
key = '{0}+{1}'.format(prefix, key) | ||
|
||
return key | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What layout are you using? shift+2 is @ on US QWERTY keyboards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Spanish QWERTY keyboard. Sorry! I forgot to consider that fact.