Base tool class. A base tool, only implements `trigger` method or no method at all. The tool is instantiated by `matplotlib.backend_managers.ToolManager`.
| 71 | |
| 72 | |
| 73 | class ToolBase: |
| 74 | """ |
| 75 | Base tool class. |
| 76 | |
| 77 | A base tool, only implements `trigger` method or no method at all. |
| 78 | The tool is instantiated by `matplotlib.backend_managers.ToolManager`. |
| 79 | """ |
| 80 | |
| 81 | default_keymap = None |
| 82 | """ |
| 83 | Keymap to associate with this tool. |
| 84 | |
| 85 | ``list[str]``: List of keys that will trigger this tool when a keypress |
| 86 | event is emitted on ``self.figure.canvas``. Note that this attribute is |
| 87 | looked up on the instance, and can therefore be a property (this is used |
| 88 | e.g. by the built-in tools to load the rcParams at instantiation time). |
| 89 | """ |
| 90 | |
| 91 | description = None |
| 92 | """ |
| 93 | Description of the Tool. |
| 94 | |
| 95 | `str`: Tooltip used if the Tool is included in a Toolbar. |
| 96 | """ |
| 97 | |
| 98 | image = None |
| 99 | """ |
| 100 | Icon filename. |
| 101 | |
| 102 | ``str | None``: Filename of the Toolbar icon; either absolute, or relative to the |
| 103 | directory containing the Python source file where the ``Tool.image`` class attribute |
| 104 | is defined (in the latter case, this cannot be defined as an instance attribute). |
| 105 | In either case, the extension is optional; leaving it off lets individual backends |
| 106 | select the icon format they prefer. If None, the *name* is used as a label in the |
| 107 | toolbar button. |
| 108 | """ |
| 109 | |
| 110 | def __init__(self, toolmanager, name): |
| 111 | self._name = name |
| 112 | self._toolmanager = toolmanager |
| 113 | self._figure = None |
| 114 | |
| 115 | name = property( |
| 116 | lambda self: self._name, |
| 117 | doc="The tool id (str, must be unique among tools of a tool manager).") |
| 118 | toolmanager = property( |
| 119 | lambda self: self._toolmanager, |
| 120 | doc="The `.ToolManager` that controls this tool.") |
| 121 | canvas = property( |
| 122 | lambda self: self._figure.canvas if self._figure is not None else None, |
| 123 | doc="The canvas of the figure affected by this tool, or None.") |
| 124 | |
| 125 | def set_figure(self, figure): |
| 126 | self._figure = figure |
| 127 | |
| 128 | figure = property( |
| 129 | lambda self: self._figure, |
| 130 | # The setter must explicitly call self.set_figure so that subclasses can |
nothing calls this directly
no test coverage detected
searching dependent graphs…