Skip to content

Make FigureCanvasWx ctor signature similar to FigureCanvasBase. #10606

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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/2018-02-15-AL-deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ The following functions and classes are deprecated:
- ``cbook.GetRealpathAndStat`` (which is only a helper for
``get_realpath_and_stat``),
- ``cbook.is_numlike`` (use ``isinstance(..., numbers.Number)`` instead),
- ``FigureCanvasWx.frame`` and ``.tb`` (use ``.window`` and ``.toolbar``
respectively, which is consistent with other backends),
- the ``FigureCanvasWx`` constructor should not be called with ``(parent, id,
figure)`` as arguments anymore, but just ``figure`` (like all other canvas
classes). Call ``Reparent`` and ``SetId`` to set the parent and id of the
canvas.
- ``mathtext.unichr_safe`` (use ``chr`` instead),
61 changes: 43 additions & 18 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,29 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel):
wx.WXK_NUMPAD_DELETE: 'delete',
}

def __init__(self, parent, id, figure):
def __init__(self, *args):
"""
Initialise a FigureWx instance.
Initialize a FigureWx instance.

- Initialise the FigureCanvasBase and wxPanel parents.
- Set event handlers for:
EVT_SIZE (Resize event)
EVT_PAINT (Paint event)
Initialize the FigureCanvasBase and wxPanel parents and set event
handlers.

Note that the canvas parent is set to the top window
(``wx.App().GetTopWindow()``) and it is the responsibility of the
caller to ``Reparent`` the canvas.
"""

if len(args) == 3:
# Legacy signature.
cbook.warn_deprecated(
"3.0", "Passing a parent and id to the FigureCanvasWx "
"constructor is deprecated; use 'SetId' and 'Reparent' if "
"needed.")
parent, id, figure = args
else:
parent = wx.GetApp().GetTopWindow()
id = wx.ID_ANY
figure, = args
FigureCanvasBase.__init__(self, figure)
# Set preferred window size hint - helps the sizer (if one is
# connected)
Expand Down Expand Up @@ -1227,7 +1240,9 @@ def _get_toolbar(self, statbar):
return toolbar

def get_canvas(self, fig):
return FigureCanvasWx(self, -1, fig)
canvas = FigureCanvasWx(fig)
canvas.Reparent(self)
return canvas

def get_figure_manager(self):
DEBUG_MSG("get_figure_manager()", 1, self)
Expand Down Expand Up @@ -1279,18 +1294,25 @@ class FigureManagerWx(FigureManagerBase):
def __init__(self, canvas, num, frame):
DEBUG_MSG("__init__()", 1, self)
FigureManagerBase.__init__(self, canvas, num)
self.frame = frame
self.window = frame

self.tb = frame.GetToolBar()
self.toolbar = self.tb # consistent with other backends
self.toolbar = frame.GetToolBar()

def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
if self.tb is not None:
self.tb.update()
if self.toolbar is not None:
self.toolbar.update()
self.canvas.figure.add_axobserver(notify_axes_change)

@property
@cbook.deprecated("3.0")
def frame(self):
return self.window

@property
@cbook.deprecated("3.0")
def tb(self):
return self.toolbar

def show(self):
self.frame.Show()
self.canvas.draw()
Expand Down Expand Up @@ -1477,7 +1499,8 @@ def __init__(self, targetfig):
wx.Frame.__init__(self, None, -1, "Configure subplots")

toolfig = Figure((6, 3))
canvas = FigureCanvasWx(self, -1, toolfig)
canvas = FigureCanvasWx(toolfig)
canvas.Reparent(self)

# Create a figure manager to manage things
figmgr = FigureManager(canvas, 1, self)
Expand All @@ -1493,7 +1516,7 @@ def __init__(self, targetfig):

class NavigationToolbar2Wx(NavigationToolbar2, wx.ToolBar):
def __init__(self, canvas):
wx.ToolBar.__init__(self, canvas.GetParent(), -1)
wx.ToolBar.__init__(self, canvas.GetParent())
NavigationToolbar2.__init__(self, canvas)
self.canvas = canvas
self._idle = True
Expand All @@ -1506,7 +1529,9 @@ def __init__(self, canvas):
self.retinaFix = 'wxMac' in wx.PlatformInfo

def get_canvas(self, frame, fig):
return type(self.canvas)(frame, -1, fig)
canvas = type(self.canvas)(fig)
canvas.Reparent(frame)
return canvas

def _init_toolbar(self):
DEBUG_MSG("_init_toolbar", 1, self)
Expand Down Expand Up @@ -1537,7 +1562,7 @@ def pan(self, *args):
NavigationToolbar2.pan(self, *args)

def configure_subplots(self, evt):
frame = wx.Frame(None, -1, "Configure subplots")
frame = wx.Frame(None, title="Configure subplots")

toolfig = Figure((6, 3))
canvas = self.get_canvas(frame, toolfig)
Expand Down Expand Up @@ -1710,7 +1735,7 @@ class StatusBarWx(wx.StatusBar):
"""

def __init__(self, parent):
wx.StatusBar.__init__(self, parent, -1)
wx.StatusBar.__init__(self, parent)
self.SetFieldsCount(2)
self.SetStatusText("None", 1)
# self.SetStatusText("Measurement: None", 2)
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_wxagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

class FigureFrameWxAgg(FigureFrameWx):
def get_canvas(self, fig):
return FigureCanvasWxAgg(self, -1, fig)
canvas = FigureCanvasWxAgg(fig)
canvas.Reparent(self)
return canvas


class FigureCanvasWxAgg(FigureCanvasAgg, _FigureCanvasWxBase):
Expand Down
15 changes: 9 additions & 6 deletions lib/matplotlib/backends/backend_wxcairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import six

import wx
import wx.lib.wxcairo as wxcairo

from .backend_cairo import cairo, FigureCanvasCairo, RendererCairo
from .backend_wx import (
_BackendWx, _FigureCanvasWxBase, FigureFrameWx,
NavigationToolbar2Wx as NavigationToolbar2WxCairo)
import wx.lib.wxcairo as wxcairo


class FigureFrameWxCairo(FigureFrameWx):
def get_canvas(self, fig):
return FigureCanvasWxCairo(self, -1, fig)
canvas = FigureCanvasWxCairo(fig)
canvas.Reparent(self)
return canvas


class FigureCanvasWxCairo(_FigureCanvasWxBase, FigureCanvasCairo):
Expand All @@ -27,12 +29,13 @@ class FigureCanvasWxCairo(_FigureCanvasWxBase, FigureCanvasCairo):
we give a hint as to our preferred minimum size.
"""

def __init__(self, parent, id, figure):
def __init__(self, *args):
# _FigureCanvasWxBase should be fixed to have the same signature as
# every other FigureCanvas and use cooperative inheritance, but in the
# meantime the following will make do.
_FigureCanvasWxBase.__init__(self, parent, id, figure)
FigureCanvasCairo.__init__(self, figure)
# meantime the following will make do. (`args[-1]` is always the
# figure.)
_FigureCanvasWxBase.__init__(self, *args)
FigureCanvasCairo.__init__(self, args[-1])
self._renderer = RendererCairo(self.figure.dpi)

def draw(self, drawDC=None):
Expand Down