Commit 5f895a8
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 (`toolbar.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 a toolbar
is instantiated; each of the callable gets the toolbar as parameter and
can modify it as it sees fit. This makes it easy to distribute such
customizations as plain python modules than can be installed from PyPI.
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 e1910b8 commit 5f895a8
File tree
9 files changed
+407
-0
lines changed- examples/user_interfaces
- images
- lib/matplotlib
- mpl-data
9 files changed
+407
-0
lines changedLoading
Binary file not shown.
Loading
Loading
Loading
0 commit comments