1717
1818def _get_testable_interactive_backends ():
1919 backends = []
20- for deps , backend in [(["cairocffi" , "pgi" ], "gtk3agg" ),
20+ # gtk3agg fails on Travis, needs to be investigated.
21+ for deps , backend in [ # (["cairocffi", "pgi"], "gtk3agg"),
2122 (["cairocffi" , "pgi" ], "gtk3cairo" ),
2223 (["PyQt5" ], "qt5agg" ),
2324 (["cairocffi" , "PyQt5" ], "qt5cairo" ),
@@ -36,16 +37,15 @@ def _get_testable_interactive_backends():
3637 return backends
3738
3839
39- # 1. Using a timer not only allows testing of timers (on other backends), but
40- # is also necessary on gtk3 and wx, where a direct call to
41- # key_press_event("q") from draw_event causes breakage due to the canvas
42- # widget being deleted too early.
43- # 2. On gtk3, we cannot even test the timer setup (on Travis, which uses pgi)
44- # due to https://github.com/pygobject/pgi/issues/45. So we just cleanly
45- # exit from the draw_event.
40+ # Using a timer not only allows testing of timers (on other backends), but is
41+ # also necessary on gtk3 and wx, where a direct call to key_press_event("q")
42+ # from draw_event causes breakage due to the canvas widget being deleted too
43+ # early. Also, gtk3 redefines key_press_event with a different signature, so
44+ # we directly invoke it from the superclass instead.
4645_test_script = """\
4746 import sys
4847from matplotlib import pyplot as plt, rcParams
48+ from matplotlib.backend_bases import FigureCanvasBase
4949rcParams.update({
5050 "webagg.open_in_browser": False,
5151 "webagg.port_retries": 1,
@@ -54,13 +54,10 @@ def _get_testable_interactive_backends():
5454fig, ax = plt.subplots()
5555ax.plot([0, 1], [2, 3])
5656
57- if rcParams["backend"].startswith("GTK3"):
58- fig.canvas.mpl_connect("draw_event", lambda event: sys.exit(0))
59- else:
60- timer = fig.canvas.new_timer(1)
61- timer.add_callback(fig.canvas.key_press_event, "q")
62- # Trigger quitting upon draw.
63- fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
57+ timer = fig.canvas.new_timer(1)
58+ timer.add_callback(FigureCanvasBase.key_press_event, fig.canvas, "q")
59+ # Trigger quitting upon draw.
60+ fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
6461
6562plt.show()
6663"""
0 commit comments