@@ -3440,7 +3440,13 @@ def add_tool(self, name, tool):
3440
3440
'not added' )
3441
3441
return
3442
3442
3443
- self ._tools [name ] = tool_cls (self , name )
3443
+ if isinstance (tool_cls , type ):
3444
+ self ._tools [name ] = tool_cls (self , name )
3445
+ else :
3446
+ tool_cls .set_navigation (self )
3447
+ tool .name = name
3448
+ self ._tools [name ] = tool_cls
3449
+
3444
3450
if tool_cls .keymap is not None :
3445
3451
self .set_tool_keymap (name , tool_cls .keymap )
3446
3452
@@ -3455,6 +3461,8 @@ def add_tool(self, name, tool):
3455
3461
3456
3462
self ._tool_added_event (self ._tools [name ])
3457
3463
3464
+ return self ._tools [name ]
3465
+
3458
3466
def _tool_added_event (self , tool ):
3459
3467
s = 'tool_added_event'
3460
3468
event = ToolEvent (s , self , tool )
@@ -3629,10 +3637,20 @@ def add_tools(self, tools):
3629
3637
3630
3638
for group , grouptools in tools :
3631
3639
for position , tool in enumerate (grouptools ):
3632
- self .add_tool (self . navigation . get_tool ( tool ) , group , position )
3640
+ self .add_tool (tool , group , position )
3633
3641
3634
3642
def add_tool (self , tool , group , position ):
3635
3643
"""Adds a tool to the toolbar"""
3644
+ t = self .navigation .get_tool (tool )
3645
+ if t is None :
3646
+ if isinstance (tool , (list , tuple )):
3647
+ t = self .navigation .add_tool (tool [0 ], tool [1 ])
3648
+ elif isinstance (tool , ToolBase ):
3649
+ t = self .navigation .add_tool (tool .name , tool )
3650
+ else :
3651
+ warning .warn ('Cannot add tool %s' % tool )
3652
+ return
3653
+ tool = t
3636
3654
image = self ._get_image_filename (tool .image )
3637
3655
toggle = getattr (tool , 'toggled' , None ) is not None
3638
3656
self .add_toolitem (tool .name , group , position , image ,
0 commit comments