@@ -2586,6 +2586,8 @@ def __init__(self, canvas, num):
2586
2586
self .key_press_handler_id = self .canvas .mpl_connect (
2587
2587
'key_press_event' ,
2588
2588
self .key_press )
2589
+ else :
2590
+ self .key_press_handler_id = None
2589
2591
"""
2590
2592
The returned id from connecting the default key handler via
2591
2593
:meth:`FigureCanvasBase.mpl_connnect`.
@@ -3331,11 +3333,7 @@ def message_event(self, message, sender=None):
3331
3333
3332
3334
@property
3333
3335
def active_toggle (self ):
3334
- """
3335
- Toggled Tool
3336
-
3337
- **dict** : Currently toggled tools
3338
- """
3336
+ """Currently toggled tools"""
3339
3337
3340
3338
return self ._toggled
3341
3339
@@ -3360,7 +3358,7 @@ def _remove_keys(self, name):
3360
3358
for k in self .get_tool_keymap (name ):
3361
3359
del self ._keys [k ]
3362
3360
3363
- def set_tool_keymap (self , name , * keys ):
3361
+ def update_keymap (self , name , * keys ):
3364
3362
"""
3365
3363
Set the keymap to associate with the specified tool
3366
3364
@@ -3449,30 +3447,31 @@ def add_tool(self, name, tool, *args, **kwargs):
3449
3447
"""
3450
3448
3451
3449
tool_cls = self ._get_cls_to_instantiate (tool )
3452
- if tool_cls is False :
3450
+ if not tool_cls :
3453
3451
raise ValueError ('Impossible to find class for %s' % str (tool ))
3454
3452
3455
3453
if name in self ._tools :
3456
3454
warnings .warn ('A "Tool class" with the same name already exists, '
3457
3455
'not added' )
3458
3456
return self ._tools [name ]
3459
3457
3460
- self ._tools [name ] = tool_cls (self , name , * args , ** kwargs )
3458
+ tool_obj = tool_cls (self , name , * args , ** kwargs )
3459
+ self ._tools [name ] = tool_obj
3461
3460
3462
- if tool_cls .keymap is not None :
3463
- self .set_tool_keymap (name , tool_cls .keymap )
3461
+ if tool_cls .default_keymap is not None :
3462
+ self .update_keymap (name , tool_cls .default_keymap )
3464
3463
3465
3464
# For toggle tools init the radio_group in self._toggled
3466
- if isinstance (self . _tools [ name ] , tools .ToolToggleBase ):
3465
+ if isinstance (tool_obj , tools .ToolToggleBase ):
3467
3466
# None group is not mutually exclusive, a set is used to keep track
3468
3467
# of all toggled tools in this group
3469
- if tool_cls .radio_group is None :
3468
+ if tool_obj .radio_group is None :
3470
3469
self ._toggled .setdefault (None , set ())
3471
3470
else :
3472
- self ._toggled .setdefault (tool_cls .radio_group , None )
3471
+ self ._toggled .setdefault (tool_obj .radio_group , None )
3473
3472
3474
- self ._tool_added_event (self . _tools [ name ] )
3475
- return self . _tools [ name ]
3473
+ self ._tool_added_event (tool_obj )
3474
+ return tool_obj
3476
3475
3477
3476
def _tool_added_event (self , tool ):
3478
3477
s = 'tool_added_event'
@@ -3483,6 +3482,16 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
3483
3482
"""
3484
3483
Toggle tools, need to untoggle prior to using other Toggle tool
3485
3484
Called from tool_trigger_event
3485
+
3486
+ Parameters
3487
+ ----------
3488
+ tool: Tool object
3489
+ sender: object
3490
+ Object that wishes to trigger the tool
3491
+ canvasevent : Event
3492
+ Original Canvas event or None
3493
+ data : Object
3494
+ Extra data to pass to the tool when triggering
3486
3495
"""
3487
3496
3488
3497
radio_group = tool .radio_group
@@ -3500,7 +3509,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
3500
3509
toggled = None
3501
3510
# If no tool was toggled in the radio_group
3502
3511
# toggle it
3503
- elif self ._toggled . get ( radio_group , None ) is None :
3512
+ elif self ._toggled [ radio_group ] is None :
3504
3513
toggled = tool .name
3505
3514
# Other tool in the radio_group is toggled
3506
3515
else :
@@ -3521,15 +3530,18 @@ def _get_cls_to_instantiate(self, callback_class):
3521
3530
if isinstance (callback_class , six .string_types ):
3522
3531
# FIXME: make more complete searching structure
3523
3532
if callback_class in globals ():
3524
- return globals ()[callback_class ]
3525
-
3526
- mod = self .__class__ .__module__
3527
- current_module = __import__ (mod ,
3528
- globals (), locals (), [mod ], 0 )
3533
+ callback_class = globals ()[callback_class ]
3534
+ else :
3535
+ mod = self .__class__ .__module__
3536
+ current_module = __import__ (mod ,
3537
+ globals (), locals (), [mod ], 0 )
3529
3538
3530
- return getattr (current_module , callback_class , False )
3539
+ callback_class = getattr (current_module , callback_class , False )
3531
3540
3532
- return callback_class
3541
+ if callable (callback_class ):
3542
+ return callback_class
3543
+ else :
3544
+ return None
3533
3545
3534
3546
def tool_trigger_event (self , name , sender = None , canvasevent = None ,
3535
3547
data = None ):
@@ -3598,7 +3610,7 @@ def get_tool(self, name, warn=True):
3598
3610
-----------
3599
3611
name : str, ToolBase
3600
3612
Name of the tool, or the tool itself
3601
- warn : bool
3613
+ warn : bool, optional
3602
3614
If this method should give warnings.
3603
3615
"""
3604
3616
if isinstance (name , tools .ToolBase ) and name .name in self ._tools :
0 commit comments