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

Skip to content

Commit e14ba67

Browse files
committed
Make FigureManagerWx more consistent with other backends.
1 parent 432403f commit e14ba67

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed
Lines 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 :attr:`FigureManagerWx.window`
13+
attribute is now always set to the canvas' parent.

lib/matplotlib/backends/backend_wx.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,6 @@ def __init__(self, num, fig):
11801180

11811181
self.canvas.SetMinSize((2, 2))
11821182

1183-
self.figmgr = FigureManagerWx(self.canvas, num, self)
1184-
11851183
self.Bind(wx.EVT_CLOSE, self._onClose)
11861184

11871185
def _get_toolbar(self, statbar):
@@ -1204,6 +1202,16 @@ def _get_toolmanager(self):
12041202
def get_canvas(self, fig):
12051203
return FigureCanvasWx(self, -1, fig)
12061204

1205+
@cbook.deprecated("3.1", alternative="frame.canvas.manager or "
1206+
"FigureManagerWx(frame.canvas, num, frame)")
1207+
@property
1208+
def figmgr(self):
1209+
if self.canvas.manager is None:
1210+
FigureManagerWx(self.canvas, num, self) # Assigns canvas.manager.
1211+
return self.canvas.manager
1212+
1213+
@cbook.deprecated("3.1", alternative="frame.canvas.manager or "
1214+
"FigureManagerWx(frame.canvas, num, frame)")
12071215
def get_figure_manager(self):
12081216
DEBUG_MSG("get_figure_manager()", 1, self)
12091217
return self.figmgr
@@ -1244,29 +1252,27 @@ class FigureManagerWx(FigureManagerBase):
12441252
12451253
Attributes
12461254
----------
1247-
canvas : `FigureCanvas`
1248-
a FigureCanvasWx(wx.Panel) instance
1255+
canvas : FigureCanvasWx
12491256
window : wxFrame
1250-
a wxFrame instance - wxpython.org/Phoenix/docs/html/Frame.html
1251-
12521257
"""
12531258

1254-
def __init__(self, canvas, num, frame):
1255-
DEBUG_MSG("__init__()", 1, self)
1259+
def __init__(self, canvas, num, frame=None):
1260+
if frame is not None:
1261+
cbook.warn_deprecated(
1262+
"3.1", name="frame", obj_type="argument",
1263+
addendum="Do not pass it anymore.")
12561264
FigureManagerBase.__init__(self, canvas, num)
1257-
self.frame = frame
1258-
self.window = frame
1259-
1260-
self.toolmanager = getattr(frame, "toolmanager", None)
1261-
self.toolbar = frame.GetToolBar()
1265+
self.frame = self.window = canvas.GetParent()
1266+
self.toolmanager = getattr(self.frame, "toolmanager", None)
1267+
self.toolbar = self.frame.GetToolBar()
12621268

12631269
def show(self):
1264-
self.frame.Show()
1270+
self.window.Show()
12651271
self.canvas.draw()
12661272

12671273
def destroy(self, *args):
12681274
DEBUG_MSG("destroy()", 1, self)
1269-
self.frame.Destroy()
1275+
self.window.Destroy()
12701276
wxapp = wx.GetApp()
12711277
if wxapp:
12721278
wxapp.Yield()
@@ -2066,11 +2072,11 @@ def new_figure_manager(cls, num, *args, **kwargs):
20662072
@classmethod
20672073
def new_figure_manager_given_figure(cls, num, figure):
20682074
frame = cls._frame_class(num, figure)
2069-
figmgr = frame.get_figure_manager()
2075+
manager = FigureManagerWx(figure.canvas, num)
20702076
if matplotlib.is_interactive():
2071-
figmgr.frame.Show()
2077+
frame.Show()
20722078
figure.canvas.draw_idle()
2073-
return figmgr
2079+
return manager
20742080

20752081
@staticmethod
20762082
def mainloop():

0 commit comments

Comments
 (0)