-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8cceed4
3118a5a
b4d5fcf
1e8af47
622cb95
d1a9de4
3f89d52
4f3c10b
6065daa
f6a2f19
05db3b6
c08fe56
b207a72
9266447
a53419a
704c717
5056729
e6a4e1e
8942c47
022de6f
2c9a195
cafe668
224f745
94c711e
67257e7
ffa65d6
6739ee0
d18206f
34a52c8
c2da483
44a9b0e
a2ed47f
0665890
411e6e2
d484ebd
75bf97b
6cc040b
0ff5997
af6734f
78513d2
377ff54
7dbbf58
dd66b57
67a414f
e415d8d
1213086
ba61dec
9f2ee2b
9da2b13
110253f
e2804ea
9a64b7e
64f947f
e8cd5d5
4bbcf4e
73a2661
1b83628
e4edd23
d4ac2fb
a7640ef
48a6971
8dafe09
a0695d0
328b169
aac4744
f09b9ef
def3a52
9ee7e25
5eae4e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ def trigger(self, *args, **kwargs): | |
fig.canvas.manager.navigation.add_tool('List', ListTools) | ||
if matplotlib.rcParams['backend'] == 'GTK3Cairo': | ||
fig.canvas.manager.navigation.add_tool('copy', CopyToolGTK3) | ||
|
||
fig.canvas.manager.toolbar.add_tool('zoom', 'foo') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple answer it ain't we have here |
||
# Uncomment to remove the forward button | ||
# fig.canvas.manager.navigation.remove_tool('forward') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3413,7 +3413,7 @@ def add_tools(self, tools): | |
for tool, name in tools: | ||
self.add_tool(name, tool) | ||
|
||
def add_tool(self, name, tool): | ||
def add_tool(self, name, tool, *args, **kwargs): | ||
"""Add tool to `NavigationBase` | ||
|
||
Add a tool to the tools controlled by Navigation | ||
|
@@ -3428,6 +3428,10 @@ def add_tool(self, name, tool): | |
Name of the tool, treated as the ID, has to be unique | ||
tool : string or `matplotlib.backend_tools.ToolBase` derived class | ||
Reference to find the class of the Tool to be added | ||
|
||
Notes | ||
----- | ||
args and kwargs get passed directly to the tools constructor. | ||
""" | ||
|
||
tool_cls = self._get_cls_to_instantiate(tool) | ||
|
@@ -3440,12 +3444,7 @@ def add_tool(self, name, tool): | |
'not added') | ||
return | ||
|
||
if isinstance(tool_cls, type): | ||
self._tools[name] = tool_cls(self, name) | ||
else: | ||
tool_cls.set_navigation(self) | ||
tool.name = name | ||
self._tools[name] = tool_cls | ||
self._tools[name] = tool_cls(self, name, *args, **kwargs) | ||
|
||
if tool_cls.keymap is not None: | ||
self.set_tool_keymap(name, tool_cls.keymap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The one who makes the sorting (by keymap) of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh? per-instance key binding happens, this just sets the default keymap. @fariza I think you should rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite follow this yet.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OceanWolf agreed and done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tacaswell |
||
|
@@ -3460,7 +3459,6 @@ def add_tool(self, name, tool): | |
self._toggled.setdefault(tool_cls.radio_group, None) | ||
|
||
self._tool_added_event(self._tools[name]) | ||
|
||
return self._tools[name] | ||
|
||
def _tool_added_event(self, tool): | ||
|
@@ -3583,7 +3581,7 @@ def get_tool(self, name): | |
name : String, ToolBase | ||
Name of the tool, or the tool itself | ||
""" | ||
if isinstance(name, tools.ToolBase): | ||
if isinstance(name, tools.ToolBase) and tool.name in self._tools: | ||
return name | ||
if name not in self._tools: | ||
warnings.warn("%s is not a tool controlled by Navigation" % name) | ||
|
@@ -3612,15 +3610,12 @@ def _message_cbk(self, event): | |
"""Captures the 'tool_message_event' to set the message on the toolbar""" | ||
self.set_message(event.message) | ||
|
||
def _tool_triggered_cbk(self, event): | ||
def _tool_toggled_cbk(self, event): | ||
"""Captures the 'tool-trigger-toolname | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be "tool_trigger_[name]" to be consistent with documentation elsewhere. |
||
|
||
This only gets used for toggled tools | ||
""" | ||
if event.sender is self: | ||
return | ||
|
||
self.toggle_toolitem(event.tool.name) | ||
self.toggle_toolitem(event.tool.name, event.tool.toggled) | ||
|
||
def add_tools(self, tools): | ||
""" Add multiple tools to `Navigation` | ||
|
@@ -3639,25 +3634,38 @@ def add_tools(self, tools): | |
for position, tool in enumerate(grouptools): | ||
self.add_tool(tool, group, position) | ||
|
||
def add_tool(self, tool, group, position): | ||
"""Adds a tool to the toolbar""" | ||
def add_tool(self, tool, group, position=-1, name=None, **kwargs): | ||
"""Adds a tool to the toolbar | ||
|
||
Parameters | ||
---------- | ||
tool : string, tool | ||
The name or the type of tool to add. | ||
group : string | ||
The name of the group to add this tool to. | ||
position : int | ||
the relative position within the group to place this tool. | ||
name : string (optional) | ||
If given, and the above fails, we use this to create a new tool of | ||
type given by tool, and use this as the name of the tool. | ||
""" | ||
t = self.navigation.get_tool(tool) | ||
if t is None: | ||
if isinstance(tool, (list, tuple)): | ||
t = self.navigation.add_tool(tool[0], tool[1]) | ||
elif isinstance(tool, ToolBase): | ||
t = self.navigation.add_tool(tool.name, tool) | ||
else: | ||
warning.warn('Cannot add tool %s'%tool) | ||
return | ||
if isinstance(tool, type): | ||
tool = tool.__class__ | ||
if name is not None: | ||
t = self.navigation.add_tool(name, tool, **kwargs) | ||
if t is None: | ||
warning.warn('Cannot add tool %s'%tool) | ||
return | ||
tool = t | ||
image = self._get_image_filename(tool.image) | ||
toggle = getattr(tool, 'toggled', None) is not None | ||
self.add_toolitem(tool.name, group, position, image, | ||
tool.description, toggle) | ||
if toggle: | ||
self.navigation.nav_connect('tool_trigger_%s' % tool.name, | ||
self._tool_triggered_cbk) | ||
self._tool_toggled_cbk) | ||
|
||
def _remove_tool_cbk(self, event): | ||
"""Captures the 'tool_removed_event' signal and removes the tool""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with making this a GTK3Cairo-only example. Makes it a little bit simpler