Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 817260d

Browse filesBrowse files
committed
Make FigureManagerWx more consistent with other backends.
1 parent 11258c2 commit 817260d
Copy full SHA for 817260d

File tree

Expand file treeCollapse file tree

2 files changed

+40
-19
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-19
lines changed
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Changes to the wx backend
2+
`````````````````````````
3+
4+
- ``FigureFrameWx`` no longer attaches a ``FigureManagerWx``
5+
to the figure. Instead, the ``FigureManagerWx`` is
6+
now created by ``backend_wx.new_figure_manager`` or
7+
``backend_wx.new_figure_manager_given_figure``, consistently with the
8+
other backends. Accordingly, the ``FigureFrameWx.figmgr`` attribute
9+
and ``FigureFrameWx.get_figure_manager`` method are deprecated (use the
10+
cross-backend ``figure.canvas.manager`` instead).
11+
- The *frame* argument and attribute of ``FigureManagerWx`` are deprecated, for
12+
consistency with other backends. The ``FigureManagerWx.window``
13+
attribute is now always set to the canvas' parent.

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+27-19Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,13 @@ def __init__(self, num, fig):
879879
# By adding toolbar in sizer, we are able to put it at the bottom
880880
# of the frame - so appearance is closer to GTK version
881881

882-
self.figmgr = FigureManagerWx(self.canvas, num, self)
882+
# Attach manager to self.canvas.
883+
FigureManagerWx(self.canvas, num)
883884

884885
self.toolbar = self._get_toolbar()
885886

886-
if self.figmgr.toolmanager:
887-
backend_tools.add_tools_to_manager(self.figmgr.toolmanager)
887+
if self.canvas.manager.toolmanager:
888+
backend_tools.add_tools_to_manager(self.canvas.manager.toolmanager)
888889
if self.toolbar:
889890
backend_tools.add_tools_to_container(self.toolbar)
890891

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

908909
@property
909910
def toolmanager(self):
910-
return self.figmgr.toolmanager
911+
return self.canvas.manager.toolmanager
911912

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

925+
@_api.deprecated("3.5", alternative="frame.canvas.manager or "
926+
"FigureManagerWx(frame.canvas, num)")
927+
@property
928+
def figmgr(self):
929+
return self.canvas.manager
930+
931+
@_api.deprecated("3.5", alternative="frame.canvas.manager or "
932+
"FigureManagerWx(frame.canvas, num)")
924933
def get_figure_manager(self):
925934
_log.debug("%s - get_figure_manager()", type(self))
926935
return self.figmgr
@@ -931,9 +940,9 @@ def _onClose(self, event):
931940
self.canvas.stop_event_loop()
932941
# set FigureManagerWx.frame to None to prevent repeated attempts to
933942
# close this frame from FigureManagerWx.destroy()
934-
self.figmgr.frame = None
943+
self.canvas.manager.window = None
935944
# remove figure manager from Gcf.figs
936-
Gcf.destroy(self.figmgr)
945+
Gcf.destroy(self.canvas.manager)
937946
# Carry on with close event propagation, frame & children destruction
938947
event.Skip()
939948

@@ -966,22 +975,21 @@ class FigureManagerWx(FigureManagerBase):
966975
967976
Attributes
968977
----------
969-
canvas : `FigureCanvas`
970-
a FigureCanvasWx(wx.Panel) instance
978+
canvas : FigureCanvasWx
971979
window : wxFrame
972-
a wxFrame instance - wxpython.org/Phoenix/docs/html/Frame.html
973980
"""
974981

975-
def __init__(self, canvas, num, frame):
982+
@_api.delete_parameter("3.5", "frame")
983+
def __init__(self, canvas, num, frame=None):
976984
_log.debug("%s - __init__()", type(self))
977-
self.frame = self.window = frame
985+
self.frame = self.window = canvas.GetParent()
978986
self._initializing = True
979987
super().__init__(canvas, num)
980988
self._initializing = False
981989

982990
@property
983991
def toolbar(self):
984-
return self.frame.GetToolBar()
992+
return self.window.GetToolBar()
985993

986994
@toolbar.setter
987995
def toolbar(self, value):
@@ -992,23 +1000,23 @@ def toolbar(self, value):
9921000

9931001
def show(self):
9941002
# docstring inherited
995-
self.frame.Show()
1003+
self.window.Show()
9961004
self.canvas.draw()
9971005
if mpl.rcParams['figure.raise_window']:
998-
self.frame.Raise()
1006+
self.window.Raise()
9991007

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

10091017
def full_screen_toggle(self):
10101018
# docstring inherited
1011-
self.frame.ShowFullScreen(not self.frame.IsFullScreen())
1019+
self.window.ShowFullScreen(not self.window.IsFullScreen())
10121020

10131021
def get_window_title(self):
10141022
# docstring inherited
@@ -1388,11 +1396,11 @@ def new_figure_manager(cls, num, *args, **kwargs):
13881396
@classmethod
13891397
def new_figure_manager_given_figure(cls, num, figure):
13901398
frame = cls._frame_class(num, figure)
1391-
figmgr = frame.get_figure_manager()
1399+
manager = FigureManagerWx(figure.canvas, num)
13921400
if mpl.is_interactive():
1393-
figmgr.frame.Show()
1401+
frame.Show()
13941402
figure.canvas.draw_idle()
1395-
return figmgr
1403+
return manager
13961404

13971405
@staticmethod
13981406
def mainloop():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.