@@ -3244,7 +3244,8 @@ def __init__(self, name, sender, tool, canvasevent=None, data=None):
3244
3244
3245
3245
3246
3246
class NavigationMessageEvent (object ):
3247
- """Event carrying messages from navigation
3247
+ """
3248
+ Event carrying messages from navigation
3248
3249
3249
3250
Messages usually get displayed to the user by the toolbar
3250
3251
"""
@@ -3255,7 +3256,8 @@ def __init__(self, name, sender, message):
3255
3256
3256
3257
3257
3258
class NavigationBase (object ):
3258
- """Helper class that groups all the user interactions for a FigureManager
3259
+ """
3260
+ Helper class that groups all the user interactions for a FigureManager
3259
3261
3260
3262
Attributes
3261
3263
----------
@@ -3281,7 +3283,8 @@ def __init__(self, canvas):
3281
3283
self .messagelock = widgets .LockDraw ()
3282
3284
3283
3285
def nav_connect (self , s , func ):
3284
- """Connect event with string *s* to *func*.
3286
+ """
3287
+ Connect event with string *s* to *func*.
3285
3288
3286
3289
Parameters
3287
3290
-----------
@@ -3306,7 +3309,8 @@ def func(event)
3306
3309
return self ._callbacks .connect (s , func )
3307
3310
3308
3311
def nav_disconnect (self , cid ):
3309
- """Disconnect callback id cid
3312
+ """
3313
+ Disconnect callback id cid
3310
3314
3311
3315
Example usage::
3312
3316
@@ -3317,7 +3321,7 @@ def nav_disconnect(self, cid):
3317
3321
return self ._callbacks .disconnect (cid )
3318
3322
3319
3323
def message_event (self , message , sender = None ):
3320
- """ Emit a tool_message_event event """
3324
+ """ Emit a `NavigationMessageEvent` """
3321
3325
if sender is None :
3322
3326
sender = self
3323
3327
@@ -3327,15 +3331,17 @@ def message_event(self, message, sender=None):
3327
3331
3328
3332
@property
3329
3333
def active_toggle (self ):
3330
- """Toggled Tool
3334
+ """
3335
+ Toggled Tool
3331
3336
3332
3337
**dict** : Currently toggled tools
3333
3338
"""
3334
3339
3335
3340
return self ._toggled
3336
3341
3337
3342
def get_tool_keymap (self , name ):
3338
- """Get the keymap associated with the specified tool
3343
+ """
3344
+ Get the keymap associated with the specified tool
3339
3345
3340
3346
Parameters
3341
3347
----------
@@ -3355,7 +3361,8 @@ def _remove_keys(self, name):
3355
3361
del self ._keys [k ]
3356
3362
3357
3363
def set_tool_keymap (self , name , * keys ):
3358
- """Set the keymap to associate with the specified tool
3364
+ """
3365
+ Set the keymap to associate with the specified tool
3359
3366
3360
3367
Parameters
3361
3368
----------
@@ -3365,7 +3372,7 @@ def set_tool_keymap(self, name, *keys):
3365
3372
"""
3366
3373
3367
3374
if name not in self ._tools :
3368
- raise AttributeError ('%s not in Tools' % name )
3375
+ raise KeyError ('%s not in Tools' % name )
3369
3376
3370
3377
self ._remove_keys (name )
3371
3378
@@ -3377,7 +3384,8 @@ def set_tool_keymap(self, name, *keys):
3377
3384
self ._keys [k ] = name
3378
3385
3379
3386
def remove_tool (self , name ):
3380
- """Remove tool from `Navigation`
3387
+ """
3388
+ Remove tool from `Navigation`
3381
3389
3382
3390
Parameters
3383
3391
----------
@@ -3401,7 +3409,8 @@ def remove_tool(self, name):
3401
3409
del self ._tools [name ]
3402
3410
3403
3411
def add_tools (self , tools ):
3404
- """ Add multiple tools to `NavigationBase`
3412
+ """
3413
+ Add multiple tools to `NavigationBase`
3405
3414
3406
3415
Parameters
3407
3416
----------
@@ -3414,7 +3423,8 @@ def add_tools(self, tools):
3414
3423
self .add_tool (name , tool )
3415
3424
3416
3425
def add_tool (self , name , tool , * args , ** kwargs ):
3417
- """Add tool to `NavigationBase`
3426
+ """
3427
+ Add tool to `NavigationBase`
3418
3428
3419
3429
Add a tool to the tools controlled by Navigation
3420
3430
@@ -3440,11 +3450,10 @@ def add_tool(self, name, tool, *args, **kwargs):
3440
3450
3441
3451
tool_cls = self ._get_cls_to_instantiate (tool )
3442
3452
if tool_cls is False :
3443
- warnings .warn ('Impossible to find class for %s' % str (tool ))
3444
- return
3453
+ raise ValueError ('Impossible to find class for %s' % str (tool ))
3445
3454
3446
3455
if name in self ._tools :
3447
- warnings .warn ('A tool_cls with the same name already exist , '
3456
+ warnings .warn ('A "Tool class" with the same name already exists , '
3448
3457
'not added' )
3449
3458
return self ._tools [name ]
3450
3459
@@ -3454,7 +3463,7 @@ def add_tool(self, name, tool, *args, **kwargs):
3454
3463
self .set_tool_keymap (name , tool_cls .keymap )
3455
3464
3456
3465
# For toggle tools init the radio_group in self._toggled
3457
- if getattr ( tool_cls , 'toggled' , False ) is not False :
3466
+ if isinstance ( self . _tools [ name ], tools . ToolToggleBase ) :
3458
3467
# None group is not mutually exclusive, a set is used to keep track
3459
3468
# of all toggled tools in this group
3460
3469
if tool_cls .radio_group is None :
@@ -3471,8 +3480,10 @@ def _tool_added_event(self, tool):
3471
3480
self ._callbacks .process (s , event )
3472
3481
3473
3482
def _handle_toggle (self , tool , sender , canvasevent , data ):
3474
- # Toggle tools, need to untoggle prior to using other Toggle tool
3475
- # Called from tool_trigger_event
3483
+ """
3484
+ Toggle tools, need to untoggle prior to using other Toggle tool
3485
+ Called from tool_trigger_event
3486
+ """
3476
3487
3477
3488
radio_group = tool .radio_group
3478
3489
# radio_group None is not mutually exclusive
@@ -3522,7 +3533,8 @@ def _get_cls_to_instantiate(self, callback_class):
3522
3533
3523
3534
def tool_trigger_event (self , name , sender = None , canvasevent = None ,
3524
3535
data = None ):
3525
- """Trigger a tool and emit the tool-trigger-[name] event
3536
+ """
3537
+ Trigger a tool and emit the tool_trigger_[name] event
3526
3538
3527
3539
Parameters
3528
3540
----------
@@ -3549,7 +3561,8 @@ def tool_trigger_event(self, name, sender=None, canvasevent=None,
3549
3561
self ._callbacks .process (s , event )
3550
3562
3551
3563
def _trigger_tool (self , name , sender = None , canvasevent = None , data = None ):
3552
- """Trigger on a tool
3564
+ """
3565
+ Trigger on a tool
3553
3566
3554
3567
Method to actually trigger the tool
3555
3568
"""
@@ -3578,7 +3591,8 @@ def tools(self):
3578
3591
return self ._tools
3579
3592
3580
3593
def get_tool (self , name , warn = True ):
3581
- """Return the tool object, also accepts the actual tool for convenience
3594
+ """
3595
+ Return the tool object, also accepts the actual tool for convenience
3582
3596
3583
3597
Parameters
3584
3598
-----------
@@ -3597,7 +3611,8 @@ def get_tool(self, name, warn=True):
3597
3611
3598
3612
3599
3613
class ToolContainerBase (object ):
3600
- """Base class for all tool containers, e.g. toolbars.
3614
+ """
3615
+ Base class for all tool containers, e.g. toolbars.
3601
3616
3602
3617
Attributes
3603
3618
----------
@@ -3611,14 +3626,16 @@ def __init__(self, navigation):
3611
3626
self ._remove_tool_cbk )
3612
3627
3613
3628
def _tool_toggled_cbk (self , event ):
3614
- """Captures the 'tool-trigger-toolname
3629
+ """
3630
+ Captures the 'tool_trigger_[name]'
3615
3631
3616
3632
This only gets used for toggled tools
3617
3633
"""
3618
3634
self .toggle_toolitem (event .tool .name , event .tool .toggled )
3619
3635
3620
3636
def add_tools (self , tools ):
3621
- """ Add multiple tools to the container.
3637
+ """
3638
+ Add multiple tools to the container.
3622
3639
3623
3640
Parameters
3624
3641
----------
@@ -3634,7 +3651,8 @@ def add_tools(self, tools):
3634
3651
self .add_tool (tool , group , position )
3635
3652
3636
3653
def add_tool (self , tool , group , position = - 1 ):
3637
- """Adds a tool to this container
3654
+ """
3655
+ Adds a tool to this container
3638
3656
3639
3657
Parameters
3640
3658
----------
@@ -3670,7 +3688,8 @@ def _get_image_filename(self, image):
3670
3688
return fname
3671
3689
3672
3690
def trigger_tool (self , name ):
3673
- """Trigger the tool
3691
+ """
3692
+ Trigger the tool
3674
3693
3675
3694
Parameters
3676
3695
----------
@@ -3681,7 +3700,8 @@ def trigger_tool(self, name):
3681
3700
self .navigation .tool_trigger_event (name , sender = self )
3682
3701
3683
3702
def add_toolitem (self , name , group , position , image , description , toggle ):
3684
- """Add a toolitem to the container
3703
+ """
3704
+ Add a toolitem to the container
3685
3705
3686
3706
This method must get implemented per backend
3687
3707
@@ -3711,7 +3731,8 @@ def add_toolitem(self, name, group, position, image, description, toggle):
3711
3731
raise NotImplementedError
3712
3732
3713
3733
def toggle_toolitem (self , name , toggled ):
3714
- """Toggle the toolitem without firing event
3734
+ """
3735
+ Toggle the toolitem without firing event
3715
3736
3716
3737
Parameters
3717
3738
----------
@@ -3723,7 +3744,8 @@ def toggle_toolitem(self, name, toggled):
3723
3744
raise NotImplementedError
3724
3745
3725
3746
def remove_toolitem (self , name ):
3726
- """Remove a toolitem from the `ToolContainer`
3747
+ """
3748
+ Remove a toolitem from the `ToolContainer`
3727
3749
3728
3750
This method must get implemented per backend
3729
3751
@@ -3750,7 +3772,8 @@ def _message_cbk(self, event):
3750
3772
self .set_message (event .message )
3751
3773
3752
3774
def set_message (self , s ):
3753
- """Display a message on toolbar or in status bar
3775
+ """
3776
+ Display a message on toolbar or in status bar
3754
3777
3755
3778
Parameters
3756
3779
----------
0 commit comments