@@ -3227,32 +3227,24 @@ def set_history_buttons(self):
3227
3227
3228
3228
class ToolEvent (object ):
3229
3229
"""Event for tool manipulation (add/remove)"""
3230
- def __init__ (self , name , sender , tool ):
3230
+ def __init__ (self , name , sender , tool , data = None ):
3231
3231
self .name = name
3232
3232
self .sender = sender
3233
3233
self .tool = tool
3234
+ self .data = data
3234
3235
3235
3236
3236
3237
class ToolTriggerEvent (ToolEvent ):
3237
3238
"""Event to inform that a tool has been triggered"""
3238
3239
def __init__ (self , name , sender , tool , canvasevent = None , data = None ):
3239
- ToolEvent .__init__ (self , name , sender , tool )
3240
+ ToolEvent .__init__ (self , name , sender , tool , data )
3240
3241
self .canvasevent = canvasevent
3241
- self .data = data
3242
-
3243
-
3244
- class ToolAddedEvent (ToolEvent ):
3245
- """Event triggered when a tool is added"""
3246
- def __init__ (self , name , sender , tool , group , position ):
3247
- ToolEvent .__init__ (self , name , sender , tool )
3248
- self .group = group
3249
- self .position = position
3250
3242
3251
3243
3252
3244
class NavigationMessageEvent (object ):
3253
- """Event carring messages from navigation
3245
+ """Event carrying messages from navigation
3254
3246
3255
- Messages are generaly displayed to the user by the toolbar
3247
+ Messages usually get displayed to the user by the toolbar
3256
3248
"""
3257
3249
def __init__ (self , name , sender , message ):
3258
3250
self .name = name
@@ -3339,7 +3331,7 @@ def active_toggle(self):
3339
3331
return self ._toggled
3340
3332
3341
3333
def get_tool_keymap (self , name ):
3342
- """Get the keymap associated with a tool
3334
+ """Get the keymap associated with the specified tool
3343
3335
3344
3336
Parameters
3345
3337
----------
@@ -3360,13 +3352,13 @@ def _remove_keys(self, name):
3360
3352
del self ._keys [k ]
3361
3353
3362
3354
def set_tool_keymap (self , name , * keys ):
3363
- """Set the keymap associated with a tool
3355
+ """Set the keymap to associate with the specified tool
3364
3356
3365
3357
Parameters
3366
3358
----------
3367
3359
name : string
3368
3360
Name of the Tool
3369
- keys : keys to associated with the Tool
3361
+ keys : keys to associate with the Tool
3370
3362
"""
3371
3363
3372
3364
if name not in self ._tools :
@@ -3440,7 +3432,7 @@ def add_tool(self, name, tool, group=None, position=None):
3440
3432
group: String
3441
3433
Group to position the tool in
3442
3434
position : int or None (default)
3443
- Position within its group in the toolbar, if None, is positioned at the end
3435
+ Position within its group in the toolbar, if None, it goes at the end
3444
3436
"""
3445
3437
3446
3438
tool_cls = self ._get_cls_to_instantiate (tool )
@@ -3457,7 +3449,7 @@ def add_tool(self, name, tool, group=None, position=None):
3457
3449
if tool_cls .keymap is not None :
3458
3450
self .set_tool_keymap (name , tool_cls .keymap )
3459
3451
3460
- # For toggle tools init the radio_grop in self._toggled
3452
+ # For toggle tools init the radio_group in self._toggled
3461
3453
if getattr (tool_cls , 'toggled' , False ) is not False :
3462
3454
# None group is not mutually exclusive, a set is used to keep track
3463
3455
# of all toggled tools in this group
@@ -3470,15 +3462,15 @@ def add_tool(self, name, tool, group=None, position=None):
3470
3462
3471
3463
def _tool_added_event (self , tool , group , position ):
3472
3464
s = 'tool_added_event'
3473
- event = ToolAddedEvent ( s , self ,
3474
- tool ,
3475
- group ,
3476
- position )
3465
+ event = ToolEvent ( s ,
3466
+ self ,
3467
+ tool ,
3468
+ data = { 'group' : group , 'position' : position } )
3477
3469
self ._callbacks .process (s , event )
3478
3470
3479
3471
def _handle_toggle (self , tool , sender , canvasevent , data ):
3480
- # Toggle tools, need to be untoggled before other Toggle tool is used
3481
- # This is called from tool_trigger_event
3472
+ # Toggle tools, need to untoggle prior to using other Toggle tool
3473
+ # Called from tool_trigger_event
3482
3474
3483
3475
radio_group = tool .radio_group
3484
3476
# radio_group None is not mutually exclusive
@@ -3490,8 +3482,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
3490
3482
self ._toggled [None ].add (tool .name )
3491
3483
return
3492
3484
3493
- # If it is the same tool that is toggled in the radio_group
3494
- # untoggle it
3485
+ # If the tool already has a toggled state, untoggle it
3495
3486
if self ._toggled [radio_group ] == tool .name :
3496
3487
toggled = None
3497
3488
# If no tool was toggled in the radio_group
@@ -3536,7 +3527,7 @@ def tool_trigger_event(self, name, sender=None, canvasevent=None,
3536
3527
name : string
3537
3528
Name of the tool
3538
3529
sender: object
3539
- Object that wish to trigger the tool
3530
+ Object that wishes to trigger the tool
3540
3531
canvasevent : Event
3541
3532
Original Canvas event or None
3542
3533
data : Object
@@ -3567,7 +3558,7 @@ def _trigger_tool(self, name, sender=None, canvasevent=None, data=None):
3567
3558
self ._handle_toggle (tool , sender , canvasevent , data )
3568
3559
3569
3560
# Important!!!
3570
- # This is where the Tool object is triggered
3561
+ # This is where the Tool object gets triggered
3571
3562
tool .trigger (sender , canvasevent , data )
3572
3563
3573
3564
def _key_press (self , event ):
@@ -3616,26 +3607,26 @@ def __init__(self, manager):
3616
3607
self ._remove_tool_cbk )
3617
3608
3618
3609
def _message_cbk (self , event ):
3619
- """Captures the 'tool_message_event' to set message on the toolbar"""
3610
+ """Captures the 'tool_message_event' to set the message on the toolbar"""
3620
3611
self .set_message (event .message )
3621
3612
3622
3613
def _tool_triggered_cbk (self , event ):
3623
3614
"""Captures the 'tool-trigger-toolname
3624
3615
3625
- This is only used for toggled tools
3616
+ This only gets used for toggled tools
3626
3617
"""
3627
3618
if event .sender is self :
3628
3619
return
3629
3620
3630
3621
self .toggle_toolitem (event .tool .name )
3631
3622
3632
3623
def _add_tool_cbk (self , event ):
3633
- """Captures 'tool_added_event' and add the tool to the toolbar"""
3624
+ """Captures 'tool_added_event' and adds the tool to the toolbar"""
3634
3625
image = self ._get_image_filename (event .tool .image )
3635
3626
toggle = getattr (event .tool , 'toggled' , None ) is not None
3636
3627
self .add_toolitem (event .tool .name ,
3637
- event .group ,
3638
- event .position ,
3628
+ event .data [ ' group' ] ,
3629
+ event .data [ ' position' ] ,
3639
3630
image ,
3640
3631
event .tool .description ,
3641
3632
toggle )
@@ -3644,11 +3635,11 @@ def _add_tool_cbk(self, event):
3644
3635
self ._tool_triggered_cbk )
3645
3636
3646
3637
def _remove_tool_cbk (self , event ):
3647
- """Captures the 'tool_removed_event' signal and remove the tool"""
3638
+ """Captures the 'tool_removed_event' signal and removes the tool"""
3648
3639
self .remove_toolitem (event .tool .name )
3649
3640
3650
3641
def _get_image_filename (self , image ):
3651
- """"Base on the image name find the corresponding image """
3642
+ """Find the image based on its name """
3652
3643
# TODO: better search for images, they are not always in the
3653
3644
# datapath
3654
3645
basedir = os .path .join (rcParams ['datapath' ], 'images' )
@@ -3664,28 +3655,28 @@ def trigger_tool(self, name):
3664
3655
Parameters
3665
3656
----------
3666
3657
name : String
3667
- Name(id) of the tool that was triggered in the toolbar
3658
+ Name(id) of the tool triggered from within the toolbar
3668
3659
3669
3660
"""
3670
3661
self .navigation .tool_trigger_event (name , sender = self )
3671
3662
3672
3663
def add_toolitem (self , name , group , position , image , description , toggle ):
3673
3664
"""Add a toolitem to the toolbar
3674
3665
3675
- This method has to be implemented per backend
3666
+ This method must get implemented per backend
3676
3667
3677
3668
The callback associated with the button click event,
3678
3669
must be **EXACTLY** `self.trigger_tool(name)`
3679
3670
3680
3671
Parameters
3681
3672
----------
3682
3673
name : string
3683
- Name of the tool to add, this is used as ID and as default label
3684
- of the buttons
3674
+ Name of the tool to add, this gets used as the tool's ID and as the
3675
+ default label of the buttons
3685
3676
group : String
3686
- Name of the group that the tool belongs to
3677
+ Name of the group that this tool belongs to
3687
3678
position : Int
3688
- Position of the tool whthin its group if -1 at the End
3679
+ Position of the tool within its group, if -1 it goes at the End
3689
3680
image_file : String
3690
3681
Filename of the image for the button or `None`
3691
3682
description : String
@@ -3723,9 +3714,9 @@ def toggle_toolitem(self, name):
3723
3714
def remove_toolitem (self , name ):
3724
3715
"""Remove a toolitem from the `Toolbar`
3725
3716
3726
- This method has to be implemented per backend
3717
+ This method must get implemented per backend
3727
3718
3728
- Called when `tool_removed_event` is emited by `NavigationBase `
3719
+ Called when `NavigationBase` emits a `tool_removed_event `
3729
3720
3730
3721
Parameters
3731
3722
----------
0 commit comments