8000 MEP22: Navigation by events by fariza · Pull Request #3652 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

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

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.

Copy link
Member Author

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.

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
Copy link
Member

Choose a reason for hiding this comment

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

Event carrying ;).

Copy link
Member Author
8000

Choose a reason for hiding this comment

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

I really appreciate the spelling and grammar corrections
But it would be a lot faster if you just made a PR for them against my branch. As you know the list of corrections can be pretty long

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

In file included from /usr/include/libpng12/png.h:540:0,
                 from src/_png.cpp:21:
/usr/include/libpng12/pngconf.h:371:12: error: ‘__pngconf’ does not name a type
            __pngconf.h__ in libpng already includes setjmp.h;
            ^
/usr/include/libpng12/pngconf.h:372:12: error: ‘__dont__’ does not name a type
            __dont__ include it again.;


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):
Expand Down Expand Up @@ -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)
"""
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -192,7 +195,7 @@ def _tool_trigger_cbk(self, event):

# If the tool is toggleable, set the cursor when the tool is triggered
Copy link
Member

Choose a reason for hiding this comment

The 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)

Expand Down
0