-
-
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 |
---|---|---|
|
@@ -3226,27 +3226,38 @@ def set_history_buttons(self): | |
|
||
|
||
class ToolEvent(object): | ||
"""Base event for tool communication""" | ||
def __init__(self, name, sender): | ||
"""Event for tool manipulation (add/remove)""" | ||
def __init__(self, name, sender, tool): | ||
self.name = name | ||
self.sender = sender | ||
self.tool = tool | ||
|
||
|
||
class ToolTriggerEvent(ToolEvent): | ||
"""Event to inform that a tool has been triggered""" | ||
def __init__(self, name, tool, sender, canvasevent=None, data=None): | ||
ToolEvent.__init__(self, name, sender) | ||
self.tool = tool | ||
def __init__(self, name, sender, tool, canvasevent=None, data=None): | ||
ToolEvent.__init__(self, name, sender, tool) | ||
self.canvasevent = canvasevent | ||
self.data = data | ||
|
||
|
||
class NavigationEvent(ToolEvent): | ||
"""Event for navigation tool management (add/remove/message)""" | ||
def __init__(self, name, sender, **kwargs): | ||
ToolEvent.__init__(self, name, sender) | ||
for key, value in kwargs.items(): | ||
setattr(self, key, value) | ||
class ToolAddedEvent(ToolEvent): | ||
"""Event triggered when a tool is added""" | ||
def __init__(self, name, sender, tool, group, position): | ||
ToolEvent.__init__(self, name, sender, tool) | ||
self.group = group | ||
self.position = position | ||
|
||
|
||
class NavigationMessageEvent(object): | ||
"""Event carring messages from navigation | ||
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. Event carrying ;).
8000
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 really appreciate the spelling and grammar corrections 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. Just going to say I will make the PR at the weekend when I look at it properly, but I see you have beaten me to it. If I find anything else I will go straight to PR. 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. Gah, build errors, I think a package got upgraded since I built on the now dead computer in the summer. Bug report sent to debian on libpng12.
|
||
|
||
Messages are generaly displayed to the user by the toolbar | ||
""" | ||
def __init__(self, name, sender, message): | ||
self.name = name | ||
self.sender = sender | ||
self.message = message | ||
|
||
|
||
class NavigationBase(object): | ||
|
@@ -3303,7 +3314,7 @@ def mpl_disconnect(self, cid): | |
|
||
Example usage:: | ||
|
||
cid = navigation.mpl_connect('tool-trigger-zoom', on_press) | ||
cid = navigation.mpl_connect('tool_trigger_zoom', on_press) | ||
#...later | ||
navigation.mpl_disconnect(cid) | ||
""" | ||
|
@@ -3315,7 +3326,7 @@ def message_event(self, message, sender=None): | |
sender = self | ||
|
||
s = 'tool_message_event' | ||
event = NavigationEvent(s, sender, message=message) | ||
event = NavigationMessageEvent(s, sender, message) | ||
self._callbacks.process(s, event) | ||
|
||
@property | ||
|
@@ -3388,7 +3399,7 @@ def remove_tool(self, name): | |
self._remove_keys(name) | ||
|
||
s = 'tool_removed_event' | ||
event = NavigationEvent(s, self, tool=tool) | ||
event = ToolEvent(s, self, tool) | ||
self._callbacks.process(s, event) | ||
|
||
del self._tools[name] | ||
|
@@ -3449,28 +3460,28 @@ def add_tool(self, name, tool, group=None, position=None): | |
|
||
def _tool_added_event(self, tool, group, position): | ||
s 8000 = 'tool_added_event' | ||
event = NavigationEvent(s, self, | ||
tool=tool, | ||
group=group, | ||
position=position) | ||
event = ToolAddedEvent(s, self, | ||
tool, | ||
group, | ||
position) | ||
self._callbacks.process(s, event) | ||
|
||
def _handle_toggle(self, name, sender, canvasevent, data): | ||
def _handle_toggle(self, tool, sender, canvasevent, data): | ||
# Toggle tools, need to be untoggled before other Toggle tool is used | ||
# This is called from tool_trigger_event | ||
|
||
if self._toggled == name: | ||
if self._toggled == tool.name: | ||
toggled = None | ||
elif self._toggled is None: | ||
toggled = name | ||
toggled = tool.name | ||
else: | ||
# Untoggle previously toggled tool | ||
self.tool_trigger_event(self._toggled, self, canvasevent, data) | ||
toggled = name | ||
toggled = tool.name | ||
|
||
self._toggled = toggled | ||
for a in self.canvas.figure.get_axes(): | ||
a.set_navigate_mode(self._toggled) | ||
# for a in self.canvas.figure.get_axes(): | ||
# a.set_navigate_mode(self._toggled) | ||
|
||
def _get_cls_to_instantiate(self, callback_class): | ||
# Find the class that corresponds to the tool | ||
|
@@ -3512,7 +3523,8 @@ def tool_trigger_event(self, name, sender=None, canvasevent=None, | |
self._trigger_tool(name, sender, canvasevent, data) | ||
|
||
s = 'tool-trigger-%s' % name | ||
event = ToolTriggerEvent(s, self._tools[name], sender, canvasevent, data) | ||
event = ToolTriggerEvent(s, sender, self._tools[name], canvasevent, | ||
data) | ||
self._callbacks.process(s, event) | ||
|
||
def _trigger_tool(self, name, sender=None, canvasevent=None, data=None): | ||
|
@@ -3523,7 +3535,7 @@ def _trigger_tool(self, name, sender=None, canvasevent=None, data=None): | |
tool = self._tools[name] | ||
|
||
if isinstance(tool, tools.ToolToggleBase): | ||
self._handle_toggle(name, sender, canvasevent, data) | ||
self._handle_toggle(tool, sender, canvasevent, data) | ||
|
||
# Important!!! | ||
# This is where the Tool object is triggered | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
import numpy as np | ||
|
||
|
||
class Cursors: | ||
class Cursors(object): | ||
"""Simple namespace for cursor reference""" | ||
HAND, POINTER, SELECT_REGION, MOVE = list(range(4)) | ||
cursors = Cursors() | ||
|
@@ -118,6 +118,9 @@ class ToolToggleBase(ToolBase): | |
Every time it is triggered, it switches between enable and disable | ||
""" | ||
|
||
radio_group = None | ||
"""Attribute to group 'radio' like tools""" | ||
|
||
cursor = None | ||
"""Cursor to use when the tool is active""" | ||
|
||
|
@@ -192,7 +195,7 @@ def _tool_trigger_cbk(self, event): | |
|
||
# If the tool is toggleable, set the cursor when the tool is triggered | ||
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. These comments above the methods should be docstrings |
||
def _add_tool(self, tool): | ||
if getattr(tool, 'toggled', None) is not None: | ||
if getattr(tool, 'cursor', None) is not None: | ||
self.navigation.mpl_connect('tool-trigger-%s' % tool.name, | ||
self._tool_trigger_cbk) | ||
|
||
|
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.
Back again and time to start commenting...
Judging by the constructor, it looks like this event will only get called for when tools get added to the toolbar, so this should probably get made clear here in the comment, and perhaps also the class name, such as ToolAddedToToolbarEvent, or perhaps even ToolbarToolChangeEvent adding in a type of change to the constructor, thus we can have Add, Remove, Modified etc served by one class.
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.
Welcome back,
The
Toolbar
is not mandatory adding Toolbar to the name is even less clear.I guess I can add the extra data needed (position) in
ToolEvent
and remove that class.