-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 |
---|---|---|
|
@@ -336,77 +336,84 @@ def trigger(self, sender, event, data=None): | |
ax.figure.canvas.draw() | ||
|
||
|
||
class ViewsPositions(object): | ||
"""Auxiliary class to handle changes in views and positions""" | ||
class ToolViewsPositions(ToolBase): | ||
"""Auxiliary Tool to handle changes in views and positions | ||
|
||
This tool is accessed by navigation.manipulate_tool | ||
This tool is used by all the tools that need to access the record of | ||
views and positions of the figure | ||
- Zoom | ||
- Pan | ||
- Home | ||
- Back | ||
- Forward | ||
""" | ||
|
||
views = WeakKeyDictionary() | ||
"""Record of views with Figure objects as keys""" | ||
def __init__(self, *args, **kwargs): | ||
self.views = WeakKeyDictionary() | ||
self.positions = WeakKeyDictionary() | ||
ToolBase.__init__(self, *args, **kwargs) | ||
|
||
positions = WeakKeyDictionary() | ||
"""Record of positions with Figure objects as keys""" | ||
def set_figure(self, figure): | ||
ToolBase.set_figure(self, figure) | ||
|
||
@classmethod | ||
def add_figure(cls, figure): | ||
"""Add a figure to the list of figures handled by this class""" | ||
if figure not in cls.views: | ||
cls.views[figure] = cbook.Stack() | ||
cls.positions[figure] = cbook.Stack() | ||
def add_figure(self): | ||
"""Add the current figure to the stack of views and positions""" | ||
if self.figure not in self.views: | ||
self.views[self.figure] = cbook.Stack() | ||
self.positions[self.figure] = cbook.Stack() | ||
# Define Home | ||
cls.push_current(figure) | ||
self.push_current() | ||
# Adding the clear method as axobserver, removes this burden from | ||
# the backend | ||
figure.add_axobserver(cls.clear) | ||
self.figure.add_axobserver(self.clear) | ||
|
||
@classmethod | ||
def clear(cls, figure): | ||
def clear(self, figure): | ||
"""Reset the axes stack""" | ||
if figure in cls.views: | ||
cls.views[figure].clear() | ||
cls.positions[figure].clear() | ||
if figure in self.views: | ||
self.views[figure].clear() | ||
self.positions[figure].clear() | ||
|
||
@classmethod | ||
def update_view(cls, figure): | ||
def update_view(self): | ||
"""Update the viewlim and position from the view and | ||
position stack for each axes | ||
""" | ||
|
||
lims = cls.views[figure]() | ||
lims = self.views[self.figure]() | ||
if lims is None: | ||
return | ||
pos = cls.positions[figure]() | ||
pos = self.positions[self.figure]() | ||
if pos is None: | ||
return | ||
for i, a in enumerate(figure.get_axes()): | ||
for i, a in enumerate(self.figure.get_axes()): | ||
xmin, xmax, ymin, ymax = lims[i] | ||
a.set_xlim((xmin, xmax)) | ||
a.set_ylim((ymin, ymax)) | ||
# Restore both the original and modified positions | ||
a.set_position(pos[i][0], 'original') | ||
a.set_position(pos[i][1], 'active') | ||
|
||
figure.canvas.draw_idle() | ||
self.figure.canvas.draw_idle() | ||
|
||
@classmethod | ||
def push_current(cls, figure): | ||
def push_current(self): | ||
"""push the current view limits and position onto the stack""" | ||
|
||
lims = [] | ||
pos = [] | ||
for a in figure.get_axes(): | ||
for a in self.figure.get_axes(): | ||
xmin, xmax = a.get_xlim() | ||
ymin, ymax = a.get_ylim() | ||
lims.append((xmin, xmax, ymin, ymax)) | ||
# Store both the original and modified positions | ||
pos.append(( | ||
a.get_position(True).frozen(), | ||
a.get_position().frozen())) | ||
cls.views[figure].push(lims) | ||
cls.positions[figure].push(pos) | ||
self.views[self.figure].push(lims) | ||
self.positions[self.figure].push(pos) | ||
|
||
@classmethod | ||
def refresh_locators(cls, figure): | ||
def refresh_locators(self): | ||
"""Redraw the canvases, update the locators""" | ||
for a in figure.get_axes(): | ||
for a in self.figure.get_axes(): | ||
xaxis = getattr(a, 'xaxis', None) | ||
yaxis = getattr(a, 'yaxis', None) | ||
zaxis = getattr(a, 'zaxis', None) | ||
|
@@ -423,37 +430,30 @@ def refresh_locators(cls, figure): | |
|
||
for loc in locators: | ||
loc.refresh() | ||
figure.canvas.draw_idle() | ||
self.figure.canvas.draw_idle() | ||
|
||
@classmethod | ||
def home(cls, figure): | ||
cls.views[figure].home() | ||
cls.positions[figure].home() | ||
def home(self): | ||
self.views[self.figure].home() | ||
self.positions[self.figure].home() | ||
|
||
@classmethod | ||
def back(cls, figure): | ||
cls.views[figure].back() | ||
cls.positions[figure].back() | ||
def back(self): | ||
self.views[self.figure].back() | ||
self.positions[self.figure].back() | ||
|
||
@classmethod | ||
def forward(cls, figure): | ||
cls.views[figure].forward() | ||
cls.positions[figure].forward() | ||
def forward(self): | ||
self.views[self.figure].forward() | ||
self.positions[self.figure].forward() | ||
|
||
|
||
class ViewsPositionsBase(ToolBase): | ||
"""Base class for ToolHome, ToolBack and ToolForward""" | ||
|
||
_on_trigger = None | ||
|
||
def __init__(self, *args, **kwargs): | ||
ToolBase.__init__(self, *args, **kwargs) | ||
self.viewspos = ViewsPositions() | ||
|
||
def trigger(self, sender, event, data=None): | ||
self.viewspos.add_figure(self.figure) | ||
getattr(self.viewspos, self._on_trigger)(self.figure) | ||
self.viewspos.update_view(self.figure) | ||
self.navigation.get_tool('viewpos').add_figure() | ||
getattr(self.navigation.get_tool('viewpos'), self._on_trigger)() | ||
self.navigation.get_tool('viewpos').update_view() | ||
|
||
|
||
class ToolHome(ViewsPositionsBase): | ||
|
@@ -499,15 +499,13 @@ class SaveFigureBase(ToolBase): | |
|
||
|
||
class ZoomPanBase(ToolToggleBase): | ||
# Base class to group common functionality between zoom and pan | ||
# Not of much use for other tools, so not documented | ||
"""Base class for Zoom and Pan tools""" | ||
def __init__(self, *args): | ||
ToolToggleBase.__init__(self, *args) | ||
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 thinking, should we be using super() here and in other Tools? 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 don't know how healthy is to mix super and and direct method calling.... |
||
self._button_pressed = None | ||
self._xypress = None | ||
self._idPress = None | ||
self._idRelease = None | ||
self.viewspos = ViewsPositions() | ||
|
||
def enable(self, event): | ||
self.figure.canvas.widgetlock(self) | ||
|
@@ -523,7 +521,7 @@ def disable(self, event): | |
self.figure.canvas.mpl_disconnect(self._idRelease) | ||
|
||
def trigger(self, sender, event, data=None): | ||
self.viewspos.add_figure(self.figure) | ||
self.navigation.get_tool('viewpos').add_figure() | ||
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. should we use some module constant rather than a hard-coded value? |
||
ToolToggleBase.trigger(self, sender, event, data) | ||
|
||
|
||
|
@@ -543,7 +541,7 @@ def _cancel_action(self): | |
for zoom_id in self._ids_zoom: | ||
self.figure.canvas.mpl_disconnect(zoom_id) | ||
self.navigation.tool_trigger_event('rubberband', self) | ||
self.viewspos.refresh_locators(self.figure) | ||
self.navigation.get_tool('viewpos').refresh_locators() | ||
self._xypress = None | ||
self._button_pressed = None | ||
self._ids_zoom = [] | ||
|
@@ -611,8 +609,6 @@ def _mouse_move(self, event): | |
x1, y1, x2, y2 = a.bbox.extents | ||
x, lastx = x1, x2 | ||
|
||
# self.navigation.draw_rubberband(event, self, x, y, lastx, lasty) | ||
# data = {'x': x, 'y': y, 'lastx': lastx, 'lasty': lasty} | ||
self.navigation.tool_trigger_event('rubberband', | ||
self, | ||
data=(x, y, lastx, lasty)) | ||
|
@@ -736,7 +732,7 @@ def _release(self, event): | |
a.set_ylim((ry1, ry2)) | ||
|
||
self._zoom_mode = None | ||
self.viewspos.push_current(self.figure) | ||
self.navigation.get_tool('viewpos').push_current() | ||
self._cancel_action() | ||
|
||
|
||
|
@@ -757,7 +753,7 @@ def _cancel_action(self): | |
self._xypress = [] | ||
self.figure.canvas.mpl_disconnect(self._idDrag) | ||
self.navigation.messagelock.release(self) | ||
self.viewspos.refresh_locators(self.figure) | ||
self.navigation.get_tool('viewpos').refresh_locators() | ||
|
||
def _press(self, event): | ||
if event.button == 1: | ||
|
@@ -794,7 +790,7 @@ def _release(self, event): | |
self._cancel_action() | ||
return | ||
|
||
self.viewspos.push_current(self.figure) | ||
self.navigation.get_tool('viewpos').push_current() | ||
self._cancel_action() | ||
|
||
def _mouse_move(self, event): | ||
|
@@ -842,6 +838,7 @@ def _mouse_move(self, event): | |
(ToolXScale, 'xscale'), | ||
(ToolYScale, 'yscale'), | ||
(ToolCursorPosition, 'position'), | ||
(ToolViewsPositions, 'viewpos'), | ||
('ToolSetCursor', 'cursor'), | ||
('ToolRubberband', 'rubberband')]]] | ||
|
||
|
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.
thanks for the mplot3d support!