Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d42acb0

Browse files
authored
Merge pull request #19752 from anntzer/btd
Cleanup backend_tools docstrings, and minor refactorings.
2 parents 9de78ea + 7bb2eeb commit d42acb0

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

lib/matplotlib/backend_tools.py

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,66 +38,58 @@ class ToolBase:
3838
"""
3939
Base tool class.
4040
41-
A base tool, only implements `trigger` method or not method at all.
41+
A base tool, only implements `trigger` method or no method at all.
4242
The tool is instantiated by `matplotlib.backend_managers.ToolManager`.
43-
44-
Attributes
45-
----------
46-
toolmanager : `matplotlib.backend_managers.ToolManager`
47-
ToolManager that controls this Tool.
48-
figure : `FigureCanvas`
49-
Figure instance that is affected by this Tool.
50-
name : str
51-
Used as **Id** of the tool, has to be unique among tools of the same
52-
ToolManager.
5343
"""
5444

5545
default_keymap = None
5646
"""
5747
Keymap to associate with this tool.
5848
59-
**String**: List of comma separated keys that will be used to call this
60-
tool when the keypress event of ``self.figure.canvas`` is emitted.
49+
``list[str]``: List of keys that will trigger this tool when a keypress
50+
event is emitted on ``self.figure.canvas``.
6151
"""
6252

6353
description = None
6454
"""
6555
Description of the Tool.
6656
67-
**String**: If the Tool is included in the Toolbar this text is used
68-
as a Tooltip.
57+
`str`: Tooltip used if the Tool is included in a Toolbar.
6958
"""
7059

7160
image = None
7261
"""
7362
Filename of the image.
7463
75-
**String**: Filename of the image to use in the toolbar. If None, the
76-
*name* is used as a label in the toolbar button.
64+
`str`: Filename of the image to use in a Toolbar. If None, the *name* is
65+
used as a label in the toolbar button.
7766
"""
7867

7968
def __init__(self, toolmanager, name):
8069
self._name = name
8170
self._toolmanager = toolmanager
8271
self._figure = None
8372

73+
name = property(
74+
lambda self: self._name,
75+
doc="The tool id (str, must be unique among tools of a tool manager).")
76+
toolmanager = property(
77+
lambda self: self._toolmanager,
78+
doc="The `.ToolManager` that controls this tool.")
79+
canvas = property(
80+
lambda self: self._figure.canvas if self._figure is not None else None,
81+
doc="The canvas of the figure affected by this tool, or None.")
82+
8483
@property
8584
def figure(self):
85+
"""The Figure affected by this tool, or None."""
8686
return self._figure
8787

8888
@figure.setter
8989
def figure(self, figure):
90-
self.set_figure(figure)
91-
92-
@property
93-
def canvas(self):
94-
if not self._figure:
95-
return None
96-
return self._figure.canvas
90+
self._figure = figure
9791

98-
@property
99-
def toolmanager(self):
100-
return self._toolmanager
92+
set_figure = figure.fset
10193

10294
def _make_classic_style_pseudo_toolbar(self):
10395
"""
@@ -108,22 +100,11 @@ def _make_classic_style_pseudo_toolbar(self):
108100
"""
109101
return SimpleNamespace(canvas=self.canvas)
110102

111-
def set_figure(self, figure):
112-
"""
113-
Assign a figure to the tool.
114-
115-
Parameters
116-
----------
117-
figure : `.Figure`
118-
"""
119-
self._figure = figure
120-
121103
def trigger(self, sender, event, data=None):
122104
"""
123105
Called when this tool gets used.
124106
125-
This method is called by
126-
`matplotlib.backend_managers.ToolManager.trigger_tool`.
107+
This method is called by `.ToolManager.trigger_tool`.
127108
128109
Parameters
129110
----------
@@ -136,17 +117,11 @@ def trigger(self, sender, event, data=None):
136117
"""
137118
pass
138119

139-
@property
140-
def name(self):
141-
"""Tool Id."""
142-
return self._name
143-
144120
def destroy(self):
145121
"""
146122
Destroy the tool.
147123
148-
This method is called when the tool is removed by
149-
`matplotlib.backend_managers.ToolManager.remove_tool`.
124+
This method is called by `.ToolManager.remove_tool`.
150125
"""
151126
pass
152127

@@ -167,10 +142,10 @@ class ToolToggleBase(ToolBase):
167142
"""
168143

169144
radio_group = None
170-
"""Attribute to group 'radio' like tools (mutually exclusive).
145+
"""
146+
Attribute to group 'radio' like tools (mutually exclusive).
171147
172-
**String** that identifies the group or **None** if not belonging to a
173-
group.
148+
`str` that identifies the group or **None** if not belonging to a group.
174149
"""
175150

176151
cursor = None
@@ -217,7 +192,6 @@ def disable(self, event=None):
217192
@property
218193
def toggled(self):
219194
"""State of the toggled tool."""
220-
221195
return self._toggled
222196

223197
def set_figure(self, figure):

0 commit comments

Comments
 (0)