@@ -2586,6 +2586,8 @@ def __init__(self, canvas, num):
25862586 self .key_press_handler_id = self .canvas .mpl_connect (
25872587 'key_press_event' ,
25882588 self .key_press )
2589+ else :
2590+ self .key_press_handler_id = None
25892591 """
25902592 The returned id from connecting the default key handler via
25912593 :meth:`FigureCanvasBase.mpl_connnect`.
@@ -3331,11 +3333,7 @@ def message_event(self, message, sender=None):
33313333
33323334 @property
33333335 def active_toggle (self ):
3334- """
3335- Toggled Tool
3336-
3337- **dict** : Currently toggled tools
3338- """
3336+ """Currently toggled tools"""
33393337
33403338 return self ._toggled
33413339
@@ -3360,7 +3358,7 @@ def _remove_keys(self, name):
33603358 for k in self .get_tool_keymap (name ):
33613359 del self ._keys [k ]
33623360
3363- def set_tool_keymap (self , name , * keys ):
3361+ def update_keymap (self , name , * keys ):
33643362 """
33653363 Set the keymap to associate with the specified tool
33663364
@@ -3449,30 +3447,31 @@ def add_tool(self, name, tool, *args, **kwargs):
34493447 """
34503448
34513449 tool_cls = self ._get_cls_to_instantiate (tool )
3452- if tool_cls is False :
3450+ if not tool_cls :
34533451 raise ValueError ('Impossible to find class for %s' % str (tool ))
34543452
34553453 if name in self ._tools :
34563454 warnings .warn ('A "Tool class" with the same name already exists, '
34573455 'not added' )
34583456 return self ._tools [name ]
34593457
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
34613460
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 )
34643463
34653464 # 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 ):
34673466 # None group is not mutually exclusive, a set is used to keep track
34683467 # of all toggled tools in this group
3469- if tool_cls .radio_group is None :
3468+ if tool_obj .radio_group is None :
34703469 self ._toggled .setdefault (None , set ())
34713470 else :
3472- self ._toggled .setdefault (tool_cls .radio_group , None )
3471+ self ._toggled .setdefault (tool_obj .radio_group , None )
34733472
3474- self ._tool_added_event (self . _tools [ name ] )
3475- return self . _tools [ name ]
3473+ self ._tool_added_event (tool_obj )
3474+ return tool_obj
34763475
34773476 def _tool_added_event (self , tool ):
34783477 s = 'tool_added_event'
@@ -3483,6 +3482,16 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
34833482 """
34843483 Toggle tools, need to untoggle prior to using other Toggle tool
34853484 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
34863495 """
34873496
34883497 radio_group = tool .radio_group
@@ -3500,7 +3509,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
35003509 toggled = None
35013510 # If no tool was toggled in the radio_group
35023511 # toggle it
3503- elif self ._toggled . get ( radio_group , None ) is None :
3512+ elif self ._toggled [ radio_group ] is None :
35043513 toggled = tool .name
35053514 # Other tool in the radio_group is toggled
35063515 else :
@@ -3521,15 +3530,18 @@ def _get_cls_to_instantiate(self, callback_class):
35213530 if isinstance (callback_class , six .string_types ):
35223531 # FIXME: make more complete searching structure
35233532 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 )
35293538
3530- return getattr (current_module , callback_class , False )
3539+ callback_class = getattr (current_module , callback_class , False )
35313540
3532- return callback_class
3541+ if callable (callback_class ):
3542+ return callback_class
3543+ else :
3544+ return None
35333545
35343546 def tool_trigger_event (self , name , sender = None , canvasevent = None ,
35353547 data = None ):
@@ -3598,7 +3610,7 @@ def get_tool(self, name, warn=True):
35983610 -----------
35993611 name : str, ToolBase
36003612 Name of the tool, or the tool itself
3601- warn : bool
3613+ warn : bool, optional
36023614 If this method should give warnings.
36033615 """
36043616 if isinstance (name , tools .ToolBase ) and name .name in self ._tools :
0 commit comments