From 4a9f6a8a1076916cf964d981c1791fd4772d31aa Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 7 Sep 2019 13:01:40 +0200 Subject: [PATCH] Various backend cleanups. - Noninteractive backends don't need to redefine `draw()` as a do-nothing: that's already the default in the base class. - The pgf backend manager can just be an alias for FigureManagerBase: this is consistent with the other noninteractive backends. - FigureCanvasQT doesn't need to assign `self.figure = figure`: that's already done in the super() init. - Use star-unpack in backend_template. - The list of event handlers set up by backend_wx is much bigger than previously documented. --- lib/matplotlib/backends/backend_pdf.py | 5 ----- lib/matplotlib/backends/backend_pgf.py | 4 +--- lib/matplotlib/backends/backend_ps.py | 4 ---- lib/matplotlib/backends/backend_qt5.py | 1 - lib/matplotlib/backends/backend_template.py | 3 +-- lib/matplotlib/backends/backend_wx.py | 9 ++++----- 6 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 7e3b600196bf..f4e254a0e9cb 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2498,14 +2498,9 @@ class FigureCanvasPdf(FigureCanvasBase): ---------- figure : `matplotlib.figure.Figure` A high-level Figure instance - """ fixed_dpi = 72 - - def draw(self): - pass - filetypes = {'pdf': 'Portable Document Format'} def get_default_filetype(self): diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index da124a2dde69..49427b1f6fbf 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -952,14 +952,12 @@ def get_renderer(self): return RendererPgf(self.figure, None, dummy=True) -class FigureManagerPgf(FigureManagerBase): - pass +FigureManagerPgf = FigureManagerBase @_Backend.export class _BackendPgf(_Backend): FigureCanvas = FigureCanvasPgf - FigureManager = FigureManagerPgf def _cleanup_all(): diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 4c6848110237..958ad6204210 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -748,10 +748,6 @@ def swap_if_landscape(self, shape): class FigureCanvasPS(FigureCanvasBase): fixed_dpi = 72 - - def draw(self): - pass - filetypes = {'ps': 'Postscript', 'eps': 'Encapsulated Postscript'} diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 6b8a7ceb034b..46b684bba928 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -222,7 +222,6 @@ def __init__(self, figure): _create_qApp() super().__init__(figure=figure) - self.figure = figure # We don't want to scale up the figure DPI more than once. # Note, we don't handle a signal for changing DPI yet. figure._original_dpi = figure.dpi diff --git a/lib/matplotlib/backends/backend_template.py b/lib/matplotlib/backends/backend_template.py index 299a8aac9c1a..19c8c822274b 100644 --- a/lib/matplotlib/backends/backend_template.py +++ b/lib/matplotlib/backends/backend_template.py @@ -200,8 +200,7 @@ def draw(self): # If the file type is not in the base set of filetypes, # you should add it to the class-scope filetypes dictionary as follows: - filetypes = FigureCanvasBase.filetypes.copy() - filetypes['foo'] = 'My magic Foo format' + filetypes = {**FigureCanvasBase.filetypes, 'foo': 'My magic Foo format'} def print_foo(self, filename, *args, **kwargs): """ diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index a01f57aa2bfe..6b94f8c399ac 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -512,12 +512,11 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel): def __init__(self, parent, id, figure): """ - 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. + - Set event handlers for resize, paint, and keyboard and mouse + interaction. """ FigureCanvasBase.__init__(self, figure)