Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MEP22: Navigation by events#3652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
WeatherGod merged 69 commits intomatplotlib:masterfromfariza:navigation-by-events
Apr 9, 2015
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
69 commits
Select commitHold shift + click to select a range
8cceed4
navigation and toolbar coexistence
farizaJan 23, 2014
3118a5a
mod keypress in figuremanager
farizaJan 23, 2014
b4d5fcf
helper methods in toolbar and navigation
farizaJan 24, 2014
1e8af47
Adding doc to base methods
farizaJan 24, 2014
622cb95
property for active_toggle
farizaJan 26, 2014
d1a9de4
simulate click
farizaJan 27, 2014
3f89d52
activate renamed to trigger
farizaJan 28, 2014
4f3c10b
toggle tools using enable/disable from its trigger method
farizaJan 29, 2014
6065daa
simplifying _handle_toggle
farizaJan 29, 2014
f6a2f19
reducing number of locks
farizaJan 29, 2014
05db3b6
changing toggle and persistent attributes for issubclass
farizaFeb 4, 2014
c08fe56
bug in combined key press
farizaFeb 4, 2014
b207a72
untoggle zoom and pan from keypress while toggled
farizaFeb 4, 2014
9266447
classmethods for default tools modification
farizaFeb 6, 2014
a53419a
adding zaxis and some pep8
farizaMay 1, 2014
704c717
removing legacy method dynamic update
farizaMay 6, 2014
5056729
tk backend
farizaMay 6, 2014
e6a4e1e
example working with Tk
farizaMay 6, 2014
8942c47
duplicate code in keymap tool initialization
farizaJul 24, 2014
022de6f
grammar corrections
farizaJul 24, 2014
2c9a195
moving views and positions to tools
farizaJul 24, 2014
cafe668
The views positions mixin automatically adds the clear as axobserver
farizaJul 25, 2014
224f745
bug when navigation was not defined
farizaJul 25, 2014
94c711e
Small refactor so that we first initiate the Navigation (ToolManager)…
OceanWolfJul 28, 2014
67257e7
Moved default_tool initilisation to FigureManagerBase and cleaned.
OceanWolfJul 29, 2014
ffa65d6
Temporary fix to backends
OceanWolfJul 29, 2014
6739ee0
removing persistent tools
farizaSep 3, 2014
d18206f
removing unregister
farizaSep 4, 2014
34a52c8
change cursor inmediately after toggle
farizaSep 5, 2014
c2da483
removing intoolbar
farizaOct 15, 2014
44a9b0e
events working
farizaOct 16, 2014
a2ed47f
using pydispatch
farizaOct 17, 2014
0665890
using navigation as signal handler
farizaOct 20, 2014
411e6e2
removing view positions singleton
farizaOct 20, 2014
d484ebd
moving set_cursor completely out of navigation
farizaOct 27, 2014
75bf97b
removing unused event class
farizaNov 10, 2014
6cc040b
underscore in tool_trigger-xxx
farizaNov 10, 2014
0ff5997
adding radio_group for toggle tools
farizaNov 14, 2014
af6734f
scroll to zoom in zoom/pan tools
farizaNov 28, 2014
78513d2
remove ToolAddedEvent incorporating the functionality into toolevent
farizaDec 5, 2014
377ff54
eliminating repeated loop
farizaJan 5, 2015
7dbbf58
replace draw by draw_idle in tools
farizaJan 21, 2015
dd66b57
rename mpl_connect
farizaJan 21, 2015
67a414f
cleaning navigation and toolbar dependencies
farizaFeb 4, 2015
e415d8d
Made NavigationBase.get_tool() more useful.
OceanWolfFeb 11, 2015
1213086
Refactored Toolbar out of NavigationBase
OceanWolfFeb 12, 2015
ba61dec
Some short cuts for adding tools
OceanWolfFeb 16, 2015
9f2ee2b
Lots of fixes
OceanWolfFeb 18, 2015
9da2b13
Rename ToolbarBase -> ToolContainerBase
OceanWolfFeb 18, 2015
110253f
Statusbar
OceanWolfFeb 20, 2015
e2804ea
tool group position
farizaFeb 26, 2015
9a64b7e
docstrings and small corrections by WeatherGod
farizaMar 23, 2015
64f947f
tkbackend updated
farizaMar 31, 2015
e8cd5d5
tacaswell comments aprl 1
farizaApr 1, 2015
4bbcf4e
renaming tool_trigger_event
farizaApr 1, 2015
73a2661
add_tools moved out of base classes
farizaApr 1, 2015
1b83628
figure.setter in tools
farizaApr 1, 2015
e4edd23
rename tools to default_tools to avoid confusion
farizaApr 1, 2015
d4ac2fb
docstring helper add_tools methods
farizaApr 1, 2015
a7640ef
rename navigation to toolmanager
farizaApr 2, 2015
48a6971
tkagg updated for toolmanager and tool groups
farizaApr 2, 2015
8dafe09
doc and minor code organization
farizaApr 2, 2015
a0695d0
whats new
farizaApr 3, 2015
328b169
missing object from class declaration
farizaApr 3, 2015
aac4744
remove comments and docstrings
farizaApr 3, 2015
f09b9ef
import with original name backend_tools
farizaApr 3, 2015
def3a52
rename 2 -> to, example without gtk only code
farizaApr 7, 2015
9ee7e25
zoom pan buttons order
farizaApr 7, 2015
5eae4e1
matplotlib.rcParams['toolbar'] == 'None' starts toolmanager but not t…
farizaApr 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsdoc/api/backend_managers_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@

:mod:`matplotlib.backend_managers`
===================================

.. automodule:: matplotlib.backend_managers
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletionsdoc/api/backend_tools_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@

:mod:`matplotlib.backend_tools`
================================

.. automodule:: matplotlib.backend_tools
:members:
:undoc-members:
:show-inheritance:
2 changes: 2 additions & 0 deletionsdoc/api/index_backend_api.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,8 @@ backends
.. toctree::

backend_bases_api.rst
backend_managers_api.rst
backend_tools_api.rst
backend_gtkagg_api.rst
backend_qt4agg_api.rst
backend_wxagg_api.rst
Expand Down
8 changes: 8 additions & 0 deletionsdoc/users/whats_new/rcparams.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,9 +15,17 @@ Added "figure.titlesize" and "figure.titleweight" keys to rcParams
Two new keys were added to rcParams to control the default font size and weight
used by the figure title (as emitted by ``pyplot.suptitle()``).


``image.composite_image`` added to rcParams
```````````````````````````````````````````
Controls whether vector graphics backends (i.e. PDF, PS, and SVG) combine
multiple images on a set of axes into a single composite image. Saving each
image individually can be useful if you generate vector graphics files in
matplotlib and then edit the files further in Inkscape or other programs.


Added "toolmanager" to "toolbar" possible values
````````````````````````````````````````````````

The new value enables the use of ``ToolManager``

68 changes: 68 additions & 0 deletionsdoc/users/whats_new/toolmanager.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
ToolManager
-----------

Federico Ariza wrote the new `matplotlib.backend_managers.ToolManager` that comes as replacement for `NavigationToolbar2`

`ToolManager` offers a new way of looking at the user interactions with the figures.
Before we had the `NavigationToolbar2` with its own tools like `zoom/pan/home/save/...` and also we had the shortcuts like
`yscale/grid/quit/....`
`Toolmanager` relocate all those actions as `Tools` (located in `matplotlib.backend_tools`), and defines a way to `access/trigger/reconfigure` them.

The `Toolbars` are replaced for `ToolContainers` that are just GUI interfaces to `trigger` the tools. But don't worry the default backends include a `ToolContainer` called `toolbar`


.. note::
For the moment the `ToolManager` is working only with `GTK3` and `Tk` backends.
Make sure you are using one of those.
Port for the rest of the backends is comming soon.

To activate the `ToolManager` include the following at the top of your file:

>>> matplotlib.rcParams['toolbar'] = 'toolmanager'


Interact with the ToolContainer
```````````````````````````````

The most important feature is the ability to easily reconfigure the ToolContainer (aka toolbar).
For example, if we want to remove the "forward" button we would just do.

>>> fig.canvas.manager.toolmanager.remove_tool('forward')

Now if you want to programmatically trigger the "home" button

>>> fig.canvas.manager.toolmanager.trigger_tool('home')


New Tools
`````````

It is possible to add new tools to the ToolManager

A very simple tool that prints "You're awesome" would be::

from matplotlib.backend_tools import ToolBase
class AwesomeTool(ToolBase):
def trigger(self, *args, **kwargs):
print("You're awesome")


To add this tool to `ToolManager`

>>> fig.canvas.manager.toolmanager.add_tool('Awesome', AwesomeTool)

If we want to add a shortcut ("d") for the tool

>>> fig.canvas.manager.toolmanager.update_keymap('Awesome', 'd')


To add it to the toolbar inside the group 'foo'

>>> fig.canvas.manager.toolbar.add_tool('Awesome', 'foo')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I get a little bit confused here. Why does the user have to interact with the toolmanager? Now that I see these examples, I wonder if the user should ever call methods upon toolmanager. I understand the functional importance of the toolmanager, but from the user's perspective, adding a tool involves interacting with two separate objects that appear (to them) to have very little to do with each other.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Some tools don't need to have visual representation and others do (button for a toolbar).
But at the end, is up to the user to determine what he wants in his toolbar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Right... good point. Might make sense in the future to add some convenience methods to make things easier for users, but I agree now that the user-facing distinction is necessary.



There is a second class of tools, "Toggleable Tools", this are almost the same as our basic tools, just that belong to a group, and are mutually exclusive inside that group.
For tools derived from `ToolToggleBase` there are two basic methods `enable` and `disable` that are called automatically whenever it is toggled.


A full example is located in :ref:`user_interfaces-toolmanager`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Don't have a section for a "Full Example" if it is just a link to an actual example. Just link it.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

92 changes: 92 additions & 0 deletionsexamples/user_interfaces/toolmanager.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
'''This example demonstrates how to:
* Modify the Toolbar
* Create tools
* Add tools
* Remove tools
Using `matplotlib.backend_managers.ToolManager`
'''


from __future__ import print_function
import matplotlib
matplotlib.use('GTK3Cairo')
matplotlib.rcParams['toolbar'] = 'toolmanager'
import matplotlib.pyplot as plt
from matplotlib.backend_tools import ToolBase, ToolToggleBase
from gi.repository import Gtk, Gdk


class ListTools(ToolBase):
'''List all the tools controlled by the `ToolManager`'''
# keyboard shortcut
default_keymap = 'm'
description = 'List Tools'

def trigger(self, *args, **kwargs):
print('_' * 80)
print("{0:12} {1:45} {2}".format('Name (id)',
'Tool description',
'Keymap'))
print('-' * 80)
tools = self.toolmanager.tools
for name in sorted(tools.keys()):
if not tools[name].description:
continue
keys = ', '.join(sorted(self.toolmanager.get_tool_keymap(name)))
print("{0:12} {1:45} {2}".format(name,
tools[name].description,
keys))
print('_' * 80)
print("Active Toggle tools")
print("{0:12} {1:45}".format("Group", "Active"))
print('-' * 80)
for group, active in self.toolmanager.active_toggle.items():
print("{0:12} {1:45}".format(group, active))


class GroupHideTool(ToolToggleBase):
'''Hide lines with a given gid'''
default_keymap = 'G'
description = 'Hide by gid'

def __init__(self, *args, **kwargs):
self.gid = kwargs.pop('gid')
ToolToggleBase.__init__(self, *args, **kwargs)

def enable(self, *args):
self.set_lines_visibility(False)

def disable(self, *args):
self.set_lines_visibility(True)

def set_lines_visibility(self, state):
gr_lines = []
for ax in self.figure.get_axes():
for line in ax.get_lines():
if line.get_gid() == self.gid:
line.set_visible(state)
self.figure.canvas.draw()


fig = plt.figure()
plt.plot([1, 2, 3], gid='mygroup')
plt.plot([2, 3, 4], gid='unknown')
plt.plot([3, 2, 1], gid='mygroup')

# Add the custom tools that we created
fig.canvas.manager.toolmanager.add_tool('List', ListTools)
fig.canvas.manager.toolmanager.add_tool('Hide', GroupHideTool, gid='mygroup')


# Add an existing tool to new group `foo`.
# It can be added as many times as we want
fig.canvas.manager.toolbar.add_tool('zoom', 'foo')

# Remove the forward button
fig.canvas.manager.toolmanager.remove_tool('forward')

# To add a custom tool to the toolbar at specific location inside
# the navigation group
fig.canvas.manager.toolbar.add_tool('Hide', 'navigation', 1)

plt.show()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp