From d4f73c1794304d8c3080ea75058012c3ad721367 Mon Sep 17 00:00:00 2001 From: DietmarSchwertberger Date: Tue, 2 Jan 2018 23:36:21 +0100 Subject: [PATCH 1/2] refactor non wx.ToolBar specific parts of NavigationToolbar2Wx and WxAgg into separate classes NavigationController2Wx/Agg to be used separately bug fix: add missing 'import six' --- lib/matplotlib/backends/backend_wx.py | 68 ++++++++++++++---------- lib/matplotlib/backends/backend_wxagg.py | 8 ++- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 0aabab7bc098..2b4de3ccf8d1 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -17,6 +17,7 @@ unicode_literals) from six.moves import xrange +import six import sys import os @@ -1483,9 +1484,13 @@ def __init__(self, targetfig): tool = SubplotTool(targetfig, toolfig) -class NavigationToolbar2Wx(NavigationToolbar2, wx.ToolBar): +class NavigationController2Wx(NavigationToolbar2): + """ + The parts from NavigationToolbar2Wx that are not specific to wx.ToolBar; + so this functionality can be used without adding a toolbar. + """ + def __init__(self, canvas): - wx.ToolBar.__init__(self, canvas.GetParent(), -1) NavigationToolbar2.__init__(self, canvas) self.canvas = canvas self._idle = True @@ -1501,33 +1506,8 @@ def get_canvas(self, frame, fig): return FigureCanvasWx(frame, -1, fig) def _init_toolbar(self): - DEBUG_MSG("_init_toolbar", 1, self) - self._parent = self.canvas.GetParent() - self.wx_ids = {} - for text, tooltip_text, image_file, callback in self.toolitems: - if text is None: - self.AddSeparator() - continue - self.wx_ids[text] = wx.NewId() - wxc._AddTool(self, self.wx_ids, text, - _load_bitmap(image_file + '.png'), - tooltip_text) - - self.Bind(wx.EVT_TOOL, getattr(self, callback), - id=self.wx_ids[text]) - - self.Realize() - - def zoom(self, *args): - self.ToggleTool(self.wx_ids['Pan'], False) - NavigationToolbar2.zoom(self, *args) - - def pan(self, *args): - self.ToggleTool(self.wx_ids['Zoom'], False) - NavigationToolbar2.pan(self, *args) - def configure_subplots(self, evt): frame = wx.Frame(None, -1, "Configure subplots") @@ -1688,6 +1668,40 @@ def set_message(self, s): if self.statbar is not None: self.statbar.set_function(s) + +class NavigationToolbar2Wx(NavigationController2Wx, wx.ToolBar): + def __init__(self, canvas): + wx.ToolBar.__init__(self, canvas.GetParent(), -1) + NavigationController2Wx.__init__(self, canvas) + + def _init_toolbar(self): + DEBUG_MSG("_init_toolbar", 1, self) + + self._parent = self.canvas.GetParent() + + self.wx_ids = {} + for text, tooltip_text, image_file, callback in self.toolitems: + if text is None: + self.AddSeparator() + continue + self.wx_ids[text] = wx.NewId() + wxc._AddTool(self, self.wx_ids, text, + _load_bitmap(image_file + '.png'), + tooltip_text) + + self.Bind(wx.EVT_TOOL, getattr(self, callback), + id=self.wx_ids[text]) + + self.Realize() + + def zoom(self, *args): + self.ToggleTool(self.wx_ids['Pan'], False) + NavigationToolbar2.zoom(self, *args) + + def pan(self, *args): + self.ToggleTool(self.wx_ids['Zoom'], False) + NavigationToolbar2.pan(self, *args) + def set_history_buttons(self): can_backward = self._nav_stack._pos > 0 can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1 diff --git a/lib/matplotlib/backends/backend_wxagg.py b/lib/matplotlib/backends/backend_wxagg.py index 8383f50cde89..df2456015c98 100644 --- a/lib/matplotlib/backends/backend_wxagg.py +++ b/lib/matplotlib/backends/backend_wxagg.py @@ -9,8 +9,8 @@ from . import wx_compat as wxc from . import backend_wx from .backend_agg import FigureCanvasAgg -from .backend_wx import ( - _BackendWx, FigureCanvasWx, FigureFrameWx, NavigationToolbar2Wx, DEBUG_MSG) +from .backend_wx import (_BackendWx, FigureCanvasWx, FigureFrameWx, + NavigationToolbar2Wx, NavigationController2Wx, DEBUG_MSG) class FigureFrameWxAgg(FigureFrameWx): @@ -90,6 +90,10 @@ def print_figure(self, filename, *args, **kwargs): self.draw() +class NavigationController2WxAgg(NavigationController2Wx): + def get_canvas(self, frame, fig): + return FigureCanvasWxAgg(frame, -1, fig) + class NavigationToolbar2WxAgg(NavigationToolbar2Wx): def get_canvas(self, frame, fig): return FigureCanvasWxAgg(frame, -1, fig) From adb60c2d62db8c7ace93e6d1e27f1799386ab244 Mon Sep 17 00:00:00 2001 From: DietmarSchwertberger Date: Wed, 3 Jan 2018 17:17:49 +0100 Subject: [PATCH 2/2] adjust whitespace to avoid Travis CI warnings --- lib/matplotlib/backends/backend_wxagg.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_wxagg.py b/lib/matplotlib/backends/backend_wxagg.py index df2456015c98..91ef3fc0f040 100644 --- a/lib/matplotlib/backends/backend_wxagg.py +++ b/lib/matplotlib/backends/backend_wxagg.py @@ -92,7 +92,8 @@ def print_figure(self, filename, *args, **kwargs): class NavigationController2WxAgg(NavigationController2Wx): def get_canvas(self, frame, fig): - return FigureCanvasWxAgg(frame, -1, fig) + return FigureCanvasWxAgg(frame, -1, fig) + class NavigationToolbar2WxAgg(NavigationToolbar2Wx): def get_canvas(self, frame, fig): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy