-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathtest_backend_gtk3.py
More file actions
51 lines (42 loc) · 1.72 KB
/
test_backend_gtk3.py
File metadata and controls
51 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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()