Skip to content

Commit 9f8e36a

Browse files
committed
Consistent behavior of draw_if_interactive across interactive backends.
Previously it would call `show()` on tk and nbagg, but only `draw_idle()` on the other backends. I would guess this was an accident of history. Remove that discrepancy, and the customization point (`trigger_manager_draw`) that I previously implemented to repro the historical behavior. (`trigger_manager_draw` is in the private `_Backend` class, so doesn't need a deprecation period.)
1 parent d9214de commit 9f8e36a

File tree

9 files changed

+9
-36
lines changed

9 files changed

+9
-36
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Consistent behavior of ``draw_if_interactive()`` across backends
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
`.pyplot.draw_if_interactive` no longer shows the window (if it was previously
4+
unshown) on the tk and nbagg backends, consistently with all other backends.

lib/matplotlib/backend_bases.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,12 +3514,9 @@ class _Backend:
35143514
# For interactive backends, the `FigureManager` class must be overridden.
35153515
FigureManager = FigureManagerBase
35163516

3517-
# The following methods must be left as None for non-interactive backends.
3518-
# For interactive backends, `trigger_manager_draw` should be a function
3519-
# taking a manager as argument and triggering a canvas draw, and `mainloop`
3520-
# should be a function taking no argument and starting the backend main
3521-
# loop.
3522-
trigger_manager_draw = None
3517+
# For interactive backends, `mainloop` should be a function taking no
3518+
# argument and starting the backend main loop. It should be left as None
3519+
# for non-interactive backends.
35233520
mainloop = None
35243521

35253522
# The following methods will be automatically defined and exported, but
@@ -3543,10 +3540,10 @@ def new_figure_manager_given_figure(cls, num, figure):
35433540

35443541
@classmethod
35453542
def draw_if_interactive(cls):
3546-
if cls.trigger_manager_draw is not None and is_interactive():
3543+
if cls.mainloop is not None and is_interactive():
35473544
manager = Gcf.get_active()
35483545
if manager:
3549-
cls.trigger_manager_draw(manager)
3546+
manager.canvas.draw_idle()
35503547

35513548
@classmethod
35523549
def show(cls, *, block=None):

lib/matplotlib/backends/_backend_tk.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,6 @@ def new_figure_manager_given_figure(cls, num, figure):
883883
canvas.draw_idle()
884884
return manager
885885

886-
@staticmethod
887-
def trigger_manager_draw(manager):
888-
manager.show()
889-
890886
@staticmethod
891887
def mainloop():
892888
managers = Gcf.get_all_fig_managers()

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,6 @@ class _BackendGTK3(_Backend):
942942
FigureCanvas = FigureCanvasGTK3
943943
FigureManager = FigureManagerGTK3
944944

945-
@staticmethod
946-
def trigger_manager_draw(manager):
947-
manager.canvas.draw_idle()
948-
949945
@staticmethod
950946
def mainloop():
951947
if Gtk.main_level() == 0:

lib/matplotlib/backends/backend_macosx.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ class _BackendMac(_Backend):
162162
FigureCanvas = FigureCanvasMac
163163
FigureManager = FigureManagerMac
164164

165-
@staticmethod
166-
def trigger_manager_draw(manager):
167-
manager.canvas.draw_idle()
168-
169165
@staticmethod
170166
def mainloop():
171167
_macosx.show()

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ def destroy(event):
239239
cid = canvas.mpl_connect('close_event', destroy)
240240
return manager
241241

242-
@staticmethod
243-
def trigger_manager_draw(manager):
244-
manager.show()
245-
246242
@staticmethod
247243
def show(block=None):
248244
## TODO: something to do when keyword block==False ?

lib/matplotlib/backends/backend_qt5.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,6 @@ class _BackendQT5(_Backend):
10251025
FigureCanvas = FigureCanvasQT
10261026
FigureManager = FigureManagerQT
10271027

1028-
@staticmethod
1029-
def trigger_manager_draw(manager):
1030-
manager.canvas.draw_idle()
1031-
10321028
@staticmethod
10331029
def mainloop():
10341030
old_signal = signal.getsignal(signal.SIGINT)

lib/matplotlib/backends/backend_webagg.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,6 @@ class _BackendWebAgg(_Backend):
306306
FigureCanvas = FigureCanvasWebAgg
307307
FigureManager = core.FigureManagerWebAgg
308308

309-
@staticmethod
310-
def trigger_manager_draw(manager):
311-
manager.canvas.draw_idle()
312-
313309
@staticmethod
314310
def show():
315311
WebAggApplication.initialize()

lib/matplotlib/backends/backend_wx.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,10 +1649,6 @@ class _BackendWx(_Backend):
16491649
FigureManager = FigureManagerWx
16501650
_frame_class = FigureFrameWx
16511651

1652-
@staticmethod
1653-
def trigger_manager_draw(manager):
1654-
manager.canvas.draw_idle()
1655-
16561652
@classmethod
16571653
def new_figure_manager(cls, num, *args, **kwargs):
16581654
# Create a wx.App instance if it has not been created so far.

0 commit comments

Comments
 (0)