Skip to content

Commit

Permalink
Merge pull request #6 from fariza/figuremanager-figure-centered
Browse files Browse the repository at this point in the history
FigureManager manages the Figure and not the Canvas, pt2
  • Loading branch information
OceanWolf committed Jun 25, 2015
2 parents eae38e5 + ca3a560 commit 18a36a3
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -79,14 +82,14 @@ 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 = 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)
self.toolmanager = ToolManager(self.figure.canvas)
self.toolbar = self._get_toolbar()

tools.add_tools_to_manager(self.toolmanager)
Expand All @@ -108,7 +111,24 @@ 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

@figure.setter
def figure(self, figure):
if hasattr(self, '_figure'):
raise NotImplementedError

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.
Expand All @@ -120,7 +140,7 @@ def destroy(self, *args):
return

self._destroying = True
self.canvas.destroy()
self.figure.canvas.destroy()
if self.toolbar:
self.toolbar.destroy()
self.window.destroy()
Expand Down

0 comments on commit 18a36a3

Please sign in to comment.