Skip to content

Commit 73a2661

Browse files
committed
add_tools moved out of base classes
1 parent 4bbcf4e commit 73a2661

File tree

4 files changed

+55
-43
lines changed

4 files changed

+55
-43
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,20 +3406,6 @@ def remove_tool(self, name):
34063406

34073407
del self._tools[name]
34083408

3409-
def add_tools(self, tools):
3410-
"""
3411-
Add multiple tools to `NavigationBase`
3412-
3413-
Parameters
3414-
----------
3415-
tools : {str: class_like}
3416-
The tools to add in a {name: tool} dict, see `add_tool` for more
3417-
info.
3418-
"""
3419-
3420-
for name, tool in six.iteritems(tools):
3421-
self.add_tool(name, tool)
3422-
34233409
def add_tool(self, name, tool, *args, **kwargs):
34243410
"""
34253411
Add tool to `NavigationBase`
@@ -3515,9 +3501,9 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
35153501
else:
35163502
# Untoggle previously toggled tool
35173503
self.trigger_tool(self._toggled[radio_group],
3518-
self,
3519-
canvasevent,
3520-
data)
3504+
self,
3505+
canvasevent,
3506+
data)
35213507
toggled = tool.name
35223508

35233509
# Keep track of the toggled tool in the radio_group
@@ -3645,23 +3631,6 @@ def _tool_toggled_cbk(self, event):
36453631
"""
36463632
self.toggle_toolitem(event.tool.name, event.tool.toggled)
36473633

3648-
def add_tools(self, tools):
3649-
"""
3650-
Add multiple tools to the container.
3651-
3652-
Parameters
3653-
----------
3654-
tools : list
3655-
List in the form
3656-
[[group1, [tool1, tool2 ...]], [group2, [...]]]
3657-
Where the tools given by tool1, and tool2 will display in group1.
3658-
See `add_tool` for details.
3659-
"""
3660-
3661-
for group, grouptools in tools:
3662-
for position, tool in enumerate(grouptools):
3663-
self.add_tool(tool, group, position)
3664-
36653634
def add_tool(self, tool, group, position=-1):
36663635
"""
36673636
Adds a tool to this container

lib/matplotlib/backend_tools.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import matplotlib.cbook as cbook
1717
from weakref import WeakKeyDictionary
1818
import numpy as np
19+
import six
1920

2021

2122
class Cursors(object):
@@ -946,3 +947,36 @@ def _mouse_move(self, event):
946947
['layout', ['subplots']],
947948
['io', ['save']]]
948949
"""Default tools in the toolbar"""
950+
951+
952+
def add_tools_2_navigation(navigation, tools=tools):
953+
"""
954+
Add multiple tools to `Navigation`
955+
956+
Parameters
957+
----------
958+
tools : {str: class_like}
959+
The tools to add in a {name: tool} dict, see `add_tool` for more
960+
info.
961+
"""
962+
963+
for name, tool in six.iteritems(tools):
964+
navigation.add_tool(name, tool)
965+
966+
967+
def add_tools_2_container(container, tools=toolbar_tools):
968+
"""
969+
Add multiple tools to the container.
970+
971+
Parameters
972+
----------
973+
tools : list
974+
List in the form
975+
[[group1, [tool1, tool2 ...]], [group2, [...]]]
976+
Where the tools given by tool1, and tool2 will display in group1.
977+
See `add_tool` for details.
978+
"""
979+
980+
for group, grouptools in tools:
981+
for position, tool in enumerate(grouptools):
982+
container.add_tool(tool, group, position)

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ def fn_name(): return sys._getframe(1).f_code.co_name
3232
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase
3333
from matplotlib.backend_bases import (ShowBase, ToolContainerBase,
3434
NavigationBase, StatusbarBase)
35-
from matplotlib.backend_tools import (SaveFigureBase, ConfigureSubplotsBase,
36-
tools, toolbar_tools, SetCursorBase, RubberbandBase)
35+
from matplotlib.backend_tools import (SaveFigureBase,
36+
ConfigureSubplotsBase,
37+
add_tools_2_navigation,
38+
add_tools_2_container,
39+
SetCursorBase,
40+
RubberbandBase)
3741

3842
from matplotlib.cbook import is_string_like, is_writable_file_like
3943
from matplotlib.colors import colorConverter
@@ -432,8 +436,10 @@ def add_widget(child, expand, fill, padding):
432436
return size_request.height
433437

434438
if matplotlib.rcParams['toolbar'] == 'navigation':
435-
self.navigation.add_tools(tools)
436-
self.toolbar.add_tools(toolbar_tools)
439+
add_tools_2_navigation(self.navigation)
440+
# self.navigation.add_tools(tools)
441+
# self.toolbar.add_tools(toolbar_tools)
442+
add_tools_2_container(self.toolbar)
437443
self.statusbar = StatusbarGTK3(self.navigation)
438444
h += add_widget(self.statusbar, False, False, 0)
439445
h += add_widget(Gtk.HSeparator(), False, False, 0)

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase
2323
from matplotlib.backend_bases import (ShowBase, ToolContainerBase,
2424
NavigationBase, StatusbarBase)
25-
from matplotlib.backend_tools import (SaveFigureBase, ConfigureSubplotsBase,
26-
tools, toolbar_tools, SetCursorBase, RubberbandBase)
25+
from matplotlib.backend_tools import (SaveFigureBase,
26+
ConfigureSubplotsBase,
27+
add_tools_2_navigation,
28+
add_tools_2_container,
29+
SetCursorBase,
30+
RubberbandBase)
2731
from matplotlib._pylab_helpers import Gcf
2832

2933
from matplotlib.figure import Figure
@@ -540,11 +544,10 @@ def __init__(self, canvas, num, window):
540544
self.statusbar = None
541545

542546
if matplotlib.rcParams['toolbar'] == 'navigation':
543-
self.navigation.add_tools(tools)
544-
self.toolbar.add_tools(toolbar_tools)
547+
add_tools_2_navigation(self.navigation)
548+
add_tools_2_container(self.toolbar)
545549
self.statusbar = StatusbarTk(self.window, self.navigation)
546550

547-
548551
self._shown = False
549552

550553
def notify_axes_change(fig):

0 commit comments

Comments
 (0)