You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When embedding, `canvas.manager` may be None, but we may still have
registered the default key_press_handler (see e.g. the
embedding_in_tk_sgskip.py example), so we still need to disable the
keymap rcParams.
In order to avoid duplicating the logic as to whether use
toolmanager-cleanup in two places (and avoid things going out of sync
between begin_typing and stop_typing), register the cleanup actions
in begin_typing.
Example:
```
from matplotlib.backend_bases import key_press_handler
from matplotlib.backends.backend_qt5agg import FigureCanvas, NavigationToolbar2QT
from matplotlib.backends.qt_compat import QtCore, QtWidgets
from matplotlib.figure import Figure
from matplotlib.widgets import TextBox
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
canvas = FigureCanvas(Figure(figsize=(5, 3)))
canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
self.setCentralWidget(canvas)
tb = NavigationToolbar2QT(canvas, self)
self.addToolBar(tb)
canvas.mpl_connect(
"key_press_event", lambda event: key_press_handler(event, canvas, tb))
axbox = canvas.figure.add_axes([0.1, 0.05, 0.8, 0.075])
self._tb = TextBox(axbox, 'label')
qapp = QtWidgets.QApplication([])
app = ApplicationWindow()
app.show()
qapp.exec_()
```
0 commit comments