@@ -34,6 +34,13 @@ def _get_testable_interactive_backends():
3434 return backends
3535
3636
37+ # 1. Using a timer not only allows testing of timers (on other backends), but
38+ # is also necessary on gtk3 and wx, where a direct call to
39+ # key_press_event("q") from draw_event causes breakage due to the canvas
40+ # widget being deleted too early.
41+ # 2. On gtk3, we cannot even test the timer setup (on Travis, which uses pgi)
42+ # due to https://github.com/pygobject/pgi/issues/45. So we just cleanly
43+ # exit from the draw_event.
3744_test_script = """\
3845 import sys
3946from matplotlib import pyplot as plt, rcParams
@@ -44,8 +51,16 @@ def _get_testable_interactive_backends():
4451
4552fig = plt.figure()
4653ax = fig.add_subplot(111)
47- ax.plot([1, 2], [2, 3])
48- fig.canvas.mpl_connect("draw_event", lambda event: sys.exit())
54+ ax.plot([0, 1], [2, 3])
55+
56+ if rcParams["backend"].startswith("GTK3"):
57+ fig.canvas.mpl_connect("draw_event", lambda event: sys.exit(0))
58+ else:
59+ timer = fig.canvas.new_timer(1)
60+ timer.add_callback(fig.canvas.key_press_event, "q")
61+ # Trigger quitting upon draw.
62+ fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
63+
4964plt.show()
5065"""
5166_test_timeout = 10 # Empirically, 1s is not enough on Travis.
0 commit comments