Skip to content

Central dispatcher TODELETE #3663

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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dda0cdc
navigation and toolbar coexistence
fariza Jan 23, 2014
10f5dc7
mod keypress in figuremanager
fariza Jan 23, 2014
08a6020
extra files
fariza Jan 23, 2014
c6c0ad3
helper methods in toolbar and navigation
fariza Jan 24, 2014
1fc29fa
Adding doc to base methods
fariza Jan 24, 2014
979875e
property for active_toggle
fariza Jan 26, 2014
c5c4f0f
simulate click
fariza Jan 27, 2014
97dfda7
pep8 backend_tools
fariza Jan 27, 2014
6b647ad
activate renamed to trigger
fariza Jan 28, 2014
99667aa
toggle tools using enable/disable from its trigger method
fariza Jan 29, 2014
6c19579
simplifying _handle_toggle
fariza Jan 29, 2014
0495aac
reducing number of locks
fariza Jan 29, 2014
fb46fc1
pep8 correction
fariza Jan 29, 2014
d49c431
changing toggle and persistent attributes for issubclass
fariza Feb 4, 2014
5ba6210
bug in combined key press
fariza Feb 4, 2014
7ca8626
untoggle zoom and pan from keypress while toggled
fariza Feb 4, 2014
dcc0f16
classmethods for default tools modification
fariza Feb 6, 2014
bc703e0
six fixes
fariza Apr 24, 2014
68dc711
adding zaxis and some pep8
fariza May 1, 2014
bb9f1c7
removing legacy method dynamic update
fariza May 6, 2014
2c2e649
tk backend
fariza May 6, 2014
a99367f
pep8
fariza May 6, 2014
3d1be34
example working with Tk
fariza May 6, 2014
afdd34c
cleanup
fariza May 7, 2014
5b49c7a
duplicate code in keymap tool initialization
fariza Jul 24, 2014
773db88
grammar corrections
fariza Jul 24, 2014
2ca6926
moving views and positions to tools
fariza Jul 24, 2014
661417d
The views positions mixin automatically adds the clear as axobserver
fariza Jul 25, 2014
90ab64f
bug when navigation was not defined
fariza Jul 25, 2014
55dd149
Small refactor so that we first initiate the Navigation (ToolManager)…
OceanWolf Jul 28, 2014
15ac091
Update for Sphinx documentation
OceanWolf Jul 28, 2014
8cd241c
Moved default_tool initilisation to FigureManagerBase and cleaned.
OceanWolf Jul 29, 2014
39f5b74
Fix navigation
OceanWolf Jul 29, 2014
b20dade
Temporary fix to backends
OceanWolf Jul 29, 2014
ff94301
Merge pull request #1 from OceanWolf/navigation-toolbar-coexistence-e…
fariza Jul 29, 2014
2cb4501
removing persistent tools
fariza Sep 3, 2014
9d3c977
removing unregister
fariza Sep 4, 2014
6e0b7e6
change cursor inmediately after toggle
fariza Sep 5, 2014
206935b
removing intoolbar
fariza Oct 15, 2014
30dcf3b
events working
fariza Oct 16, 2014
d8e90df
using pydispatch
fariza Oct 17, 2014
00c8f59
pydispatch in travis
fariza Oct 18, 2014
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
The views positions mixin automatically adds the clear as axobserver
  • Loading branch information
fariza committed Jul 25, 2014
commit 661417d949f4132d582e75fe790d1ffecdf7b46f
6 changes: 3 additions & 3 deletions examples/user_interfaces/navigation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import matplotlib
matplotlib.use('GTK3Cairo')
# matplotlib.use('TkAGG')
# matplotlib.use('GTK3Cairo')
matplotlib.use('TkAGG')
matplotlib.rcParams['toolbar'] = 'navigation'
import matplotlib.pyplot as plt
from matplotlib.backend_tools import ToolBase
Expand Down Expand Up @@ -54,6 +54,6 @@ def trigger(self, event):
fig.canvas.manager.navigation.add_tool('copy', CopyToolGTK3)

# Just for fun, lets remove the back button
fig.canvas.manager.navigation.remove_tool('Back')
# fig.canvas.manager.navigation.remove_tool('Back')

plt.show()
32 changes: 26 additions & 6 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def set_figure(self, figure):


class ToolPersistentBase(ToolBase):
"""Persisten tool
"""Persistent tool

Persistent Tools are keept alive after their initialization,
Persistent Tools are kept alive after their initialization,
a reference of the instance is kept by `navigation`.

Notes
Expand Down Expand Up @@ -287,20 +287,41 @@ def trigger(self, event):


class ViewsPositionsMixin(object):
"""Mixin to handle changes in views and positions

Tools that change the views and positions, use this mixin to
keep track of the changes.
"""

views = WeakKeyDictionary()
"""Record of views with Figure objects as keys"""

positions = WeakKeyDictionary()
"""Record of positions with Figure objects as keys"""

def init_vp(self):
"""Add a figure to the list of figures handled by this mixin

To handle the views and positions for a given figure, this method
has to be called at least once before any other method.

The best way to call it is during the set_figure method of the tools
"""
if self.figure not in self.views:
self.views[self.figure] = cbook.Stack()
self.positions[self.figure] = cbook.Stack()
# Define Home
self.push_current()
# Adding the clear method as axobserver, removes this burden from
# the backend
self.figure.add_axobserver(self.clear)

@classmethod
def clear(cls, figure):
"""Reset the axes stack"""
print('clear')
if figure in cls.views:
print('done clear')
cls.views[figure].clear()
cls.positions[figure].clear()

Expand Down Expand Up @@ -375,12 +396,9 @@ def forward(self):
self.positions[self.figure].forward()


def clear_views_positions(figure):
ViewsPositionsMixin.clear(figure)


class ViewsPositionsBase(ViewsPositionsMixin, ToolBase):
# Simple base to avoid repeating code on Home, Back and Forward
# Not of much use for other tools, so not documented
_on_trigger = None

def set_figure(self, *args):
Expand Down Expand Up @@ -435,6 +453,8 @@ class SaveFigureBase(ToolBase):


class ZoomPanBase(ViewsPositionsMixin, ToolToggleBase):
# Base class to group common functionality between zoom and pan
# Not of much use for other tools, so not documented
def __init__(self, *args):
ToolToggleBase.__init__(self, *args)
self.init_vp()
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase
from matplotlib.backend_bases import ShowBase, ToolbarBase, NavigationBase
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, \
clear_views_positions
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase

from matplotlib.cbook import is_string_like, is_writable_file_like
from matplotlib.colors import colorConverter
Expand Down Expand Up @@ -439,7 +438,7 @@ def destroy(*args):
def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
if self.navigation is not None:
clear_views_positions(fig)
pass
elif self.toolbar is not None: self.toolbar.update()
self.canvas.figure.add_axobserver(notify_axes_change)

Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase
from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase
from matplotlib.backend_bases import ShowBase, ToolbarBase, NavigationBase
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, \
clear_views_positions
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase
from matplotlib._pylab_helpers import Gcf

from matplotlib.figure import Figure
Expand Down Expand Up @@ -548,7 +547,7 @@ def __init__(self, canvas, num, window):
def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
if self.navigation is not None:
clear_views_positions(fig)
pass
elif self.toolbar is not None:
self.toolbar.update()
self.canvas.figure.add_axobserver(notify_axes_change)
Expand Down