Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make FigureManagerWx more consistent with other backends. #13153

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions doc/api/next_api_changes/deprecations/13153-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Changes to the wx backend
`````````````````````````

- ``FigureFrameWx`` no longer attaches a ``FigureManagerWx``
to the figure. Instead, the ``FigureManagerWx`` is
now created by ``backend_wx.new_figure_manager`` or
``backend_wx.new_figure_manager_given_figure``, consistently with the
other backends. Accordingly, the ``FigureFrameWx.figmgr`` attribute
and ``FigureFrameWx.get_figure_manager`` method are deprecated (use the
cross-backend ``figure.canvas.manager`` instead).
- The *frame* argument and attribute of ``FigureManagerWx`` are deprecated, for
consistency with other backends. The ``FigureManagerWx.window``
attribute is now always set to the canvas' parent.
46 changes: 27 additions & 19 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,12 +879,13 @@ def __init__(self, num, fig):
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version

self.figmgr = FigureManagerWx(self.canvas, num, self)
# Attach manager to self.canvas.
FigureManagerWx(self.canvas, num)

self.toolbar = self._get_toolbar()

if self.figmgr.toolmanager:
backend_tools.add_tools_to_manager(self.figmgr.toolmanager)
if self.canvas.manager.toolmanager:
backend_tools.add_tools_to_manager(self.canvas.manager.toolmanager)
if self.toolbar:
backend_tools.add_tools_to_container(self.toolbar)

Expand All @@ -907,7 +908,7 @@ def __init__(self, num, fig):

@property
def toolmanager(self):
return self.figmgr.toolmanager
return self.canvas.manager.toolmanager

def _get_toolbar(self):
if mpl.rcParams['toolbar'] == 'toolbar2':
Expand All @@ -921,6 +922,14 @@ def _get_toolbar(self):
def get_canvas(self, fig):
return FigureCanvasWx(self, -1, fig)

@_api.deprecated("3.5", alternative="frame.canvas.manager or "
"FigureManagerWx(frame.canvas, num)")
@property
def figmgr(self):
return self.canvas.manager

@_api.deprecated("3.5", alternative="frame.canvas.manager or "
"FigureManagerWx(frame.canvas, num)")
def get_figure_manager(self):
_log.debug("%s - get_figure_manager()", type(self))
return self.figmgr
Expand All @@ -931,9 +940,9 @@ def _onClose(self, event):
self.canvas.stop_event_loop()
# set FigureManagerWx.frame to None to prevent repeated attempts to
# close this frame from FigureManagerWx.destroy()
self.figmgr.frame = None
self.canvas.manager.window = None
# remove figure manager from Gcf.figs
Gcf.destroy(self.figmgr)
Gcf.destroy(self.canvas.manager)
# Carry on with close event propagation, frame & children destruction
event.Skip()

Expand Down Expand Up @@ -966,22 +975,21 @@ class FigureManagerWx(FigureManagerBase):

Attributes
----------
canvas : `FigureCanvas`
a FigureCanvasWx(wx.Panel) instance
canvas : FigureCanvasWx
window : wxFrame
a wxFrame instance - wxpython.org/Phoenix/docs/html/Frame.html
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link is broken and if anything the only link should be to the wxpython general docs at the top of the module (perhaps).

"""

def __init__(self, canvas, num, frame):
@_api.delete_parameter("3.5", "frame")
def __init__(self, canvas, num, frame=None):
_log.debug("%s - __init__()", type(self))
self.frame = self.window = frame
self.frame = self.window = canvas.GetParent()
self._initializing = True
super().__init__(canvas, num)
self._initializing = False

@property
def toolbar(self):
return self.frame.GetToolBar()
return self.window.GetToolBar()

@toolbar.setter
def toolbar(self, value):
Expand All @@ -992,23 +1000,23 @@ def toolbar(self, value):

def show(self):
# docstring inherited
self.frame.Show()
self.window.Show()
self.canvas.draw()
if mpl.rcParams['figure.raise_window']:
self.frame.Raise()
self.window.Raise()

def destroy(self, *args):
# docstring inherited
_log.debug("%s - destroy()", type(self))
frame = self.frame
frame = self.window
if frame: # Else, may have been already deleted, e.g. when closing.
# As this can be called from non-GUI thread from plt.close use
# wx.CallAfter to ensure thread safety.
wx.CallAfter(frame.Close)

def full_screen_toggle(self):
# docstring inherited
self.frame.ShowFullScreen(not self.frame.IsFullScreen())
self.window.ShowFullScreen(not self.window.IsFullScreen())

def get_window_title(self):
# docstring inherited
Expand Down Expand Up @@ -1388,11 +1396,11 @@ def new_figure_manager(cls, num, *args, **kwargs):
@classmethod
def new_figure_manager_given_figure(cls, num, figure):
frame = cls._frame_class(num, figure)
figmgr = frame.get_figure_manager()
manager = FigureManagerWx(figure.canvas, num)
if mpl.is_interactive():
figmgr.frame.Show()
frame.Show()
figure.canvas.draw_idle()
return figmgr
return manager

@staticmethod
def mainloop():
Expand Down