-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MEP27 Decouple pyplot from backends (refactoring Gcf out of backend code) #4143
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
24caf2b
2b05d38
f4fc354
0b31e3a
6fb452e
0a868a2
61ba2b4
f0eb84c
8fe9cd7
494e5f1
ed16178
21b8f58
cf42e3b
f027b16
24b7b73
bc99129
7f7f05e
713abcb
80adaaf
4e5f69d
160ef57
b6d6acc
ecd5038
f8e83fe
c53b79a
34c6b12
8a4268a
44df199
860a8ed
c44e744
2fe9215
3b434ef
490629f
8eb987b
224a4f3
cdbd51b
50e3719
85be519
7edaf5a
8e6e252
72575cb
4a78246
e300707
ee76451
6f0c7ab
ae9bf5b
fb004e0
1d2095b
24e43b3
208c3be
a44ebd9
f8f9cf2
0e09a54
a38b6d7
64f0c61
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import time | ||
import warnings | ||
|
||
import os | ||
|
||
|
||
class Cursors(object): | ||
"""Simple namespace for cursor reference""" | ||
|
@@ -679,6 +681,43 @@ class SaveFigureBase(ToolBase): | |
default_keymap = rcParams['keymap.save'] | ||
|
||
|
||
class ToolSaveFigure(ToolBase): | ||
"""Saves the figure""" | ||
|
||
description = 'Save the figure' | ||
image = 'filesave.png' | ||
default_keymap = rcParams['keymap.save'] | ||
|
||
def get_filechooser(self): | ||
fc = self.figure.canvas.backend.FileChooserDialog( | ||
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. the 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 added it to the canvas in the commit before this... the reason for this, we will always have a canvas we won't always have a |
||
title='Save the figure', | ||
parent=self.figure.canvas.manager.window, | ||
path=os.path.expanduser(rcParams.get('savefig.directory', '')), | ||
filetypes=self.figure.canvas.get_supported_filetypes(), | ||
default_filetype=self.figure.canvas.get_default_filetype()) | ||
fc.set_current_name(self.figure.canvas.get_default_filename()) | ||
return fc | ||
|
||
def trigger(self, *args, **kwargs): | ||
chooser = self.get_filechooser() | ||
fname, format_ = chooser.get_filename_from_user() | ||
chooser.destroy() | ||
if fname: | ||
startpath = os.path.expanduser( | ||
rcParams.get('savefig.directory', '')) | ||
if startpath == '': | ||
# explicitly missing key or empty str signals to use cwd | ||
rcParams['savefig.directory'] = startpath | ||
else: | ||
# save dir for next time | ||
rcParams['savefig.directory'] = os.path.dirname( | ||
six.text_type(fname)) | ||
try: | ||
self.figure.canvas.print_figure(fname, format=format_) | ||
except Exception as e: | ||
error_msg_gtk(str(e), parent=self) | ||
|
||
|
||
class ZoomPanBase(ToolToggleBase): | ||
"""Base class for `ToolZoom` and `ToolPan`""" | ||
def __init__(self, *args): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -923,38 +923,6 @@ def set_message(self, s): | |
self.push(self._context, s) | ||
|
||
|
||
class SaveFigureGTK3(backend_tools.SaveFigureBase): | ||
|
||
def get_filechooser(self): | ||
fc = FileChooserDialog( | ||
title='Save the figure', | ||
parent=self.figure.canvas.manager.window, | ||
path=os.path.expanduser(rcParams.get('savefig.directory', '')), | ||
filetypes=self.figure.canvas.get_supported_filetypes(), | ||
default_filetype=self.figure.canvas.get_default_filetype()) | ||
fc.set_current_name(self.figure.canvas.get_default_filename()) | ||
return fc | ||
|
||
def trigger(self, *args, **kwargs): | ||
chooser = self.get_filechooser() | ||
fname, format_ = chooser.get_filename_from_user() | ||
chooser.destroy() | ||
if fname: | ||
startpath = os.path.expanduser( | ||
rcParams.get('savefig.directory', '')) | ||
if startpath == '': | ||
# explicitly missing key or empty str signals to use cwd | ||
rcParams['savefig.directory'] = startpath | ||
else: | ||
# save dir for next time | ||
rcParams['savefig.directory'] = os.path.dirname( | ||
six.text_type(fname)) | ||
try: | ||
self.figure.canvas.print_figure(fname, format=format_) | ||
except Exception as e: | ||
error_msg_gtk(str(e), parent=self) | ||
|
||
|
||
class SetCursorGTK3(backend_tools.SetCursorBase): | ||
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. Why did this + 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. There is a new generic Tool that does exactly that without having to implement it for each backend. 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. 🐑 Sorry for asking silly questions. 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. Hehe, no worries, this actually triggered this MEP, looking through the new The aim of this MEP became removing all matplotlib specific code from the backends, allowing the backends to become flexible and reusable for any matplotlib task. |
||
def set_cursor(self, cursor): | ||
self.figure.canvas.get_property("window").set_cursor(cursord[cursor]) | ||
|
@@ -1039,7 +1007,6 @@ def error_msg_gtk(msg, parent=None): | |
dialog.destroy() | ||
|
||
|
||
backend_tools.ToolSaveFigure = SaveFigureGTK3 | ||
backend_tools.ToolConfigureSubplots = ConfigureSubplotsGTK3 | ||
backend_tools.ToolSetCursor = SetCursorGTK3 | ||
backend_tools.ToolRubberband = RubberbandGTK3 | ||
|
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.
Adding this one,
SaveFigureBase
should be removed.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.
I agree, I added it to the Todo list at the top of the PR under TkAgg. As the code stands at the moment, TkAgg still works in this PR for
rcParams['toolbar'] == 'toolmanager'
.