Skip to content
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
23 changes: 16 additions & 7 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3220,13 +3220,6 @@ def __init__(self, manager):
# to write into toolbar message
self.messagelock = widgets.LockDraw()

for name, tool in tools.tools:
if tool is None:
if self.toolbar is not None:
self.toolbar.add_separator(-1)
else:
self.add_tool(name, tool, None)

self._last_cursor = self._default_cursor

@property
Expand Down Expand Up @@ -3329,6 +3322,22 @@ def remove_tool(self, name):
if self.toolbar:
self.toolbar._remove_toolitem(name)

def add_tools(self, tools):
""" Add multiple tools to `Navigation`

Parameters
----------
tools : a list of tuples which contains the id of the tool and
a either a reference to the tool Tool class itself, or None to
insert a spacer. See :func:`add_tool`.
"""
for name, tool in tools:
if tool is None:
if self.toolbar is not None:
self.toolbar.add_separator(-1)
else:
self.add_tool(name, tool, None)

def add_tool(self, name, tool, position=None):
"""Add tool to `Navigation`

Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase
from matplotlib.backend_bases import ShowBase, ToolbarBase, NavigationBase
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, tools

from matplotlib.cbook import is_string_like, is_writable_file_like
from matplotlib.colors import colorConverter
Expand Down Expand Up @@ -415,6 +415,8 @@ def __init__(self, canvas, num):

self.toolbar = self._get_toolbar()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all the backends use the same _get_toolbar method. So far every backend implementation has been up to the developer to decide how to do it, check backend_wx.py that is really different from the others

self.navigation = self._get_navigation()
if matplotlib.rcParams['toolbar'] == 'navigation':
self.navigation.add_tools(tools)

# calculate size for window
w = int (self.canvas.figure.bbox.width)
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase
from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase
from matplotlib.backend_bases import ShowBase, ToolbarBase, NavigationBase
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, tools
from matplotlib._pylab_helpers import Gcf

from matplotlib.figure import Figure
Expand Down Expand Up @@ -538,6 +538,8 @@ def __init__(self, canvas, num, window):

self.toolbar = self._get_toolbar()
self.navigation = self._get_navigation()
if matplotlib.rcParams['toolbar'] == 'navigation':
self.navigation.add_tools(tools)

if self.toolbar is not None:
self.toolbar.update()
Expand Down