Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor non wx.ToolBar specific parts of NavigationToolbar2Wx and Wx…
…Agg into

separate classes NavigationController2Wx/Agg to be used separately

bug fix: add missing 'import six'
  • Loading branch information
DietmarSchwertberger committed Jan 2, 2018
commit d4f73c1794304d8c3080ea75058012c3ad721367
68 changes: 41 additions & 27 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
unicode_literals)

from six.moves import xrange
import six

import sys
import os
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/backends/backend_wxagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down