Skip to content

wx.App() should be init'ed in new_figure_manager_given_figure #22339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/matplotlib/backends/backend_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@ def show(*, block=None):

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


def new_figure_manager_given_figure(num, figure):
"""Create a new figure manager instance for the given figure."""
# If a main-level app must be created, this is the usual place to do it
# -- see the wx and tk backends for examples (the default implementation
# of new_figure_manager defers to new_figure_manager_given_figure, so it
# also benefits from this instantiation). Not all GUIs require explicit
# instantiation of a main-level app (e.g., backend_gtk3) for pylab.
canvas = FigureCanvasTemplate(figure)
manager = FigureManagerTemplate(canvas, num)
return manager
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ class _BackendWx(_Backend):
FigureManager = FigureManagerWx

@classmethod
def new_figure_manager(cls, num, *args, **kwargs):
def new_figure_manager_given_figure(cls, num, figure):
# Create a wx.App instance if it has not been created so far.
wxapp = wx.GetApp()
if wxapp is None:
Expand All @@ -1366,10 +1366,6 @@ def new_figure_manager(cls, num, *args, **kwargs):
# Retain a reference to the app object so that it does not get
# garbage collected.
_BackendWx._theWxApp = wxapp
return super().new_figure_manager(num, *args, **kwargs)

@classmethod
def new_figure_manager_given_figure(cls, num, figure):
frame = FigureFrameWx(num, figure, canvas_class=cls.FigureCanvas)
figmgr = frame.get_figure_manager()
if mpl.is_interactive():
Expand Down