Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Commit6515cbc
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". Inpractice, it remains currently difficult to add general customizations;for example, the color-vision deficiency simulator recently proposeddoes not fit in the MEP22 framework. Moreover, there is no way toregister 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 canbe specified in the matplotlibrc file) that get called wheneverplt.figure() creates a figure is instantiated; each of the callable getsthe figure as parameter and can modify it as it sees fit (note that itis equivalent to pass the figure or the toolbar as parameter, as onecan reach one from the other; passing the figure was deemed nicer).This makes it easy to distribute such customizations as plain pythonmodules than can be installed from PyPI. Also note that figure hooksare intentionally *not* applied when figures are created without goingthrough `plt.figure` -- when embedding, one can easily explicitly callthe hooks directly on the figure (this is one reason why passing thefigure is nicer than passing the toolbar).As an example, the color-vision deficiency simulator is modified to usethis hook (see docstring of the `user_interfaces/mplcvd.py` example).The advantage of this approach is that arbitrary modifications to thetoolbar become possible (here, adding a menu-in-a-toolbar), but thisnaturally means that each GUI toolkit needs its own code. Likely wewill need to provide "template" implementations that can be copiedby third-parties. (There is also some functionality currently onlyavailable as private API, as mentioned in comments; one such API is`_icon`, which provides theme-dependent icon recolorization. These APIsshould be made public in some form, but that should be doable.)(One should check to what extent this approach is generalizable tothe macos and notebook backends -- customizations to the former couldpossibly be implemented via PyObjC(?), and the latter via js injection?)1 parentc0c3627 commit6515cbc
File tree
9 files changed
+417
-1
lines changed- examples/user_interfaces
- images
- lib/matplotlib
- mpl-data
9 files changed
+417
-1
lines changedLines changed: 70 additions & 0 deletions
Loading
Binary file not shown.
Loading
Lines changed: 70 additions & 0 deletions
Loading
Loading
0 commit comments
Comments
(0)