| 1667 | self._observers.process('submit', self.text) |
| 1668 | |
| 1669 | def begin_typing(self): |
| 1670 | self.capturekeystrokes = True |
| 1671 | # Disable keypress shortcuts, which may otherwise cause the figure to |
| 1672 | # be saved, closed, etc., until the user stops typing. The way to |
| 1673 | # achieve this depends on whether toolmanager is in use. |
| 1674 | stack = ExitStack() # Register cleanup actions when user stops typing. |
| 1675 | self._on_stop_typing = stack.close |
| 1676 | toolmanager = getattr( |
| 1677 | self.ax.get_figure(root=True).canvas.manager, "toolmanager", None) |
| 1678 | if toolmanager is not None: |
| 1679 | # If using toolmanager, lock keypresses, and plan to release the |
| 1680 | # lock when typing stops. |
| 1681 | toolmanager.keypresslock(self) |
| 1682 | stack.callback(toolmanager.keypresslock.release, self) |
| 1683 | else: |
| 1684 | # If not using toolmanager, disable all keypress-related rcParams. |
| 1685 | # Avoid spurious warnings if keymaps are getting deprecated. |
| 1686 | with _api.suppress_matplotlib_deprecation_warning(): |
| 1687 | stack.enter_context(mpl.rc_context( |
| 1688 | {k: [] for k in mpl.rcParams if k.startswith("keymap.")})) |
| 1689 | |
| 1690 | def stop_typing(self): |
| 1691 | if self.capturekeystrokes: |