Commit 1c6d5a1
committed
Make widgets.TextBox work also when embedding.
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_()
```1 parent 065769b commit 1c6d5a1
1 file changed
Lines changed: 22 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
850 | 859 | | |
851 | 860 | | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
| 861 | + | |
| 862 | + | |
857 | 863 | | |
858 | 864 | | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | 865 | | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
| 866 | + | |
| 867 | + | |
871 | 868 | | |
| 869 | + | |
| 870 | + | |
872 | 871 | | |
873 | 872 | | |
874 | 873 | | |
875 | 874 | | |
| 875 | + | |
| 876 | + | |
876 | 877 | | |
877 | 878 | | |
878 | 879 | | |
| |||
0 commit comments