@@ -43,11 +43,11 @@ class ToolManager:
43
43
44
44
Attributes
45
45
----------
46
- figure : `Figure`
47
- keypresslock : `widgets.LockDraw`
48
- `LockDraw` object to know if the `canvas` key_press_event is locked
49
- messagelock : `widgets.LockDraw`
50
- `LockDraw` object to know if the message is available to write
46
+ figure : `. Figure`
47
+ keypresslock : `~matplotlib. widgets.LockDraw`
48
+ `. LockDraw` object to know if the `canvas` key_press_event is locked.
49
+ messagelock : `~matplotlib. widgets.LockDraw`
50
+ `. LockDraw` object to know if the message is available to write.
51
51
"""
52
52
53
53
def __init__ (self , figure = None ):
@@ -92,8 +92,8 @@ def set_figure(self, figure, update_tools=True):
92
92
Parameters
93
93
----------
94
94
figure : `.Figure`
95
- update_tools : bool
96
- Force tools to update figure
95
+ update_tools : bool, default: True
96
+ Force tools to update figure.
97
97
"""
98
98
if self ._key_press_handler_id :
99
99
self .canvas .mpl_disconnect (self ._key_press_handler_id )
@@ -111,23 +111,27 @@ def toolmanager_connect(self, s, func):
111
111
112
112
Parameters
113
113
----------
114
- s : String
115
- Name of the event
116
-
117
- The following events are recognized
114
+ s : str
115
+ The name of the event. The following events are recognized:
118
116
119
117
- 'tool_message_event'
120
118
- 'tool_removed_event'
121
119
- 'tool_added_event'
122
120
123
121
For every tool added a new event is created
124
122
125
- - 'tool_trigger_TOOLNAME`
126
- Where TOOLNAME is the id of the tool.
123
+ - 'tool_trigger_TOOLNAME', where TOOLNAME is the id of the tool.
124
+
125
+ func : callable
126
+ Callback function for the toolmanager event with signature::
127
+
128
+ def func(event: ToolEvent) -> Any
127
129
128
- func : function
129
- Function to be called with signature
130
- def func(event)
130
+ Returns
131
+ -------
132
+ cid
133
+ The callback id for the connection. This can be used in
134
+ `.toolmanager_disconnect`.
131
135
"""
132
136
return self ._callbacks .connect (s , func )
133
137
@@ -159,7 +163,7 @@ def active_toggle(self):
159
163
160
164
def get_tool_keymap (self , name ):
161
165
"""
162
- Get the keymap associated with the specified tool.
166
+ Return the keymap associated with the specified tool.
163
167
164
168
Parameters
165
169
----------
@@ -168,7 +172,8 @@ def get_tool_keymap(self, name):
168
172
169
173
Returns
170
174
-------
171
- list : list of keys associated with the Tool
175
+ list of str
176
+ List of keys associated with the tool.
172
177
"""
173
178
174
179
keys = [k for k , i in self ._keys .items () if i == name ]
@@ -186,7 +191,8 @@ def update_keymap(self, name, *keys):
186
191
----------
187
192
name : str
188
193
Name of the Tool.
189
- keys : keys to associate with the Tool
194
+ keys : list of str
195
+ Keys to associate with the tool.
190
196
"""
191
197
192
198
if name not in self ._tools :
@@ -208,7 +214,7 @@ def remove_tool(self, name):
208
214
Parameters
209
215
----------
210
216
name : str
211
- Name of the Tool .
217
+ Name of the tool .
212
218
"""
213
219
214
220
tool = self .get_tool (name )
@@ -294,13 +300,13 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
294
300
295
301
Parameters
296
302
----------
297
- tool : Tool object
303
+ tool : `.ToolBase`
298
304
sender : object
299
- Object that wishes to trigger the tool
305
+ Object that wishes to trigger the tool.
300
306
canvasevent : Event
301
- Original Canvas event or None
302
- data : Object
303
- Extra data to pass to the tool when triggering
307
+ Original Canvas event or None.
308
+ data : object
309
+ Extra data to pass to the tool when triggering.
304
310
"""
305
311
306
312
radio_group = tool .radio_group
@@ -358,11 +364,11 @@ def trigger_tool(self, name, sender=None, canvasevent=None, data=None):
358
364
name : str
359
365
Name of the tool.
360
366
sender : object
361
- Object that wishes to trigger the tool
367
+ Object that wishes to trigger the tool.
362
368
canvasevent : Event
363
- Original Canvas event or None
364
- data : Object
365
- Extra data to pass to the tool when triggering
369
+ Original Canvas event or None.
370
+ data : object
371
+ Extra data to pass to the tool when triggering.
366
372
"""
367
373
tool = self .get_tool (name )
368
374
if tool is None :
@@ -404,14 +410,22 @@ def tools(self):
404
410
405
411
def get_tool (self , name , warn = True ):
406
412
"""
407
- Return the tool object, also accepts the actual tool for convenience.
413
+ Return the tool object with the given name.
414
+
415
+ For convenience, this passes tool objects through.
408
416
409
417
Parameters
410
418
----------
411
- name : str, ToolBase
412
- Name of the tool, or the tool itself
413
- warn : bool, optional
414
- If this method should give warnings.
419
+ name : str or `.ToolBase`
420
+ Name of the tool, or the tool itself.
421
+ warn : bool, default: True
422
+ Whether a warning should be emitted it no tool with the given name
423
+ exists.
424
+
425
+ Returns
426
+ -------
427
+ tool : `.ToolBase` or None
428
+ The tool or None if no tool with the given name exists.
415
429
"""
416
430
if isinstance (name , tools .ToolBase ) and name .name in self ._tools :
417
431
return name
0 commit comments