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

Skip to content

Commit 1571ebb

Browse files
authored
Merge pull request #6598 from anntzer/history-for-figureoptions
ENH: Register figureoptions edits in views history.
2 parents f5c146d + d601ad1 commit 1571ebb

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from six.moves import xrange
4040

4141
from contextlib import contextmanager
42+
from functools import partial
4243
import importlib
4344
import io
4445
import itertools
@@ -2833,6 +2834,13 @@ def __init__(self, canvas):
28332834
self.mode = '' # a mode string for the status bar
28342835
self.set_history_buttons()
28352836

2837+
@partial(canvas.mpl_connect, 'draw_event')
2838+
def define_home(event):
2839+
self.push_current()
2840+
# The decorator sets `define_home` to the callback cid, so we can
2841+
# disconnect it after the first use.
2842+
canvas.mpl_disconnect(define_home)
2843+
28362844
def set_message(self, s):
28372845
"""Display a message on toolbar or in status bar."""
28382846

@@ -2982,11 +2990,6 @@ def press_pan(self, event):
29822990
return
29832991

29842992
x, y = event.x, event.y
2985-
2986-
# push the current view to define home if stack is empty
2987-
if self._views.empty():
2988-
self.push_current()
2989-
29902993
self._xypress = []
29912994
for i, a in enumerate(self.canvas.figure.get_axes()):
29922995
if (x is not None and y is not None and a.in_axes(event) and
@@ -3022,11 +3025,6 @@ def press_zoom(self, event):
30223025
return
30233026

30243027
x, y = event.x, event.y
3025-
3026-
# push the current view to define home if stack is empty
3027-
if self._views.empty():
3028-
self.push_current()
3029-
30303028
self._xypress = []
30313029
for i, a in enumerate(self.canvas.figure.get_axes()):
30323030
if (x is not None and y is not None and a.in_axes(event) and

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def figure_edit(axes, parent=None):
4747
sep = (None, None) # separator
4848

4949
# Get / General
50+
# Cast to builtin floats as they have nicer reprs.
5051
xmin, xmax = map(float, axes.get_xlim())
5152
ymin, ymax = map(float, axes.get_ylim())
5253
general = [('Title', axes.get_title()),
@@ -177,6 +178,9 @@ def prepare_data(d, init):
177178

178179
def apply_callback(data):
179180
"""This function will be called to apply changes"""
181+
orig_xlim = axes.get_xlim()
182+
orig_ylim = axes.get_ylim()
183+
180184
general = data.pop(0)
181185
curves = data.pop(0) if has_curve else []
182186
images = data.pop(0) if has_image else []
@@ -248,6 +252,8 @@ def apply_callback(data):
248252
# Redraw
249253
figure = axes.get_figure()
250254
figure.canvas.draw()
255+
if not (axes.get_xlim() == orig_xlim and axes.get_ylim() == orig_ylim):
256+
figure.canvas.toolbar.push_current()
251257

252258
data = formlayout.fedit(datalist, title="Figure options", parent=parent,
253259
icon=get_icon('qt4_editor_options.svg'),

0 commit comments

Comments
 (0)