mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
Allow plot plugin to have tools
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user