Allow plot plugin to have tools

This commit is contained in:
Steven Silvester
2015-06-20 06:51:39 -05:00
parent be5f6fdc3f
commit f442fe231a
8 changed files with 162 additions and 135 deletions
+21
View File
@@ -2,6 +2,7 @@ import numpy as np
from ..qt import QtGui
from ..utils import new_plot
from ..utils.canvas import BlitManager, EventManager
from .base import Plugin
@@ -23,11 +24,17 @@ class PlotPlugin(Plugin):
self._height = height
self._width = width
self._blit_manager = None
self._tools = []
self._event_manager = None
def attach(self, image_viewer):
super(PlotPlugin, self).attach(image_viewer)
# Add plot for displaying intensity profile.
self.add_plot()
if image_viewer.useblit:
self._blit_manager = BlitManager(self.ax)
self._event_manager = EventManager(self.ax)
def redraw(self):
"""Redraw plot."""
@@ -51,3 +58,17 @@ class PlotPlugin(Plugin):
def _update_original_image(self, image):
super(PlotPlugin, self)._update_original_image(image)
self.redraw()
def add_tool(self, tool):
if self._blit_manager:
self._blit_manager.add_artists(tool.artists)
self._tools.append(tool)
self._event_manager.attach(tool)
def remove_tool(self, tool):
if tool not in self._tools:
return
if self._blit_manager:
self._blit_manager.remove_artists(tool.artists)
self._tools.remove(tool)
self._event_manager.detach(tool)