-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
More accurate handling of unicode/numpad input in gtk3 backends. #17791
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
GTK key name changes | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The handling of non-ASCII keypresses (as reported in the KeyEvent passed to | ||
``key_press_event``-handlers) in the GTK backends now correctly reports Unicode | ||
characters (e.g., €), and respects NumLock on the numpad. | ||
|
||
The following key names have changed; the new names are consistent with those | ||
reported by the Qt backends: | ||
|
||
- The "Break/Pause" key (keysym 0xff13) is now reported as "pause" instead of | ||
"break" (this is also consistent with the X key name). | ||
- The numpad "delete" key is now reported as "delete" instead of "dec". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from matplotlib import pyplot as plt | ||
|
||
import pytest | ||
|
||
|
||
pytest.importorskip("matplotlib.backends.backend_gtk3agg") | ||
|
||
|
||
@pytest.mark.backend("gtk3agg") | ||
def test_correct_key(): | ||
pytest.xfail("test_widget_send_event is not triggering key_press_event") | ||
|
||
from gi.repository import Gdk, Gtk | ||
fig = plt.figure() | ||
buf = [] | ||
|
||
def send(event): | ||
for key, mod in [ | ||
(Gdk.KEY_a, Gdk.ModifierType.SHIFT_MASK), | ||
(Gdk.KEY_a, 0), | ||
(Gdk.KEY_a, Gdk.ModifierType.CONTROL_MASK), | ||
(Gdk.KEY_agrave, 0), | ||
(Gdk.KEY_Control_L, Gdk.ModifierType.MOD1_MASK), | ||
(Gdk.KEY_Alt_L, Gdk.ModifierType.CONTROL_MASK), | ||
(Gdk.KEY_agrave, | ||
Gdk.ModifierType.CONTROL_MASK | ||
| Gdk.ModifierType.MOD1_MASK | ||
| Gdk.ModifierType.MOD4_MASK), | ||
(0xfd16, 0), # KEY_3270_Play. | ||
(Gdk.KEY_BackSpace, 0), | ||
(Gdk.KEY_BackSpace, Gdk.ModifierType.CONTROL_MASK), | ||
]: | ||
# This is not actually really the right API: it depends on the | ||
# actual keymap (e.g. on Azerty, shift+agrave -> 0). | ||
Gtk.test_widget_send_key(fig.canvas, key, mod) | ||
|
||
def receive(event): | ||
buf.append(event.key) | ||
if buf == [ | ||
"A", "a", "ctrl+a", | ||
"\N{LATIN SMALL LETTER A WITH GRAVE}", | ||
"alt+control", "ctrl+alt", | ||
"ctrl+alt+super+\N{LATIN SMALL LETTER A WITH GRAVE}", | ||
# (No entry for KEY_3270_Play.) | ||
"backspace", "ctrl+backspace", | ||
]: | ||
plt.close(fig) | ||
|
||
fig.canvas.mpl_connect("draw_event", send) | ||
fig.canvas.mpl_connect("key_press_event", receive) | ||
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could this be why it's getting stuck? Maybe you can check
len(buf)
and assert the result after shutting down?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.
Actually turns out that even locally this is not passing anymore, i.e. calls to Gtk.test_widget_send_event (or Gdk.simulate_key_event) don't result in the key_press_event handler being called at all. At some point it worked, so likely a Gtk version thing? I just xfailed the whole thing for now...
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.
According to https://mail.gnome.org/archives/commits-list/2017-January/msg01173.html, those were never fully implemented (I only see an x11 version in that commit).