Add *tool* to `ToolManager` If successful adds a new event `tool_trigger_name` where **name** is the **name** of the tool, this event is fired everytime the tool is triggered. Parameters ---------- name : str Name of the tool, tr
(self, name, tool, *args, **kwargs)
| 232 | del self._tools[name] |
| 233 | |
| 234 | def add_tool(self, name, tool, *args, **kwargs): |
| 235 | """ |
| 236 | Add *tool* to `ToolManager` |
| 237 | |
| 238 | If successful adds a new event `tool_trigger_name` where **name** is |
| 239 | the **name** of the tool, this event is fired everytime |
| 240 | the tool is triggered. |
| 241 | |
| 242 | Parameters |
| 243 | ---------- |
| 244 | name : str |
| 245 | Name of the tool, treated as the ID, has to be unique |
| 246 | tool : class_like, i.e. str or type |
| 247 | Reference to find the class of the Tool to added. |
| 248 | |
| 249 | Notes |
| 250 | ----- |
| 251 | args and kwargs get passed directly to the tools constructor. |
| 252 | |
| 253 | See Also |
| 254 | -------- |
| 255 | matplotlib.backend_tools.ToolBase : The base class for tools. |
| 256 | """ |
| 257 | |
| 258 | tool_cls = self._get_cls_to_instantiate(tool) |
| 259 | if not tool_cls: |
| 260 | raise ValueError('Impossible to find class for %s' % str(tool)) |
| 261 | |
| 262 | if name in self._tools: |
| 263 | warnings.warn('A "Tool class" with the same name already exists, ' |
| 264 | 'not added') |
| 265 | return self._tools[name] |
| 266 | |
| 267 | tool_obj = tool_cls(self, name, *args, **kwargs) |
| 268 | self._tools[name] = tool_obj |
| 269 | |
| 270 | if tool_cls.default_keymap is not None: |
| 271 | self.update_keymap(name, tool_cls.default_keymap) |
| 272 | |
| 273 | # For toggle tools init the radio_group in self._toggled |
| 274 | if isinstance(tool_obj, tools.ToolToggleBase): |
| 275 | # None group is not mutually exclusive, a set is used to keep track |
| 276 | # of all toggled tools in this group |
| 277 | if tool_obj.radio_group is None: |
| 278 | self._toggled.setdefault(None, set()) |
| 279 | else: |
| 280 | self._toggled.setdefault(tool_obj.radio_group, None) |
| 281 | |
| 282 | # If initially toggled |
| 283 | if tool_obj.toggled: |
| 284 | self._handle_toggle(tool_obj, None, None, None) |
| 285 | tool_obj.set_figure(self.figure) |
| 286 | |
| 287 | self._tool_added_event(tool_obj) |
| 288 | return tool_obj |
| 289 | |
| 290 | def _tool_added_event(self, tool): |
| 291 | s = 'tool_added_event' |
no test coverage detected