@@ -3266,16 +3266,17 @@ def _get_toolbar(self, toolbar, canvas):
3266
3266
3267
3267
@property
3268
3268
def active_toggle (self ):
3269
- """Get the tooggled Tool"""
3269
+ """Toggled Tool
3270
+
3271
+ **string** : Currently toggled tool, or None
3272
+ """
3270
3273
return self ._toggled
3271
3274
3272
- def get_instances (self ):
3273
- """Get the active tools instgances
3275
+ @property
3276
+ def instances (self ):
3277
+ """Active tools instances
3274
3278
3275
- Returns
3276
- ----------
3277
- A dictionary with the active instances that are registered with
3278
- Navigation
3279
+ **dictionary** : Contains the active instances that are registered
3279
3280
"""
3280
3281
return self ._instances
3281
3282
@@ -3289,7 +3290,7 @@ def get_tool_keymap(self, name):
3289
3290
3290
3291
Returns
3291
3292
----------
3292
- Keymap : list of keys associated with the Tool
3293
+ list : list of keys associated with the Tool
3293
3294
"""
3294
3295
keys = [k for k , i in self ._keys .items () if i == name ]
3295
3296
return keys
@@ -3321,6 +3322,11 @@ def set_tool_keymap(self, name, *keys):
3321
3322
def unregister (self , name ):
3322
3323
"""Unregister the tool from the active instances
3323
3324
3325
+ Parameters
3326
+ ----------
3327
+ name : string
3328
+ Name of the tool to unregister
3329
+
3324
3330
Notes
3325
3331
-----
3326
3332
This method is used by `PersistentTools` to remove the reference kept
@@ -3330,8 +3336,7 @@ def unregister(self, name):
3330
3336
destroy if it is a graphical Tool.
3331
3337
3332
3338
If called, next time the `Tool` is used it will be reinstantiated
3333
- instead
3334
- of using the existing instance.
3339
+ instead of using the existing instance.
3335
3340
"""
3336
3341
if self ._toggled == name :
3337
3342
self ._handle_toggle (name , from_toolbar = False )
@@ -3408,24 +3413,21 @@ def _get_cls_to_instantiate(self, callback_class):
3408
3413
3409
3414
return callback_class
3410
3415
3411
- def _key_press (self , event ):
3412
- if event .key is None :
3413
- return
3416
+ def click_tool (self , name ):
3417
+ """Simulate a click on a tool
3414
3418
3415
- #some tools may need to capture keypress, but they need to be toggle
3416
- if self ._toggled :
3417
- instance = self ._get_instance (self ._toggled )
3418
- if self .keypresslock .isowner (instance ):
3419
- instance .key_press (event )
3420
- return
3419
+ This is a convenient method to programatically click on
3420
+ Tools
3421
+ """
3422
+ self ._tool_activate (name , None , False )
3421
3423
3422
- name = self . _keys . get ( event . key , None )
3423
- if name is None :
3424
- return
3424
+ def _tool_activate ( self , name , event , from_toolbar ):
3425
+ if name not in self . _tools :
3426
+ raise AttributeError ( '%s not in Tools' % name )
3425
3427
3426
3428
tool = self ._tools [name ]
3427
3429
if tool .toggle :
3428
- self ._handle_toggle (name , event = event )
3430
+ self ._handle_toggle (name , event = event , from_toolbar = from_toolbar )
3429
3431
elif tool .persistent :
3430
3432
instance = self ._get_instance (name )
3431
3433
instance .activate (event )
@@ -3434,6 +3436,20 @@ def _key_press(self, event):
3434
3436
#instantiated and forgotten (reminds me an exgirlfriend?)
3435
3437
tool (self .canvas .figure , event )
3436
3438
3439
+ def _key_press (self , event ):
3440
+ if event .key is None :
3441
+ return
3442
+
3443
+ #some tools may need to capture keypress, but they need to be toggle
3444
+ if self ._toggled :
3445
+ instance = self ._get_instance (self ._toggled )
3446
+ if self .keypresslock .isowner (instance ):
3447
+ instance .key_press (event )
3448
+ return
3449
+
3450
+ name = self ._keys .get (event .key , None )
3451
+ self ._tool_activate (name , event , False )
3452
+
3437
3453
def _get_instance (self , name ):
3438
3454
if name not in self ._instances :
3439
3455
instance = self ._tools [name ](self .canvas .figure )
@@ -3454,14 +3470,7 @@ def _toolbar_callback(self, name):
3454
3470
Name of the tool that was activated (click) by the user using the
3455
3471
toolbar
3456
3472
"""
3457
- tool = self ._tools [name ]
3458
- if tool .toggle :
3459
- self ._handle_toggle (name , from_toolbar = True )
3460
- elif tool .persistent :
3461
- instance = self ._get_instance (name )
3462
- instance .activate (None )
3463
- else :
3464
- tool (self .canvas .figure , None )
3473
+ self ._tool_activate (name , None , True )
3465
3474
3466
3475
def _handle_toggle (self , name , event = None , from_toolbar = False ):
3467
3476
#toggle toolbar without callback
0 commit comments