8000 Mep22 · matplotlib/matplotlib Wiki · GitHub
[go: up one dir, main page]

Skip to content
Federico Ariza edited this page Jan 8, 2014 · 25 revisions
.. author:: Federico Ariza

Discussion

Previous work

The main goal of this MEP is to make it easier to modify (add, change, remove) the way the user interacts with the figures.

The user interaction with the figure is deeply integrated within the Canvas and Toolbar. Making extremely difficult to do any modification.

This MEP proposes the separation of this interaction into Toolbar, Navigation and Tools to provide independent access and reconfiguration.

This approach will make easier to create and share tools among users. In the far future, we can even foresee a kind of Marketplace for Tools where the most popular can be added into the main distribution.

The reconfiguration of the Toolbar is complex, most of the time it requires a custom backend.

The creation of custom Tools sometimes interferes with the Toolbar, as example see https://github.com/matplotlib/matplotlib/issues/2694 also the shortcuts are hardcoded and again not easily modifiable https://github.com/matplotlib/matplotlib/issues/2699

The proposed solution is to take the actions out of the Toolbar and the shortcuts out of the Canvas. This actions and shortcuts will be in the form of Tools.

A new class Navigation will be the bridge between the events from the Canvas and Toolbar and redirect them to the appropiate Tool.

At the end the user interaction will be divided into three classes:
  • NavigationBase: This class is instantiated for each FigureManager and connect the all user interactions with the Tools
  • ToolbarBase: This existing class is relegated only as a GUI access to this Tools.
  • ToolBase: Is the basic definition of Tools.
To make the creation of tools simple, only two types of tools will be defined.
  • Button, as Home, Back, Quit
  • Radio, as Zoom and Pan
Each tool defines the following methods
  • activate
  • deactivate
  • set_figure: Set the figure affected by this Tool
Each tool defines the following attributes that are going to be used by Navigation
  • Type: Button or Radio
  • Image: Image to be used in the toolbar
  • Position: int or None defining position in the toolbar or not present in the toolbar
  • Shortcut: Desired shortcut for the Tool (final decision belongs to Navigation)

By default the current tools will be added Home, Back, Quit, etc...

For simplicity there will be only one group for Radio Tools, this means only one or none of the Radio Tools can be active at any time.

The NavigationBase defines methods to
  • add: Add Tool
  • remove: Remove Tool
  • activate: Activate Tool
  • deactivate: Deactivate Tool
  • list: Get the list of Tools
  • list shortcuts: Get the list of shortcuts with their respective Tool
  • change shortcut: Change the Tool shortcut
  • toggle tool: Tooggle a radio Tool
  • get toggled: Get the status or Toggled Tool
The basic methods are
  • add: Add a Tool
  • remove: Remove a Tool
  • set_figure: Set the figure affected by this toolbar

Unfurtunatelly making a change like this, will brake backwards compatibility with any custom backend that modifies the Toolbar.

TBD

Clone this wiki locally
0