-
-
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 |
---|---|---|
|
@@ -61,6 +61,9 @@ class FigureManager(cbook.EventEmitter): | |
canvas : `matplotlib.backend_bases.FigureCanvasBase` | ||
The GUI element on which we draw. | ||
|
||
figure : `matplotlib.figure.Figure` | ||
The figure that holds the canvas | ||
|
||
toolbar : `matplotlib.backend_bases.NavigationToolbar2` | ||
The toolbar used for interacting with the figure. | ||
|
||
|
@@ -79,14 +82,15 @@ def __init__(self, figure, num): | |
self.window = self._backend.Window('Figure %d' % num) | ||
self.window.mpl_connect('window_destroy_event', self.destroy) | ||
|
||
self.canvas = self._backend.FigureCanvas(figure, manager=self) | ||
self._figure = None | ||
self._set_figure(figure) | ||
|
||
w = int(self.canvas.figure.bbox.width) | ||
h = int(self.canvas.figure.bbox.height) | ||
w = int(self.figure.bbox.width) | ||
h = int(self.figure.bbox.height) | ||
|
||
self.window.add_element(self.canvas, True, 'center') | ||
self.window.add_element(self.figure.canvas, True, 'center') | ||
|
||
self.toolmanager = ToolManager(self.canvas.figure) | ||
self.toolmanager = ToolManager(self.figure) | ||
self.toolbar = self._get_toolbar() | ||
|
||
tools.add_tools_to_manager(self.toolmanager) | ||
|
@@ -108,7 +112,20 @@ def notify_axes_change(fig): | |
'this will be called whenever the current axes is changed' | ||
if self.toolmanager is None and self.toolbar is not None: | ||
self.toolbar.update() | ||
self.canvas.figure.add_axobserver(notify_axes_change) | ||
self.figure.add_axobserver(notify_axes_change) | ||
|
||
@property | ||
def figure(self): | ||
return self._figure | ||
|
||
def _set_figure(self, figure): | ||
if not figure.canvas: | ||
self._backend.FigureCanvas(figure, manager=self) | ||
self._figure = figure | ||
|
||
@property | ||
def canvas(self): | ||
return self._figure.canvas | ||
|
||
def destroy(self, *args): | ||
"""Called to destroy this FigureManager. | ||
|
@@ -120,7 +137,7 @@ def destroy(self, *args): | |
return | ||
|
||
self._destroying = True | ||
self.canvas.destroy() | ||
self.figure.canvas.destroy() | ||
if self.toolbar: | ||
self.toolbar.destroy() | ||
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 don't let 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. forget it, it is much simpler this way 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. Not sure... can leave it for a later refactor if someone feels inclined :P. 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 do think this a bit too complicated for now as this will depend on the backend... i.e. if one added backend specific widgets to the thing that have a different method name to destroy (assuming they have one). So for now I would rather leave this open like this, leave the class that created the items have the responsibility for cleaning them up. |
||
self.window.destroy() | ||
|
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.
Do we need the add_axobserver? it is already handled by toolmanager and as far as I know MEP27 is going to be used exclusively with toolmanager.