Skip to content

Commit c6bad8c

Browse files
authored
Merge pull request #22339 from anntzer/wxapp
wx.App() should be init'ed in new_figure_manager_given_figure
2 parents 6fe94c3 + cb72c42 commit c6bad8c

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

lib/matplotlib/backends/backend_template.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,17 @@ def show(*, block=None):
158158

159159
def new_figure_manager(num, *args, FigureClass=Figure, **kwargs):
160160
"""Create a new figure manager instance."""
161-
# If a main-level app must be created, this (and
162-
# new_figure_manager_given_figure) is the usual place to do it -- see
163-
# backend_wx, backend_wxagg and backend_tkagg for examples. Not all GUIs
164-
# require explicit instantiation of a main-level app (e.g., backend_gtk3)
165-
# for pylab.
166161
thisFig = FigureClass(*args, **kwargs)
167162
return new_figure_manager_given_figure(num, thisFig)
168163

169164

170165
def new_figure_manager_given_figure(num, figure):
171166
"""Create a new figure manager instance for the given figure."""
167+
# If a main-level app must be created, this is the usual place to do it
168+
# -- see the wx and tk backends for examples (the default implementation
169+
# of new_figure_manager defers to new_figure_manager_given_figure, so it
170+
# also benefits from this instantiation). Not all GUIs require explicit
171+
# instantiation of a main-level app (e.g., backend_gtk3) for pylab.
172172
canvas = FigureCanvasTemplate(figure)
173173
manager = FigureManagerTemplate(canvas, num)
174174
return manager

lib/matplotlib/backends/backend_wx.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ class _BackendWx(_Backend):
13561356
FigureManager = FigureManagerWx
13571357

13581358
@classmethod
1359-
def new_figure_manager(cls, num, *args, **kwargs):
1359+
def new_figure_manager_given_figure(cls, num, figure):
13601360
# Create a wx.App instance if it has not been created so far.
13611361
wxapp = wx.GetApp()
13621362
if wxapp is None:
@@ -1366,10 +1366,6 @@ def new_figure_manager(cls, num, *args, **kwargs):
13661366
# Retain a reference to the app object so that it does not get
13671367
# garbage collected.
13681368
_BackendWx._theWxApp = wxapp
1369-
return super().new_figure_manager(num, *args, **kwargs)
1370-
1371-
@classmethod
1372-
def new_figure_manager_given_figure(cls, num, figure):
13731369
frame = FigureFrameWx(num, figure, canvas_class=cls.FigureCanvas)
13741370
figmgr = frame.get_figure_manager()
13751371
if mpl.is_interactive():

0 commit comments

Comments
 (0)