Skip to content

Commit 78513d2

Browse files
committed
remove ToolAddedEvent incorporating the functionality into toolevent
1 parent af6734f commit 78513d2

File tree

2 files changed

+43
-53
lines changed

2 files changed

+43
-53
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,32 +3227,24 @@ def set_history_buttons(self):
32273227

32283228
class ToolEvent(object):
32293229
"""Event for tool manipulation (add/remove)"""
3230-
def __init__(self, name, sender, tool):
3230+
def __init__(self, name, sender, tool, data=None):
32313231
self.name = name
32323232
self.sender = sender
32333233
self.tool = tool
3234+
self.data = data
32343235

32353236

32363237
class ToolTriggerEvent(ToolEvent):
32373238
"""Event to inform that a tool has been triggered"""
32383239
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)
32403241
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
32503242

32513243

32523244
class NavigationMessageEvent(object):
3253-
"""Event carring messages from navigation
3245+
"""Event carrying messages from navigation
32543246
3255-
Messages are generaly displayed to the user by the toolbar
3247+
Messages usually get displayed to the user by the toolbar
32563248
"""
32573249
def __init__(self, name, sender, message):
32583250
self.name = name
@@ -3339,7 +3331,7 @@ def active_toggle(self):
33393331
return self._toggled
33403332

33413333
def get_tool_keymap(self, name):
3342-
"""Get the keymap associated with a tool
3334+
"""Get the keymap associated with the specified tool
33433335
33443336
Parameters
33453337
----------
@@ -3360,13 +3352,13 @@ def _remove_keys(self, name):
33603352
del self._keys[k]
33613353

33623354
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
33643356
33653357
Parameters
33663358
----------
33673359
name : string
33683360
Name of the Tool
3369-
keys : keys to associated with the Tool
3361+
keys : keys to associate with the Tool
33703362
"""
33713363

33723364
if name not in self._tools:
@@ -3440,7 +3432,7 @@ def add_tool(self, name, tool, group=None, position=None):
34403432
group: String
34413433
Group to position the tool in
34423434
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
34443436
"""
34453437

34463438
tool_cls = self._get_cls_to_instantiate(tool)
@@ -3457,7 +3449,7 @@ def add_tool(self, name, tool, group=None, position=None):
34573449
if tool_cls.keymap is not None:
34583450
self.set_tool_keymap(name, tool_cls.keymap)
34593451

3460-
# For toggle tools init the radio_grop in self._toggled
3452+
# For toggle tools init the radio_group in self._toggled
34613453
if getattr(tool_cls, 'toggled', False) is not False:
34623454
# None group is not mutually exclusive, a set is used to keep track
34633455
# of all toggled tools in this group
@@ -3470,15 +3462,15 @@ def add_tool(self, name, tool, group=None, position=None):
34703462

34713463
def _tool_added_event(self, tool, group, position):
34723464
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})
34773469
self._callbacks.process(s, event)
34783470

34793471
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
34823474

34833475
radio_group = tool.radio_group
34843476
# radio_group None is not mutually exclusive
@@ -3490,8 +3482,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
34903482
self._toggled[None].add(tool.name)
34913483
return
34923484

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
34953486
if self._toggled[radio_group] == tool.name:
34963487
toggled = None
34973488
# If no tool was toggled in the radio_group
@@ -3536,7 +3527,7 @@ def tool_trigger_event(self, name, sender=None, canvasevent=None,
35363527
name : string
35373528
Name of the tool
35383529
sender: object
3539-
Object that wish to trigger the tool
3530+
Object that wishes to trigger the tool
35403531
canvasevent : Event
35413532
Original Canvas event or None
35423533
data : Object
@@ -3567,7 +3558,7 @@ def _trigger_tool(self, name, sender=None, canvasevent=None, data=None):
35673558
self._handle_toggle(tool, sender, canvasevent, data)
35683559

35693560
# Important!!!
3570-
# This is where the Tool object is triggered
3561+
# This is where the Tool object gets triggered
35713562
tool.trigger(sender, canvasevent, data)
35723563

35733564
def _key_press(self, event):
@@ -3616,26 +3607,26 @@ def __init__(self, manager):
36163607
self._remove_tool_cbk)
36173608

36183609
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"""
36203611
self.set_message(event.message)
36213612

36223613
def _tool_triggered_cbk(self, event):
36233614
"""Captures the 'tool-trigger-toolname
36243615
3625-
This is only used for toggled tools
3616+
This only gets used for toggled tools
36263617
"""
36273618
if event.sender is self:
36283619
return
36293620

36303621
self.toggle_toolitem(event.tool.name)
36313622

36323623
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"""
36343625
image = self._get_image_filename(event.tool.image)
36353626
toggle = getattr(event.tool, 'toggled', None) is not None
36363627
self.add_toolitem(event.tool.name,
3637-
event.group,
3638-
event.position,
3628+
event.data['group'],
3629+
event.data['position'],
36393630
image,
36403631
event.tool.description,
36413632
toggle)
@@ -3644,11 +3635,11 @@ def _add_tool_cbk(self, event):
36443635
self._tool_triggered_cbk)
36453636

36463637
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"""
36483639
self.remove_toolitem(event.tool.name)
36493640

36503641
def _get_image_filename(self, image):
3651-
""""Base on the image name find the corresponding image"""
3642+
"""Find the image based on its name"""
36523643
# TODO: better search for images, they are not always in the
36533644
# datapath
36543645
basedir = os.path.join(rcParams['datapath'], 'images')
@@ -3664,28 +3655,28 @@ def trigger_tool(self, name):
36643655
Parameters
36653656
----------
36663657
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
36683659
36693660
"""
36703661
self.navigation.tool_trigger_event(name, sender=self)
36713662

36723663
def add_toolitem(self, name, group, position, image, description, toggle):
36733664
"""Add a toolitem to the toolbar
36743665
3675-
This method has to be implemented per backend
3666+
This method must get implemented per backend
36763667
36773668
The callback associated with the button click event,
36783669
must be **EXACTLY** `self.trigger_tool(name)`
36793670
36803671
Parameters
36813672
----------
36823673
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
36853676
group : String
3686-
Name of the group that the tool belongs to
3677+
Name of the group that this tool belongs to
36873678
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
36893680
image_file : String
36903681
Filename of the image for the button or `None`
36913682
description : String
@@ -3723,9 +3714,9 @@ def toggle_toolitem(self, name):
37233714
def remove_toolitem(self, name):
37243715
"""Remove a toolitem from the `Toolbar`
37253716
3726-
This method has to be implemented per backend
3717+
This method must get implemented per backend
37273718
3728-
Called when `tool_removed_event` is emited by `NavigationBase`
3719+
Called when `NavigationBase` emits a `tool_removed_event`
37293720
37303721
Parameters
37313722
----------

lib/matplotlib/backend_tools.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ def trigger(self, sender, event, data=None):
143143
def enable(self, event=None):
144144
"""Enable the toggle tool
145145
146-
This method is called dby `trigger` when the `toggled` is False
146+
`trigger` calls this method when `toggled` is False
147147
"""
148148

149149
pass
150150

151151
def disable(self, event=None):
152152
"""Disable the toggle tool
153153
154-
This method is called by `trigger` when the `toggled` is True.
154+
`trigger` call this methond when `toggled` is True.
155155
156156
This can happen in different circumstances
157157
@@ -174,7 +174,7 @@ class SetCursorBase(ToolBase):
174174
"""Change to the current cursor while inaxes
175175
176176
This tool, keeps track of all `ToolToggleBase` derived tools, and calls
177-
set_cursor when one of these tools is triggered
177+
set_cursor when a tool gets triggered
178178
"""
179179
def __init__(self, *args, **kwargs):
180180
ToolBase.__init__(self, *args, **kwargs)
@@ -251,7 +251,6 @@ def send_message(self, event):
251251
message = ' '
252252

253253
if event.inaxes and event.inaxes.get_navigate():
254-
255254
try:
256255
s = event.inaxes.format_coord(event.xdata, event.ydata)
257256
except (ValueError, OverflowError):
@@ -275,14 +274,14 @@ def trigger(self, sender, event, data):
275274
def draw_rubberband(self, *data):
276275
"""Draw rubberband
277276
278-
This method has to be implemented per backend
277+
This method must get implemented per backend
279278
"""
280279
pass
281280

282281
def remove_rubberband(self):
283282
"""Remove rubberband
284283
285-
This method has to be implemented per backend
284+
This method must get implemented per backend
286285
"""
287286
pass
288287

@@ -383,7 +382,7 @@ def disable(self, event):
383382

384383

385384
class ToolYScale(AxisScaleBase):
386-
"""Tool to toggle between linear and logarithmic the Y axis"""
385+
"""Tool to toggle between linear and logarithmic scales on the Y axis"""
387386

388387
description = 'Toogle Scale Y axis'
389388
keymap = rcParams['keymap.yscale']
@@ -393,7 +392,7 @@ def set_scale(self, ax, scale):
393392

394393

395394
class ToolXScale(AxisScaleBase):
396-
"""Tool to toggle between linear and logarithmic the X axis"""
395+
"""Tool to toggle between linear and logarithmic scales on the X axis"""
397396

398397
description = 'Toogle Scale X axis'
399398
keymap = rcParams['keymap.xscale']
@@ -405,8 +404,8 @@ def set_scale(self, ax, scale):
405404
class ToolViewsPositions(ToolBase):
406405
"""Auxiliary Tool to handle changes in views and positions
407406
408-
Runs in the background and is used by all the tools that
409-
need to access the record of views and positions of the figure
407+
Runs in the background and should get used by all the tools that
408+
need to access the figure's history of views and positions, e.g.
410409
411410
* `ToolZoom`
412411
* `ToolPan`

0 commit comments

Comments
 (0)