Skip to content

Simplify canvas class control in FigureFrameWx. #21983

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
Dec 21, 2021
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
8 changes: 8 additions & 0 deletions doc/api/next_api_changes/behavior/21983-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
``FigureFrameWx`` constructor, subclasses, and ``get_canvas``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``FigureCanvasWx`` constructor gained a *canvas_class* keyword-only
parameter which specifies the canvas class that should be used. This
parameter will become required in the future. The ``get_canvas`` method,
which was previously used to customize canvas creation, is deprecated. The
``FigureFrameWxAgg`` and ``FigureFrameWxCairo`` subclasses, which overrode
``get_canvas``, are deprecated.
17 changes: 13 additions & 4 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def _print_image(self, filetype, filename):


class FigureFrameWx(wx.Frame):
def __init__(self, num, fig):
def __init__(self, num, fig, *, canvas_class=None):
# On non-Windows platform, explicitly set the position - fix
# positioning bug on some Linux platforms
if wx.Platform == '__WXMSW__':
Expand All @@ -905,7 +905,15 @@ def __init__(self, num, fig):
self.num = num
_set_frame_icon(self)

self.canvas = self.get_canvas(fig)
# The parameter will become required after the deprecation elapses.
if canvas_class is not None:
self.canvas = canvas_class(self, -1, fig)
else:
_api.warn_deprecated(
"3.6", message="The canvas_class parameter will become "
"required after the deprecation period starting in Matplotlib "
"%(since)s elapses.")
self.canvas = self.get_canvas(fig)
w, h = map(math.ceil, fig.bbox.size)
self.canvas.SetInitialSize(wx.Size(w, h))
self.canvas.SetFocus()
Expand Down Expand Up @@ -953,6 +961,8 @@ def _get_toolbar(self):
toolbar = None
return toolbar

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

Expand Down Expand Up @@ -1393,7 +1403,6 @@ def trigger(self, *args, **kwargs):
class _BackendWx(_Backend):
FigureCanvas = FigureCanvasWx
FigureManager = FigureManagerWx
_frame_class = FigureFrameWx

@classmethod
def new_figure_manager(cls, num, *args, **kwargs):
Expand All @@ -1410,7 +1419,7 @@ def new_figure_manager(cls, num, *args, **kwargs):

@classmethod
def new_figure_manager_given_figure(cls, num, figure):
frame = cls._frame_class(num, figure)
frame = FigureFrameWx(num, figure, canvas_class=cls.FigureCanvas)
figmgr = frame.get_figure_manager()
if mpl.is_interactive():
figmgr.frame.Show()
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_wxagg.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import wx

from .. import _api
from .backend_agg import FigureCanvasAgg
from .backend_wx import (
_BackendWx, _FigureCanvasWxBase, FigureFrameWx,
NavigationToolbar2Wx as NavigationToolbar2WxAgg)


@_api.deprecated(
"3.6", alternative="FigureFrameWx(..., canvas_class=FigureCanvasWxAgg)")
class FigureFrameWxAgg(FigureFrameWx):
def get_canvas(self, fig):
return FigureCanvasWxAgg(self, -1, fig)
Expand Down Expand Up @@ -56,4 +59,3 @@ def _rgba_to_wx_bitmap(rgba):
@_BackendWx.export
class _BackendWxAgg(_BackendWx):
FigureCanvas = FigureCanvasWxAgg
_frame_class = FigureFrameWxAgg
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_wxcairo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import wx.lib.wxcairo as wxcairo

from .. import _api
from .backend_cairo import cairo, FigureCanvasCairo
from .backend_wx import (
_BackendWx, _FigureCanvasWxBase, FigureFrameWx,
NavigationToolbar2Wx as NavigationToolbar2WxCairo)


@_api.deprecated(
"3.6", alternative="FigureFrameWx(..., canvas_class=FigureCanvasWxCairo)")
class FigureFrameWxCairo(FigureFrameWx):
def get_canvas(self, fig):
return FigureCanvasWxCairo(self, -1, fig)
Expand Down Expand Up @@ -36,4 +39,3 @@ def draw(self, drawDC=None):
@_BackendWx.export
class _BackendWxCairo(_BackendWx):
FigureCanvas = FigureCanvasWxCairo
_frame_class = FigureFrameWxCairo