@@ -3405,17 +3405,15 @@ def add_tools(self, tools):
3405
3405
----------
3406
3406
tools : List
3407
3407
List in the form
3408
- [[group1, [(Tool1, name1), (Tool2, name2) ...]][group2...]]
3409
- where group1 is the name of the group where the
3410
- Tool1, Tool2... are going to be added, and name1, name2... are the
3411
- names of the tools
3408
+ [(Tool1, name1), (Tool2, name2) ...]
3409
+ where Tool1, name1 represent the tool, and the respective name
3410
+ of the tool which gets used as an id.
3412
3411
"""
3413
3412
3414
- for group , grouptools in tools :
3415
- for position , tool in enumerate (grouptools ):
3416
- self .add_tool (tool [1 ], tool [0 ], group , position )
3413
+ for tool , name in tools :
3414
+ self .add_tool (name , tool )
3417
3415
3418
- def add_tool (self , name , tool , group = None , position = None ):
3416
+ def add_tool (self , name , tool ):
3419
3417
"""Add tool to `NavigationBase`
3420
3418
3421
3419
Add a tool to the tools controlled by Navigation
@@ -3430,10 +3428,6 @@ def add_tool(self, name, tool, group=None, position=None):
3430
3428
Name of the tool, treated as the ID, has to be unique
3431
3429
tool : string or `matplotlib.backend_tools.ToolBase` derived class
3432
3430
Reference to find the class of the Tool to be added
3433
- group: String
3434
- Group to position the tool in
3435
- position : int or None (default)
3436
- Position within its group in the toolbar, if None, it goes at the end
3437
3431
"""
3438
3432
3439
3433
tool_cls = self ._get_cls_to_instantiate (tool )
@@ -3459,14 +3453,11 @@ def add_tool(self, name, tool, group=None, position=None):
3459
3453
else :
3460
3454
self ._toggled .setdefault (tool_cls .radio_group , None )
3461
3455
3462
- self ._tool_added_event (self ._tools [name ], group , position )
3456
+ self ._tool_added_event (self ._tools [name ])
3463
3457
3464
- def _tool_added_event (self , tool , group , position ):
3458
+ def _tool_added_event (self , tool ):
3465
3459
s = 'tool_added_event'
3466
- event = ToolEvent (s ,
3467
- self ,
3468
- tool ,
3469
- data = {'group' : group , 'position' : position })
3460
+ event = ToolEvent (s , self , tool )
3470
3461
self ._callbacks .process (s , event )
3471
3462
3472
3463
def _handle_toggle (self , tool , sender , canvasevent , data ):
@@ -3606,7 +3597,6 @@ def __init__(self, navigation):
3606
3597
self .navigation = navigation
3607
3598
3608
3599
self .navigation .nav_connect ('tool_message_event' , self ._message_cbk )
3609
- self .navigation .nav_connect ('tool_added_event' , self ._add_tool_cbk )
3610
3600
self .navigation .nav_connect ('tool_removed_event' ,
3611
3601
self ._remove_tool_cbk )
3612
3602
@@ -3624,18 +3614,31 @@ def _tool_triggered_cbk(self, event):
3624
3614
3625
3615
self .toggle_toolitem (event .tool .name )
3626
3616
3627
- def _add_tool_cbk (self , event ):
3628
- """Captures 'tool_added_event' and adds the tool to the toolbar"""
3629
- image = self ._get_image_filename (event .tool .image )
3630
- toggle = getattr (event .tool , 'toggled' , None ) is not None
3631
- self .add_toolitem (event .tool .name ,
3632
- event .data ['group' ],
3633
- event .data ['position' ],
3634
- image ,
3635
- event .tool .description ,
3636
- toggle )
3617
+ def add_tools (self , tools ):
3618
+ """ Add multiple tools to `Navigation`
3619
+
3620
+ Parameters
3621
+ ----------
3622
+ tools : List
3623
+ List in the form
3624
+ [[group1, [name1, name2 ...]][group2...]]
3625
+ where group1 is the name of the group where the
3626
+ Tool1, Tool2... are going to be added, and name1, name2... are the
3627
+ names of the tools
3628
+ """
3629
+
3630
+ for group , grouptools in tools :
3631
+ for position , tool in enumerate (grouptools ):
3632
+ self .add_tool (self .navigation .get_tool (tool ), group , position )
3633
+
3634
+ def add_tool (self , tool , group , position ):
3635
+ """Adds a tool to the toolbar"""
3636
+ image = self ._get_image_filename (tool .image )
3637
+ toggle = getattr (tool , 'toggled' , None ) is not None
3638
+ self .add_toolitem (tool .name , group , position , image ,
3639
+ tool .description , toggle )
3637
3640
if toggle :
3638
- self .navigation .nav_connect ('tool_trigger_%s' % event . tool .name ,
3641
+ self .navigation .nav_connect ('tool_trigger_%s' % tool .name ,
3639
3642
self ._tool_triggered_cbk )
3640
3643
3641
3644
def _remove_tool_cbk (self , event ):
0 commit comments