Commit 9e113c9
committed
Arbitrary toolbar customization hooks.
MEP22 was intended to provide a way to customize user interactions,
in particular with the toolbar via the implementation to "tools". In
practice, it remains currently difficult to add general customizations;
for example, the color-vision deficiency simulator recently proposed
does not fit in the MEP22 framework. Moreover, there is no way to
register MEP22 tools to be added to all figures.
This patch proposes an alternative approach for toolbar customization:
it adds a rcParam (`figure.hooks`) which is a list of callables
(actually, of "modulename:functioname" strings, so that they can
be specified in the matplotlibrc file) that get called whenever
plt.figure() creates a figure is instantiated; each of the callable gets
the figure as parameter and can modify it as it sees fit (note that it
is equivalent to pass the figure or the toolbar as parameter, as one
can reach one from the other; passing the figure was deemed nicer).
This makes it easy to distribute such customizations as plain python
modules than can be installed from PyPI. Also note that figure hooks
are intentionally *not* applied when figures are created without going
through `plt.figure` -- when embedding, one can easily explicitly call
the hooks directly on the figure (this is one reason why passing the
figure is nicer than passing the toolbar).
As an example, the color-vision deficiency simulator is modified to use
this hook (see docstring of the `user_interfaces/mplcvd.py` example).
The advantage of this approach is that arbitrary modifications to the
toolbar become possible (here, adding a menu-in-a-toolbar), but this
naturally means that each GUI toolkit needs its own code. Likely we
will need to provide "template" implementations that can be copied
by third-parties. (There is also some functionality currently only
available as private API, as mentioned in comments; one such API is
`_icon`, which provides theme-dependent icon recolorization. These APIs
should be made public in some form, but that should be doable.)
(One should check to what extent this approach is generalizable to
the macos and notebook backends -- customizations to the former could
possibly be implemented via PyObjC(?), and the latter via js injection?)1 parent c1588e6 commit 9e113c9
File tree
10 files changed
+418
-1
lines changed- doc/users/next_whats_new
- examples/user_interfaces
- images
- lib/matplotlib
- mpl-data
10 files changed
+418
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
Loading
Binary file not shown.
Loading
Loading
Loading
0 commit comments