@@ -38,66 +38,58 @@ class ToolBase:
38
38
"""
39
39
Base tool class.
40
40
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.
42
42
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.
53
43
"""
54
44
55
45
default_keymap = None
56
46
"""
57
47
Keymap to associate with this tool.
58
48
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``.
61
51
"""
62
52
63
53
description = None
64
54
"""
65
55
Description of the Tool.
66
56
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.
69
58
"""
70
59
71
60
image = None
72
61
"""
73
62
Filename of the image.
74
63
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.
77
66
"""
78
67
79
68
def __init__ (self , toolmanager , name ):
80
69
self ._name = name
81
70
self ._toolmanager = toolmanager
82
71
self ._figure = None
83
72
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
+
84
83
@property
85
84
def figure (self ):
85
+ """The Figure affected by this tool, or None."""
86
86
return self ._figure
87
87
88
88
@figure .setter
89
89
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
97
91
98
- @property
99
- def toolmanager (self ):
100
- return self ._toolmanager
92
+ set_figure = figure .fset
101
93
102
94
def _make_classic_style_pseudo_toolbar (self ):
103
95
"""
@@ -108,22 +100,11 @@ def _make_classic_style_pseudo_toolbar(self):
108
100
"""
109
101
return SimpleNamespace (canvas = self .canvas )
110
102
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
-
121
103
def trigger (self , sender , event , data = None ):
122
104
"""
123
105
Called when this tool gets used.
124
106
125
- This method is called by
126
- `matplotlib.backend_managers.ToolManager.trigger_tool`.
107
+ This method is called by `.ToolManager.trigger_tool`.
127
108
128
109
Parameters
129
110
----------
@@ -136,17 +117,11 @@ def trigger(self, sender, event, data=None):
136
117
"""
137
118
pass
138
119
139
- @property
140
- def name (self ):
141
- """Tool Id."""
142
- return self ._name
143
-
144
120
def destroy (self ):
145
121
"""
146
122
Destroy the tool.
147
123
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`.
150
125
"""
151
126
pass
152
127
@@ -167,10 +142,10 @@ class ToolToggleBase(ToolBase):
167
142
"""
168
143
169
144
radio_group = None
170
- """Attribute to group 'radio' like tools (mutually exclusive).
145
+ """
146
+ Attribute to group 'radio' like tools (mutually exclusive).
171
147
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.
174
149
"""
175
150
176
151
cursor = None
@@ -217,7 +192,6 @@ def disable(self, event=None):
217
192
@property
218
193
def toggled (self ):
219
194
"""State of the toggled tool."""
220
-
221
195
return self ._toggled
222
196
223
197
def set_figure (self , figure ):
0 commit comments