@@ -3308,16 +3308,17 @@ def _get_toolbar(self, toolbar, canvas):
3308
3308
3309
3309
@property
3310
3310
def active_toggle (self ):
3311
- """Get the tooggled Tool"""
3311
+ """Toggled Tool
3312
+
3313
+ **string** : Currently toggled tool, or None
3314
+ """
3312
3315
return self ._toggled
3313
3316
3314
- def get_instances (self ):
3315
- """Get the active tools instgances
3317
+ @property
3318
+ def instances (self ):
3319
+ """Active tools instances
3316
3320
3317
- Returns
3318
- ----------
3319
- A dictionary with the active instances that are registered with
3320
- Navigation
3321
+ **dictionary** : Contains the active instances that are registered
3321
3322
"""
3322
3323
return self ._instances
3323
3324
@@ -3331,7 +3332,7 @@ def get_tool_keymap(self, name):
3331
3332
3332
3333
Returns
3333
3334
----------
3334
- Keymap : list of keys associated with the Tool
3335
+ list : list of keys associated with the Tool
3335
3336
"""
3336
3337
keys = [k for k , i in self ._keys .items () if i == name ]
3337
3338
return keys
@@ -3363,6 +3364,11 @@ def set_tool_keymap(self, name, *keys):
3363
3364
def unregister (self , name ):
3364
3365
"""Unregister the tool from the active instances
3365
3366
3367
+ Parameters
3368
+ ----------
3369
+ name : string
3370
+ Name of the tool to unregister
3371
+
3366
3372
Notes
3367
3373
-----
3368
3374
This method is used by `PersistentTools` to remove the reference kept
@@ -3372,8 +3378,7 @@ def unregister(self, name):
3372
3378
destroy if it is a graphical Tool.
3373
3379
3374
3380
If called, next time the `Tool` is used it will be reinstantiated
3375
- instead
3376
- of using the existing instance.
3381
+ instead of using the existing instance.
3377
3382
"""
3378
3383
if self ._toggled == name :
3379
3384
self ._handle_toggle (name , from_toolbar = False )
@@ -3450,24 +3455,21 @@ def _get_cls_to_instantiate(self, callback_class):
3450
3455
3451
3456
return callback_class
3452
3457
3453
- def _key_press (self , event ):
3454
- if event .key is None :
3455
- return
3458
+ def click_tool (self , name ):
3459
+ """Simulate a click on a tool
3456
3460
3457
- #some tools may need to capture keypress, but they need to be toggle
3458
- if self ._toggled :
3459
- instance = self ._get_instance (self ._toggled )
3460
- if self .keypresslock .isowner (instance ):
3461
- instance .key_press (event )
3462
- return
3461
+ This is a convenient method to programatically click on
3462
+ Tools
3463
+ """
3464
+ self ._tool_activate (name , None , False )
3463
3465
3464
- name = self . _keys . get ( event . key , None )
3465
- if name is None :
3466
- return
3466
+ def _tool_activate ( self , name , event , from_toolbar ):
3467
+ if name not in self . _tools :
3468
+ raise AttributeError ( '%s not in Tools' % name )
3467
3469
3468
3470
tool = self ._tools [name ]
3469
3471
if tool .toggle :
3470
- self ._handle_toggle (name , event = event )
3472
+ self ._handle_toggle (name , event = event , from_toolbar = from_toolbar )
3471
3473
elif tool .persistent :
3472
3474
instance = self ._get_instance (name )
3473
3475
instance .activate (event )
@@ -3476,6 +3478,20 @@ def _key_press(self, event):
3476
3478
#instantiated and forgotten (reminds me an exgirlfriend?)
3477
3479
tool (self .canvas .figure , event )
3478
3480
3481
+ def _key_press (self , event ):
3482
+ if event .key is None :
3483
+ return
3484
+
3485
+ #some tools may need to capture keypress, but they need to be toggle
3486
+ if self ._toggled :
3487
+ instance = self ._get_instance (self ._toggled )
3488
+ if self .keypresslock .isowner (instance ):
3489
+ instance .key_press (event )
3490
+ return
3491
+
3492
+ name = self ._keys .get (event .key , None )
3493
+ self ._tool_activate (name , event , False )
3494
+
3479
3495
def _get_instance (self , name ):
3480
3496
if name not in self ._instances :
3481
3497
instance = self ._tools [name ](self .canvas .figure )
@@ -3496,14 +3512,7 @@ def _toolbar_callback(self, name):
3496
3512
Name of the tool that was activated (click) by the user using the
3497
3513
toolbar
3498
3514
"""
3499
- tool = self ._tools [name ]
3500
- if tool .toggle :
3501
- self ._handle_toggle (name , from_toolbar = True )
3502
- elif tool .persistent :
3503
- instance = self ._get_instance (name )
3504
- instance .activate (None )
3505
- else :
3506
- tool (self .canvas .figure , None )
3515
+ self ._tool_activate (name , None , True )
3507
3516
3508
3517
def _handle_toggle (self , name , event = None , from_toolbar = False ):
3509
3518
#toggle toolbar without callback
0 commit comments