8000 Register figureoptions edits in views history. by anntzer · Pull Request #6598 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Register figureoptions edits in views history. #6598

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 2 commits into from
Aug 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Register figureoptions edits in views history.
Changing axes limits in views history is now taken into account by the
views history navigation.  The home position is now defined the first
time the figure canvas is drawn (rather than the first time an edit
button is selected), via a one-shot callback.
  • Loading branch information
anntzer committed Aug 10, 2017
commit fb83117a9eb3083768d4e067414fe4dbea49e98e
18 changes: 8 additions & 10 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from six.moves import xrange

from contextlib import contextmanager
from functools import partial
import importlib
import io
import itertools
Expand Down Expand Up @@ -2833,6 +2834,13 @@ def __init__(self, canvas):
self.mode = '' # a mode string for the status bar
self.set_history_buttons()

@partial(canvas.mpl_connect, 'draw_event')
def define_home(event):
self.push_current()
# The decorator sets `define_home` to the callback cid, so we can
# disconnect it after the first use.
canvas.mpl_disconnect(define_home)
Copy link
Member

Choose a reason for hiding this comment

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

We need to update the docs on mpl_disconnect that this works with a function instead of a cid.

Independent of that, I do not see where this is used.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I now understand this and I like it 😄

I have not seen this pattern before, can you leave a short comment as to what this is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


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

Expand Down Expand Up @@ -2982,11 +2990,6 @@ def press_pan(self, event):
return

x, y = event.x, event.y

# push the current view to define home if stack is empty
if self._views.empty():
self.push_current()

self._xypress = []
for i, a in enumerate(self.canvas.figure.get_axes()):
if (x is not None and y is not None and a.in_axes(event) and
Expand Down Expand Up @@ -3022,11 +3025,6 @@ def press_zoom(self, event):
return

x, y = event.x, event.y

# push the current view to define home if stack is empty
if self._views.empty():
self.push_current()

self._xypress = []
for i, a in enumerate(self.canvas.figure.get_axes()):
if (x is not None and y is not None and a.in_axes(event) and
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def apply_callback(data):
# Redraw
figure = axes.get_figure()
figure.canvas.draw()
figure.canvas.toolbar.push_current()

data = formlayout.fedit(datalist, title="Figure options", parent=parent,
icon=get_icon('qt4_editor_options.svg'),
Expand Down
0