Skip to content

Commit feadcb9

Browse files
authored
Merge pull request #1558 from pllim/blink-back-to-the-future
Allow Shift+b to blink backwards
2 parents 9bf654c + a3a6518 commit feadcb9

File tree

6 files changed

+54
-11
lines changed

6 files changed

+54
-11
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ Imviz
1818

1919
- Auto-populate simple aperture photometry values if JWST data is loaded into viewer. [#1549]
2020

21+
- Pressing Shift+b now blinks backwards. Right-clicking on the image while Blink tool
22+
is active on the toolbar also blinks backwards. [#1558]
23+
2124
Mosviz
2225
^^^^^^
26+
2327
- NIRISS parser now sorts FITS files by header instead of file name. [#819]
2428

2529
Specviz

docs/imviz/displayimages.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ Blinking
156156
Blinking is an Imviz-specific functionality that allows a user to quickly switch
157157
between viewing two or more images, as long as they are linked (see :ref:`imviz_pan_zoom` for
158158
more on linking behavior). This can be done by selecting the |icon-blink| icon and
159-
then clicking on the image. You can also blink by pressing the "b" key on your
160-
keyboard while moused over the image.
159+
then left-clicking on the image to blink forward; right-clicking would blink backwards.
160+
161+
You can also blink forward by pressing the "b" key on your keyboard while moused over the image.
162+
If you press Shift + "b" ("B"), you may blink backwards.
161163

162164
From the API
163165
------------
@@ -167,6 +169,10 @@ From the API within the Jupyter notebook::
167169
viewer = imviz.default_viewer
168170
viewer.blink_once()
169171

172+
And to blink backwards::
173+
174+
viewer.blink_once(reversed=True)
175+
170176
Contrast/Bias
171177
=============
172178

jdaviz/configs/imviz/plugins/tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ class BlinkOnce(CheckableTool):
102102
icon = os.path.join(ICON_DIR, 'blink.svg')
103103
tool_id = 'jdaviz:blinkonce'
104104
action_text = 'Go to next image'
105-
tool_tip = ('Click on the viewer to display the next image, '
106-
'or you can also press the "b" key anytime')
105+
tool_tip = ('Click on the viewer or press "b" to display the next image, '
106+
'or right-click or press "B" to display the previous')
107107

108108
def activate(self):
109-
self.viewer.add_event_callback(self.on_click, events=['click'])
109+
self.viewer.add_event_callback(self.on_click, events=['click', 'contextmenu'])
110110

111111
def deactivate(self):
112112
self.viewer.remove_event_callback(self.on_click)
113113

114114
def on_click(self, data):
115-
self.viewer.blink_once()
115+
self.viewer.blink_once(reversed=data['event']=='contextmenu') # noqa: E225
116116

117117
# Also update the coordinates display.
118118
data['event'] = 'mousemove'

jdaviz/configs/imviz/plugins/viewers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ def on_mouse_or_key_event(self, data):
151151
elif data['event'] == 'keydown':
152152
key_pressed = data['key']
153153

154-
if key_pressed == 'b':
155-
self.blink_once()
154+
if key_pressed in ('b', 'B'):
155+
self.blink_once(reversed=key_pressed=='B') # noqa: E225
156156

157157
# Also update the coordinates display.
158158
data['event'] = 'mousemove'
@@ -171,7 +171,7 @@ def on_mouse_or_key_event(self, data):
171171
self.line_profile_xy.selected_viewer = self.reference_id
172172
self.line_profile_xy.vue_draw_plot()
173173

174-
def blink_once(self):
174+
def blink_once(self, reversed=False):
175175
# Simple blinking of images - this will make it so that only one
176176
# layer is visible at a time and cycles through the layers.
177177

@@ -198,7 +198,11 @@ def blink_once(self):
198198
color='warning', sender=self)
199199
self.session.hub.broadcast(msg)
200200
elif n_visible > 0:
201-
next_layer = valid[(valid.index(visible[-1]) + 1) % n_layers]
201+
if not reversed:
202+
delta = 1
203+
else:
204+
delta = -1
205+
next_layer = valid[(valid.index(visible[-1]) + delta) % n_layers]
202206
self.state.layers[next_layer].visible = True
203207

204208
for ilayer in (set(valid) - set([next_layer])):

jdaviz/configs/imviz/tests/test_linking.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def test_wcslink_affine_with_extras(self):
151151

152152
# blink image through clicking with blink tool
153153
self.viewer.toolbar_nested.active_tool_id = 'jdaviz:blinkonce'
154-
self.viewer.toolbar_nested.active_tool.on_click({'domain': {'x': 0, 'y': 0}})
154+
self.viewer.toolbar_nested.active_tool.on_click(
155+
{'event': 'click', 'domain': {'x': 0, 'y': 0}})
155156
assert self.viewer.label_mouseover.pixel == 'x=00.0 y=00.0'
156157
assert self.viewer.label_mouseover.value == '+1.00000e+00 '
157158
assert self.viewer.label_mouseover.world_ra_deg == '337.5202808000'

jdaviz/configs/imviz/tests/test_tools.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as np
2+
13
from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_WCS
24

35

@@ -32,3 +34,29 @@ def test_zoom_tools(self):
3234
v.toolbar_nested.tools['jdaviz:prevzoom'].activate()
3335
assert (v.state.x_min, v.state.x_max, v.state.y_min, v.state.y_max) == (1, 8, 1, 8)
3436
assert (v2.state.x_min, v2.state.x_max, v2.state.y_min, v2.state.y_max) == (1, 8, 1, 8)
37+
38+
39+
def test_blink(imviz_helper):
40+
viewer = imviz_helper.default_viewer
41+
42+
for i in range(3):
43+
imviz_helper.load_data(np.zeros((2, 2)) + i, data_label=f'image_{i}')
44+
45+
# Last loaded is shown first. So, blinking will take you back to the first one.
46+
# Blink forward. The event will also initialize viewer.label_mouseover .
47+
viewer.on_mouse_or_key_event({'event': 'keydown', 'key': 'b', 'domain': {'x': 0, 'y': 0}})
48+
assert viewer.label_mouseover.value == '+0.00000e+00 '
49+
50+
# Blink forward again and update coordinates info panel.
51+
viewer.blink_once()
52+
viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
53+
assert viewer.label_mouseover.value == '+1.00000e+00 '
54+
55+
# Blink backward.
56+
viewer.blink_once(reversed=True)
57+
viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
58+
assert viewer.label_mouseover.value == '+0.00000e+00 '
59+
60+
# Blink backward again.
61+
viewer.on_mouse_or_key_event({'event': 'keydown', 'key': 'B', 'domain': {'x': 0, 'y': 0}})
62+
assert viewer.label_mouseover.value == '+2.00000e+00 '

0 commit comments

Comments
 (0)