Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
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
tacaswell comments aprl 1
  • Loading branch information
fariza committed Apr 7, 2015
commit e8cd5d55ba713da4af761a9cea25df7cecfabeee
4 changes: 2 additions & 2 deletions examples/user_interfaces/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class allows to:
class ListTools(ToolBase):
'''List all the tools controlled by `Navigation`'''
# keyboard shortcut
keymap = 'm'
default_keymap = 'm'
description = 'List Tools'

def trigger(self, *args, **kwargs):
Expand Down Expand Up @@ -46,7 +46,7 @@ def trigger(self, *args, **kwargs):
# ref: at https://github.com/matplotlib/matplotlib/issues/1987
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, should be a class docstring

class CopyToolGTK3(ToolBase):
'''Copy canvas to clipboard'''
keymap = 'ctrl+c'
default_keymap = 'ctrl+c'
description = 'Copy canvas'

def trigger(self, *args, **kwargs):
Expand Down
60 changes: 36 additions & 24 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,8 @@ def __init__(self, canvas, num):
self.key_press_handler_id = self.canvas.mpl_connect(
'key_press_event',
self.key_press)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should self.key_press_handler_id get defined with a None so that an AttributeError doesn't happen by accident?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Eventually self.key_press_handler_id will get removed completely from FigureManagerBase, why do prevent the AttributeError now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am torn on this one, I see @fariza point that this is on it's way out, but I also don't like variable attributes on objects (just because you can doesn't mean you should). On the other hand, this is the only place in our code base that we reference self.key_press_handler_id so it probably does not really matter either way.

This would only be used to deregister a call back, does that code cope well with None?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was added to make it possible for users to disable the default keymap
entirely. It is not intended to be internal only, and I even have a
subsection in my book devoted to it. IIRC, the disconnect code handles None
fine.
On Mar 31, 2015 10:33 PM, "Thomas A Caswell" [email protected]
wrote:

In lib/matplotlib/backend_bases.py
#3652 (comment):

@@ -2552,8 +2564,10 @@ def init(self, canvas, num):
canvas.manager = self # store a pointer to parent
self.num = num

  •    self.key_press_handler_id = self.canvas.mpl_connect('key_press_event',
    
  •                                                        self.key_press)
    
  •    if rcParams['toolbar'] != 'navigation':
    
  •        self.key_press_handler_id = self.canvas.mpl_connect(
    
  •                                            'key_press_event',
    
  •                                            self.key_press)
    

I am torn on this one, I see @fariza https://github.com/fariza point
that this is on it's way out, but I also don't like variable attributes on
objects (just because you can doesn't mean you should). On the other
hand, this is the only place in our code base that we reference
self.key_press_handler_id so it probably does not really matter either
way.

This would only be used to deregister a call back, does that code cope
well with None?


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3652/files#r27540901.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done, I added the self.key_press_handler_id = None just beside the rcParams['toolbar'] verification, so when that will be removed, this will be as well.

else:
self.key_press_handler_id = None
"""
The returned id from connecting the default key handler via
:meth:`FigureCanvasBase.mpl_connnect`.
Expand Down Expand Up @@ -3331,11 +3333,7 @@ def message_event(self, message, sender=None):

@property
def active_toggle(self):
"""
Toggled Tool

**dict** : Currently toggled tools
"""
"""Currently toggled tools"""

return self._toggled

Expand All @@ -3360,7 +3358,7 @@ def _remove_keys(self, name):
for k in self.get_tool_keymap(name):
del self._keys[k]

def set_tool_keymap(self, name, *keys):
def update_keymap(self, name, *keys):
"""
Set the keymap to associate with the specified tool
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you clarify this a bit. This is setting a property of NavigationBase to trigger the tool on a key stroke. This docstring and function name make it sound like this is modifying the Tool object in some way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What do you think of renaming to set_keymap?, we don't have keymaps for anything else than tools.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about update_keymap? 'set' makes me think it is being replaced. As this is a Navigation level function I think that is the correct sematics (even though you are replacing the keys for the given tool).

It might also be worth adding a append kwarg to skip removing all of the existing keys for the given tool.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

rename done, not sure about append

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this done and not pushed? I am not seeing the code change....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am finishing all the current comments and push the commit, give me 5 😉


Expand Down Expand Up @@ -3449,30 +3447,31 @@ def add_tool(self, name, tool, *args, **kwargs):
"""

tool_cls = self._get_cls_to_instantiate(tool)
if tool_cls is False:
if not tool_cls:
raise ValueError('Impossible to find class for %s' % str(tool))

if name in self._tools:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be done first in this function? Do we want to check to make sure that they are the same type? Again, why warn rather than raise?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I used warn because i don't think that adding twice the same tool represents a major fault and your program will keep working as expected (you already have the tool)

warnings.warn('A "Tool class" with the same name already exists, '
'not added')
return self._tools[name]

self._tools[name] = tool_cls(self, name, *args, **kwargs)
tool_obj = tool_cls(self, name, *args, **kwargs)
self._tools[name] = tool_obj

if tool_cls.keymap is not None:
self.set_tool_keymap(name, tool_cls.keymap)
if tool_cls.default_keymap is not None:
self.update_keymap(name, tool_cls.default_keymap)

# For toggle tools init the radio_group in self._toggled
if isinstance(self._tools[name], tools.ToolToggleBase):
if isinstance(tool_obj, tools.ToolToggleBase):
# None group is not mutually exclusive, a set is used to keep track
# of all toggled tools in this group
if tool_cls.radio_group is None:
if tool_obj.radio_group is None:
self._toggled.setdefault(None, set())
else:
self._toggled.setdefault(tool_cls.radio_group, None)
self._toggled.setdefault(tool_obj.radio_group, None)

self._tool_added_event(self._tools[name])
return self._tools[name]
self._tool_added_event(tool_obj)
return tool_obj

def _tool_added_event(self, tool):
s = 'tool_added_event'
Expand All @@ -3483,6 +3482,16 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you put docstrings on these with the expected types?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Toggle tools, need to untoggle prior to using other Toggle tool
Called from tool_trigger_event

Parameters
----------
tool: Tool object
sender: object
Object that wishes to trigger the tool
canvasevent : Event
Original Canvas event or None
data : Object
Extra data to pass to the tool when triggering
"""

radio_group = tool.radio_group
Expand All @@ -3500,7 +3509,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
toggled = None
# If no tool was toggled in the radio_group
# toggle it
elif self._toggled.get(radio_group, None) is None:
elif self._toggled[radio_group] is None:
toggled = tool.name
# Other tool in the radio_group is toggled
else:
Expand All @@ -3521,15 +3530,18 @@ def _get_cls_to_instantiate(self, callback_class):
if isinstance(callback_class, six.string_types):
# FIXME: make more complete searching structure
if callback_class in globals():
return globals()[callback_class]

mod = self.__class__.__module__
current_module = __import__(mod,
globals(), locals(), [mod], 0)
callback_class = globals()[callback_class]
else:
mod = self.__class__.__module__
current_module = __import__(mod,
globals(), locals(), [mod], 0)

return getattr(current_module, callback_class, False)
callback_class = getattr(current_module, callback_class, False)

return callback_class
if callable(callback_class):
return callback_class
else:
return None

def tool_trigger_event(self, name, sender=None, canvasevent=None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This name is a bit too ambiguous, can it be process_tool_trigger or emit_tool_trigger or something like that? (I don't have my head around the code enough to have a good idea yet, but I don't like this name)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agree, what do you think of just trigger_tool? it does both, emit the event and trigger the tool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 to 'trigger_tool'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

data=None):
Expand Down Expand Up @@ -3598,7 +3610,7 @@ def get_tool(self, name, warn=True):
-----------
name : str, ToolBase
Name of the tool, or the tool itself
warn : bool
warn : bool, optional
If this method should give warnings.
"""
if isinstance(name, tools.ToolBase) and name.name in self._tools:
Expand Down
28 changes: 14 additions & 14 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ToolBase(object):
Navigation
"""

keymap = None
default_keymap = None
"""
Keymap to associate with this tool

Expand Down Expand Up @@ -311,7 +311,7 @@ class ToolQuit(ToolBase):
"""Tool to call the figure manager destroy method"""

description = 'Quit the figure'
keymap = rcParams['keymap.quit']
default_keymap = rcParams['keymap.quit']

def trigger(self, sender, event, data=None):
Gcf.destroy_fig(self.figure)
Expand All @@ -321,7 +321,7 @@ class ToolEnableAllNavigation(ToolBase):
"""Tool to enable all axes for navigation interaction"""

description = 'Enables all axes navigation'
keymap = rcParams['keymap.all_axes']
default_keymap = rcParams['keymap.all_axes']

def trigger(self, sender, event, data=None):
if event.inaxes is None:
Expand All @@ -337,7 +337,7 @@ class ToolEnableNavigation(ToolBase):
"""Tool to enable a specific axes for navigation interaction"""

description = 'Enables one axes navigation'
keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)
default_keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)

def trigger(self, sender, event, data=None):
if event.inaxes is None:
Expand All @@ -354,7 +354,7 @@ class ToolGrid(ToolToggleBase):
"""Tool to toggle the grid of the figure"""

description = 'Toogle Grid'
keymap = rcParams['keymap.grid']
default_keymap = rcParams['keymap.grid']

def trigger(self, sender, event, data=None):
if event.inaxes is None:
Expand All @@ -374,7 +374,7 @@ class ToolFullScreen(ToolToggleBase):
"""Tool to toggle full screen"""

description = 'Toogle Fullscreen mode'
keymap = rcParams['keymap.fullscreen']
default_keymap = rcParams['keymap.fullscreen']

def enable(self, event):
self.figure.canvas.manager.full_screen_toggle()
Expand Down Expand Up @@ -404,7 +404,7 @@ class ToolYScale(AxisScaleBase):
"""Tool to toggle between linear and logarithmic scales on the Y axis"""

description = 'Toogle Scale Y axis'
keymap = rcParams['keymap.yscale']
default_keymap = rcParams['keymap.yscale']

def set_scale(self, ax, scale):
ax.set_yscale(scale)
Expand All @@ -414,7 +414,7 @@ class ToolXScale(AxisScaleBase):
"""Tool to toggle between linear and logarithmic scales on the X axis"""

description = 'Toogle Scale X axis'
keymap = rcParams['keymap.xscale']
default_keymap = rcParams['keymap.xscale']

def set_scale(self, ax, scale):
ax.set_xscale(scale)
Expand Down Expand Up @@ -547,7 +547,7 @@ class ToolHome(ViewsPositionsBase):

description = 'Reset original view'
image = 'home.png'
keymap = rcParams['keymap.home']
default_keymap = rcParams['keymap.home']
_on_trigger = 'home'


Expand All @@ -556,7 +556,7 @@ class ToolBack(ViewsPositionsBase):

description = 'Back to previous view'
image = 'back.png'
keymap = rcParams['keymap.back']
default_keymap = rcParams['keymap.back']
_on_trigger = 'back'


Expand All @@ -565,7 +565,7 @@ class ToolForward(ViewsPositionsBase):

description = 'Forward to next view'
image = 'forward.png'
keymap = rcParams['keymap.forward']
default_keymap = rcParams['keymap.forward']
_on_trigger = 'forward'


Expand All @@ -581,7 +581,7 @@ class SaveFigureBase(ToolBase):

description = 'Save the figure'
image = 'filesave.png'
keymap = rcParams['keymap.save']
default_keymap = rcParams['keymap.save']


class ZoomPanBase(ToolToggleBase):
Expand Down Expand Up @@ -651,7 +651,7 @@ class ToolZoom(ZoomPanBase):

description = 'Zoom to rectangle'
image = 'zoom_to_rect.png'
keymap = rcParams['keymap.zoom']
default_keymap = rcParams['keymap.zoom']
cursor = cursors.SELECT_REGION
radio_group = 'default'

Expand Down Expand Up @@ -861,7 +861,7 @@ def _release(self, event):
class ToolPan(ZoomPanBase):
"""Pan axes with left mouse, zoom with right"""

keymap = rcParams['keymap.pan']
default_keymap = rcParams['keymap.pan']
description = 'Pan axes with left mouse, zoom with right'
image = 'move.png'
cursor = cursors.MOVE
Expand Down