diff --git a/jdaviz/configs/imviz/plugins/tools.py b/jdaviz/configs/imviz/plugins/tools.py index c217314481..39dfc2af01 100644 --- a/jdaviz/configs/imviz/plugins/tools.py +++ b/jdaviz/configs/imviz/plugins/tools.py @@ -1,13 +1,19 @@ import time +import os + from echo import delay_callback + from glue.config import viewer_tool from glue.core import BaseData from glue_jupyter.bqplot.common.tools import Tool from glue.viewers.common.tool import CheckableTool from glue.plugins.wcs_autolinking.wcs_autolinking import wcs_autolink, WCSLink +from glue_jupyter.bqplot.common.tools import BqplotPanZoomMode __all__ = [] +ICON_DIR = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'data', 'icons') + @viewer_tool class BlinkOnce(Tool): @@ -17,30 +23,28 @@ class BlinkOnce(Tool): tool_tip = ('Click on this button to display the next image, ' 'or you can also press the "b" key anytime') - def __init__(self, viewer, **kwargs): - super().__init__(viewer, **kwargs) - def activate(self): self.viewer.blink_once() @viewer_tool -class BqplotMatchWCS(CheckableTool): - - icon = 'glue_link' - tool_id = 'bqplot:matchwcs' - action_text = 'Match WCS between images' - tool_tip = 'Click on image to have the other image viewer show the same coordinates' - - def __init__(self, viewer, **kwargs): +class BqplotMatchWCS(BqplotPanZoomMode): - super().__init__(viewer, **kwargs) + icon = os.path.join(ICON_DIR, 'pan_wcs.png') + tool_id = 'bqplot:panzoomwcs' + action_text = 'Pan, matching WCS between viwers' + tool_tip = 'Pan and Zoom in this viewer to see the same regions in other viewers' def activate(self): - self.viewer.add_event_callback(self.on_mouse_or_key_event, events=['click']) + super().activate() + + self.viewer.state.add_callback('x_min', self.on_limits_change) + self.viewer.state.add_callback('x_max', self.on_limits_change) + self.viewer.state.add_callback('y_min', self.on_limits_change) + self.viewer.state.add_callback('y_max', self.on_limits_change) - # For now clickling this will automatically set up links between datasets. We + # For now clicking this will automatically set up links between datasets. We # do this when activating this tool so that this ends up being 'opt-in' only # when the user wants to match WCS. @@ -72,21 +76,26 @@ def activate(self): break viewer.state.reference_data = self.viewer.state.reference_data + # Trigger a sync so the initial limits match + self.on_limits_change() + def deactivate(self): - self.viewer.remove_event_callback(self.on_mouse_or_key_event) - def on_mouse_or_key_event(self, data): - if data['event'] == 'click': - x = data['domain']['x'] - y = data['domain']['y'] - dx = self.viewer.state.x_max - self.viewer.state.x_min - dy = self.viewer.state.y_max - self.viewer.state.y_min - for viewer in self.viewer.session.application.viewers: + self.viewer.state.remove_callback('x_min', self.on_limits_change) + self.viewer.state.remove_callback('x_max', self.on_limits_change) + self.viewer.state.remove_callback('y_min', self.on_limits_change) + self.viewer.state.remove_callback('y_max', self.on_limits_change) + + super().deactivate() + + def on_limits_change(self, *args): + for viewer in self.viewer.session.application.viewers: + if viewer is not self.viewer: with delay_callback(viewer.state, 'x_min', 'x_max', 'y_min', 'y_max'): - viewer.state.x_min = x - dx / 2 - viewer.state.x_max = x + dx / 2 - viewer.state.y_min = y - dy / 2 - viewer.state.y_max = y + dy / 2 + viewer.state.x_min = self.viewer.state.x_min + viewer.state.x_max = self.viewer.state.x_max + viewer.state.y_min = self.viewer.state.y_min + viewer.state.y_max = self.viewer.state.y_max @viewer_tool diff --git a/jdaviz/configs/imviz/plugins/viewers.py b/jdaviz/configs/imviz/plugins/viewers.py index bc981ff8f5..588e30d011 100644 --- a/jdaviz/configs/imviz/plugins/viewers.py +++ b/jdaviz/configs/imviz/plugins/viewers.py @@ -14,8 +14,14 @@ @viewer_registry("imviz-image-viewer", label="Image 2D (Imviz)") class ImvizImageView(BqplotImageView): - tools = ['bqplot:panzoom', 'bqplot:contrastbias', 'bqplot:blinkonce', 'bqplot:rectangle', - 'bqplot:circle', 'bqplot:matchwcs'] + # Whether to inherit tools from glue-jupyter automatically. Set this to + # False to have full control here over which tools are shown in case new + # ones are added in glue-jupyter in future that we don't want here. + inherit_tools = False + + tools = ['bqplot:home', 'bqplot:panzoom', 'bqplot:panzoomwcs', + 'bqplot:contrastbias', 'bqplot:blinkonce', + 'bqplot:rectangle', 'bqplot:circle'] default_class = None def __init__(self, *args, **kwargs): diff --git a/jdaviz/data/icons/pan_wcs.png b/jdaviz/data/icons/pan_wcs.png new file mode 100644 index 0000000000..ad10b9c1ca Binary files /dev/null and b/jdaviz/data/icons/pan_wcs.png differ diff --git a/jdaviz/data/icons/pan_wcs.svg b/jdaviz/data/icons/pan_wcs.svg new file mode 100644 index 0000000000..f8925ef251 --- /dev/null +++ b/jdaviz/data/icons/pan_wcs.svg @@ -0,0 +1,211 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/notebooks/ImvizExample.ipynb b/notebooks/ImvizExample.ipynb index f92088d958..2318be6f5e 100644 --- a/notebooks/ImvizExample.ipynb +++ b/notebooks/ImvizExample.ipynb @@ -207,7 +207,7 @@ "metadata": {}, "outputs": [], "source": [ - "data = imviz.app.get_data_from_viewer('viewer-1', 'gc_2mass_j')" + "data = imviz.app.get_data_from_viewer('viewer-1', 'gc_2mass_j[PRIMARY,1]')" ] }, {