Manager for actions triggered by user interactions (key press, toolbar clicks, ...) on a Figure. Attributes ---------- figure : `.Figure` keypresslock : `~matplotlib.widgets.LockDraw` `.LockDraw` object to know if the `canvas` key_press_event is locked. messagel
| 30 | |
| 31 | |
| 32 | class ToolManager: |
| 33 | """ |
| 34 | Manager for actions triggered by user interactions (key press, toolbar |
| 35 | clicks, ...) on a Figure. |
| 36 | |
| 37 | Attributes |
| 38 | ---------- |
| 39 | figure : `.Figure` |
| 40 | keypresslock : `~matplotlib.widgets.LockDraw` |
| 41 | `.LockDraw` object to know if the `canvas` key_press_event is locked. |
| 42 | messagelock : `~matplotlib.widgets.LockDraw` |
| 43 | `.LockDraw` object to know if the message is available to write. |
| 44 | """ |
| 45 | |
| 46 | def __init__(self, figure=None): |
| 47 | |
| 48 | self._key_press_handler_id = None |
| 49 | |
| 50 | self._tools = {} |
| 51 | self._keys = {} |
| 52 | self._toggled = {} |
| 53 | self._callbacks = cbook.CallbackRegistry() |
| 54 | |
| 55 | # to process keypress event |
| 56 | self.keypresslock = widgets.LockDraw() |
| 57 | self.messagelock = widgets.LockDraw() |
| 58 | |
| 59 | self._figure = None |
| 60 | self.set_figure(figure) |
| 61 | |
| 62 | @property |
| 63 | def canvas(self): |
| 64 | """Canvas managed by FigureManager.""" |
| 65 | if not self._figure: |
| 66 | return None |
| 67 | return self._figure.canvas |
| 68 | |
| 69 | @property |
| 70 | def figure(self): |
| 71 | """Figure that holds the canvas.""" |
| 72 | return self._figure |
| 73 | |
| 74 | @figure.setter |
| 75 | def figure(self, figure): |
| 76 | self.set_figure(figure) |
| 77 | |
| 78 | def set_figure(self, figure, update_tools=True): |
| 79 | """ |
| 80 | Bind the given figure to the tools. |
| 81 | |
| 82 | Parameters |
| 83 | ---------- |
| 84 | figure : `.Figure` |
| 85 | update_tools : bool, default: True |
| 86 | Force tools to update figure. |
| 87 | """ |
| 88 | if self._key_press_handler_id: |
| 89 | self.canvas.mpl_disconnect(self._key_press_handler_id) |
no outgoing calls
no test coverage detected
searching dependent graphs…