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
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
adding zaxis and some pep8
  • Loading branch information
fariza committed Apr 7, 2015
commit a53419aafe1ae4452f074e53393f832874647a2f
55 changes: 43 additions & 12 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,7 @@ class NavigationBase(object):
locked
messagelock : `LockDraw` to know if the message is available to write
"""

_default_cursor = cursors.POINTER
_default_tools = [tools.ToolToggleGrid,
tools.ToolToggleFullScreen,
Expand All @@ -3255,6 +3256,7 @@ class NavigationBase(object):

def __init__(self, canvas, toolbar=None):
""".. automethod:: _toolbar_callback"""

self.canvas = canvas
self.toolbar = self._get_toolbar(toolbar, canvas)

Expand All @@ -3273,9 +3275,9 @@ def __init__(self, canvas, toolbar=None):
self._instances = {}
self._toggled = None

#to process keypress event
# to process keypress event
self.keypresslock = widgets.LockDraw()
#to write into toolbar message
# to write into toolbar message
self.messagelock = widgets.LockDraw()

for tool in self._default_tools:
Expand All @@ -3290,11 +3292,13 @@ def __init__(self, canvas, toolbar=None):
@classmethod
def get_default_tools(cls):
"""Get the default tools"""

return cls._default_tools

@classmethod
def set_default_tools(cls, tools):
"""Set default tools"""

cls._default_tools = tools

def _get_toolbar(self, toolbar, canvas):
Expand All @@ -3312,6 +3316,7 @@ def active_toggle(self):

**string** : Currently toggled tool, or None
"""

return self._toggled

@property
Expand All @@ -3320,6 +3325,7 @@ def instances(self):

**dictionary** : Contains the active instances that are registered
"""

return self._instances

def get_tool_keymap(self, name):
Expand All @@ -3334,6 +3340,7 @@ def get_tool_keymap(self, name):
----------
list : list of keys associated with the Tool
"""

keys = [k for k, i in six.iteritems(self._keys) if i == name]
return keys

Expand Down Expand Up @@ -3380,6 +3387,7 @@ def unregister(self, name):
If called, next time the `Tool` is used it will be reinstantiated
instead of using the existing instance.
"""

if self._toggled == name:
self._handle_toggle(name, from_toolbar=False)
if name in self._instances:
Expand All @@ -3393,6 +3401,7 @@ def remove_tool(self, name):
name : string
Name of the Tool
"""

self.unregister(name)
del self._tools[name]
keys = [k for k, v in six.iteritems(self._keys) if v == name]
Expand All @@ -3410,6 +3419,7 @@ def add_tool(self, tool):
tool : string or `Tool` class
Reference to find the class of the Tool to be added
"""

tool_cls = self._get_cls_to_instantiate(tool)
name = tool_cls.name

Expand Down Expand Up @@ -3445,7 +3455,7 @@ def add_tool(self, tool):

def _get_cls_to_instantiate(self, callback_class):
if isinstance(callback_class, six.string_types):
#FIXME: make more complete searching structure
# FIXME: make more complete searching structure
if callback_class in globals():
return globals()[callback_class]

Expand All @@ -3462,6 +3472,7 @@ def trigger_tool(self, name):

Method to programatically "click" on Tools
"""

self._trigger_tool(name, None, False)

def _trigger_tool(self, name, event, from_toolbar):
Expand All @@ -3475,8 +3486,7 @@ def _trigger_tool(self, name, event, from_toolbar):
instance = self._get_instance(name)
instance.trigger(event)
else:
#Non persistent tools, are
#instantiated and forgotten (reminds me an exgirlfriend?)
# Non persistent tools, are instantiated and forgotten
tool(self.canvas.figure, event)

def _key_press(self, event):
Expand All @@ -3491,7 +3501,7 @@ def _key_press(self, event):
def _get_instance(self, name):
if name not in self._instances:
instance = self._tools[name](self.canvas.figure)
#register instance
# register instance
self._instances[name] = instance

return self._instances[name]
Expand All @@ -3508,24 +3518,25 @@ def _toolbar_callback(self, name):
Name of the tool that was activated (click) by the user using the
toolbar
"""

self._trigger_tool(name, None, True)

def _handle_toggle(self, name, event=None, from_toolbar=False):
#toggle toolbar without callback
# toggle toolbar without callback
if not from_toolbar and self.toolbar:
self.toolbar._toggle(name, False)

instance = self._get_instance(name)
if self._toggled is None:
#first trigger of tool
# first trigger of tool
self._toggled = name
elif self._toggled == name:
#second trigger of tool
# second trigger of tool
self._toggled = None
else:
#other tool is triggered so trigger toggled tool
# other tool is triggered so trigger toggled tool
if self.toolbar:
#untoggle the previous toggled tool
# untoggle the previous toggled tool
self.toolbar._toggle(self._toggled, False)
self._get_instance(self._toggled).trigger(event)
self._toggled = name
Expand All @@ -3537,6 +3548,7 @@ def _handle_toggle(self, name, event=None, from_toolbar=False):

def list_tools(self):
"""Print the list the tools controlled by `Navigation`"""

print ('_' * 80)
print ("{0:20} {1:50} {2}".format('Name (id)', 'Tool description',
'Keymap'))
Expand All @@ -3550,6 +3562,7 @@ def list_tools(self):

def update(self):
"""Reset the axes stack"""

self.views.clear()
self.positions.clear()
# self.set_history_buttons()
Expand Down Expand Up @@ -3585,16 +3598,21 @@ def _mouse_move(self, event):

def draw(self):
"""Redraw the canvases, update the locators"""

for a in self.canvas.figure.get_axes():
xaxis = getattr(a, 'xaxis', None)
yaxis = getattr(a, 'yaxis', None)
zaxis = getattr(a, 'zaxis', None)
locators = []
if xaxis is not None:
locators.append(xaxis.get_major_locator())
locators.append(xaxis.get_minor_locator())
if yaxis is not None:
locators.append(yaxis.get_major_locator())
locators.append(yaxis.get_minor_locator())
if zaxis is not None:
locators.append(zaxis.get_major_locator())
locators.append(zaxis.get_minor_locator())

for loc in locators:
loc.refresh()
Expand All @@ -3608,6 +3626,7 @@ def set_cursor(self, cursor):
Set the current cursor to one of the :class:`Cursors`
enums values
"""

pass

def update_view(self):
Expand All @@ -3633,6 +3652,7 @@ def update_view(self):

def push_current(self):
"""push the current view limits and position onto the stack"""

lims = []
pos = []
for a in self.canvas.figure.get_axes():
Expand All @@ -3659,6 +3679,7 @@ def draw_rubberband(self, event, caller, x0, y0, x1, y1):
caller : instance trying to draw the rubberband
x0, y0, x1, y1 : coordinates
"""

if not self.canvas.widgetlock.available(caller):
warnings.warn("%s doesn't own the canvas widgetlock" % caller)

Expand All @@ -3673,6 +3694,7 @@ def remove_rubberband(self, event, caller):
event : `FigureCanvas` event
caller : instance trying to remove the rubberband
"""

if not self.canvas.widgetlock.available(caller):
warnings.warn("%s doesn't own the canvas widgetlock" % caller)

Expand All @@ -3684,12 +3706,14 @@ class ToolbarBase(object):
----------
manager : `FigureManager` instance that integrates this `Toolbar`
"""

def __init__(self, manager):
"""
.. automethod:: _add_toolitem
.. automethod:: _remove_toolitem
.. automethod:: _toggle
"""

self.manager = manager

def _add_toolitem(self, name, description, image_file, position,
Expand Down Expand Up @@ -3717,6 +3741,7 @@ def _add_toolitem(self, name, description, image_file, position,
* `False` : The button is a normal button (returns to unpressed
state after release)
"""

raise NotImplementedError

def add_separator(self, pos):
Expand All @@ -3728,10 +3753,12 @@ def add_separator(self, pos):
Position where to add the separator within the toolitems
if -1 at the end
"""

pass

def set_message(self, s):
"""Display a message on toolbar or in status bar"""

pass

def _toggle(self, name, callback=False):
Expand All @@ -3746,7 +3773,8 @@ def _toggle(self, name, callback=False):
* `False`: toggle the button without calling the callback

"""
#carefull, callback means to perform or not the callback while toggling

# carefull, callback means to perform or not the callback while toggling
raise NotImplementedError

def _remove_toolitem(self, name):
Expand All @@ -3758,6 +3786,7 @@ def _remove_toolitem(self, name):
Name of the tool to remove

"""

raise NotImplementedError

def move_toolitem(self, pos_ini, pos_fin):
Expand All @@ -3770,6 +3799,7 @@ def move_toolitem(self, pos_ini, pos_fin):
pos_fin : integer
Final position of the toolitem
"""

pass

def set_toolitem_visibility(self, name, visible):
Expand All @@ -3783,4 +3813,5 @@ def set_toolitem_visibility(self, name, visible):
* `True`: set the toolitem visible
* `False`: set the toolitem invisible
"""

pass
Loading
0