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

Skip to content

Commit 72f4046

Browse files
authored
Merge pull request #21983 from anntzer/ffw
Simplify canvas class control in FigureFrameWx.
2 parents 882f0e6 + c8e3742 commit 72f4046

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
``FigureFrameWx`` constructor, subclasses, and ``get_canvas``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The ``FigureCanvasWx`` constructor gained a *canvas_class* keyword-only
4+
parameter which specifies the canvas class that should be used. This
5+
parameter will become required in the future. The ``get_canvas`` method,
6+
which was previously used to customize canvas creation, is deprecated. The
7+
``FigureFrameWxAgg`` and ``FigureFrameWxCairo`` subclasses, which overrode
8+
``get_canvas``, are deprecated.

lib/matplotlib/backends/backend_wx.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ def _print_image(self, filetype, filename):
876876

877877

878878
class FigureFrameWx(wx.Frame):
879-
def __init__(self, num, fig):
879+
def __init__(self, num, fig, *, canvas_class=None):
880880
# On non-Windows platform, explicitly set the position - fix
881881
# positioning bug on some Linux platforms
882882
if wx.Platform == '__WXMSW__':
@@ -889,7 +889,15 @@ def __init__(self, num, fig):
889889
self.num = num
890890
_set_frame_icon(self)
891891

892-
self.canvas = self.get_canvas(fig)
892+
# The parameter will become required after the deprecation elapses.
893+
if canvas_class is not None:
894+
self.canvas = canvas_class(self, -1, fig)
895+
else:
896+
_api.warn_deprecated(
897+
"3.6", message="The canvas_class parameter will become "
898+
"required after the deprecation period starting in Matplotlib "
899+
"%(since)s elapses.")
900+
self.canvas = self.get_canvas(fig)
893901
w, h = map(math.ceil, fig.bbox.size)
894902
self.canvas.SetInitialSize(wx.Size(w, h))
895903
self.canvas.SetFocus()
@@ -937,6 +945,8 @@ def _get_toolbar(self):
937945
toolbar = None
938946
return toolbar
939947

948+
@_api.deprecated(
949+
"3.6", alternative="the canvas_class constructor parameter")
940950
def get_canvas(self, fig):
941951
return FigureCanvasWx(self, -1, fig)
942952

@@ -1377,7 +1387,6 @@ def trigger(self, *args, **kwargs):
13771387
class _BackendWx(_Backend):
13781388
FigureCanvas = FigureCanvasWx
13791389
FigureManager = FigureManagerWx
1380-
_frame_class = FigureFrameWx
13811390

13821391
@classmethod
13831392
def new_figure_manager(cls, num, *args, **kwargs):
@@ -1394,7 +1403,7 @@ def new_figure_manager(cls, num, *args, **kwargs):
13941403

13951404
@classmethod
13961405
def new_figure_manager_given_figure(cls, num, figure):
1397-
frame = cls._frame_class(num, figure)
1406+
frame = FigureFrameWx(num, figure, canvas_class=cls.FigureCanvas)
13981407
figmgr = frame.get_figure_manager()
13991408
if mpl.is_interactive():
14001409
figmgr.frame.Show()

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import wx
22

3+
from .. import _api
34
from .backend_agg import FigureCanvasAgg
45
from .backend_wx import (
56
_BackendWx, _FigureCanvasWxBase, FigureFrameWx,
67
NavigationToolbar2Wx as NavigationToolbar2WxAgg)
78

89

10+
@_api.deprecated(
11+
"3.6", alternative="FigureFrameWx(..., canvas_class=FigureCanvasWxAgg)")
912
class FigureFrameWxAgg(FigureFrameWx):
1013
def get_canvas(self, fig):
1114
return FigureCanvasWxAgg(self, -1, fig)
@@ -56,4 +59,3 @@ def _rgba_to_wx_bitmap(rgba):
5659
@_BackendWx.export
5760
class _BackendWxAgg(_BackendWx):
5861
FigureCanvas = FigureCanvasWxAgg
59-
_frame_class = FigureFrameWxAgg

lib/matplotlib/backends/backend_wxcairo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import wx.lib.wxcairo as wxcairo
22

3+
from .. import _api
34
from .backend_cairo import cairo, FigureCanvasCairo
45
from .backend_wx import (
56
_BackendWx, _FigureCanvasWxBase, FigureFrameWx,
67
NavigationToolbar2Wx as NavigationToolbar2WxCairo)
78

89

10+
@_api.deprecated(
11+
"3.6", alternative="FigureFrameWx(..., canvas_class=FigureCanvasWxCairo)")
912
class FigureFrameWxCairo(FigureFrameWx):
1013
def get_canvas(self, fig):
1114
return FigureCanvasWxCairo(self, -1, fig)
@@ -36,4 +39,3 @@ def draw(self, drawDC=None):
3639
@_BackendWx.export
3740
class _BackendWxCairo(_BackendWx):
3841
FigureCanvas = FigureCanvasWxCairo
39-
_frame_class = FigureFrameWxCairo

0 commit comments

Comments
 (0)