Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c054de

Browse files
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 231d1c8 commit 2c054de

File tree

10 files changed

+425
-1
lines changed

10 files changed

+425
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Figure hooks
2+
~~~~~~~~~~~~
3+
The new :rc:`figure.hooks` provides a mechanism to register
4+
arbitrary customizations on pyplot figures; it is a list of
5+
"dotted.module.name:dotted.callable.name" strings specifying functions
6+
that are called on each figure created by `.pyplot.figure`; these
7+
functions can e.g. attach callbacks or modify the toolbar. See
8+
:doc:`/gallery/user_interfaces/mplcvd` for an example of toolbar customization.
Lines changed: 70 additions & 0 deletions
Loading
3.44 KB
Binary file not shown.
635 Bytes
Loading
Lines changed: 70 additions & 0 deletions
Loading
1.12 KB
Loading

0 commit comments

Comments
 (0)