Skip to content

Commit b9891ac

Browse files
authored
Merge pull request astropy#41 from mwcraig/remove-interavtivity-api
Remove interactive marking API
2 parents 65d5550 + f50f364 commit b9891ac

File tree

3 files changed

+4
-161
lines changed

3 files changed

+4
-161
lines changed

src/astro_image_display_api/dummy_viewer.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class ImageViewer:
2828
image_width: int = 0
2929
image_height: int = 0
3030
zoom_level: float = 1
31-
_is_marking: bool = False
3231
stretch_options: tuple = ("linear", "log", "sqrt")
3332
autocut_options: tuple = ("minmax", "zscale", "asinh", "percentile", "histogram")
3433
_cursor: str = ImageViewerInterface.ALLOWED_CURSOR_LOCATIONS[0]
@@ -46,9 +45,6 @@ class ImageViewer:
4645
# Default marker name for marking via API
4746
DEFAULT_MARKER_NAME: str = ImageViewerInterface.DEFAULT_MARKER_NAME
4847

49-
# Default marker name for interactive marking
50-
DEFAULT_INTERACTIVE_MARKER_NAME: str = ImageViewerInterface.DEFAULT_INTERACTIVE_MARKER_NAME
51-
5248
# some internal variable for keeping track of viewer state
5349
_interactive_marker_name: str = ""
5450
_previous_click_center: bool = False
@@ -60,18 +56,12 @@ class ImageViewer:
6056
_center: tuple[float, float] = (0.0, 0.0)
6157

6258
# Some properties where we need to control what happens
63-
@property
64-
def is_marking(self) -> bool:
65-
return self._is_marking
66-
6759
@property
6860
def click_center(self) -> bool:
6961
return self._click_center
7062

7163
@click_center.setter
7264
def click_center(self, value: bool) -> None:
73-
if self.is_marking:
74-
raise ValueError("Cannot set click_center while marking is active.")
7565
self._click_center = value
7666
self._click_drag = not value
7767

@@ -80,8 +70,6 @@ def click_drag(self) -> bool:
8070
return self._click_drag
8171
@click_drag.setter
8272
def click_drag(self, value: bool) -> None:
83-
if self.is_marking:
84-
raise ValueError("Cannot set click_drag while marking is active.")
8573
self._click_drag = value
8674
self._click_center = not value
8775

@@ -198,45 +186,6 @@ def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None:
198186
p.write_text("This is a dummy file. The viewer does not save anything.")
199187

200188
# Marker-related methods
201-
def start_marking(self, marker_name: str | None = None, marker: Any = None) -> None:
202-
"""
203-
Start interactive marking of points on the image.
204-
205-
Parameters
206-
----------
207-
marker_name : str, optional
208-
The name of the marker set to use. If not given, a unique
209-
name will be generated.
210-
"""
211-
self._is_marking = True
212-
self._previous_click_center = self.click_center
213-
self._previous_click_drag = self.click_drag
214-
self._previous_marker = self.marker
215-
self._previous_scroll_pan = self.scroll_pan
216-
self._click_center = False
217-
self._click_drag = False
218-
self.scroll_pan = True
219-
self._interactive_marker_name = marker_name if marker_name else self.DEFAULT_INTERACTIVE_MARKER_NAME
220-
self.marker = marker if marker else self.DEFAULT_INTERACTIVE_MARKER_NAME
221-
222-
def stop_marking(self, clear_markers: bool = False) -> None:
223-
"""
224-
Stop interactive marking of points on the image.
225-
226-
Parameters
227-
----------
228-
clear_markers : bool, optional
229-
If `True`, clear the markers that were created during
230-
interactive marking. Default is `False`.
231-
"""
232-
self._is_marking = False
233-
self.click_center = self._previous_click_center
234-
self.click_drag = self._previous_click_drag
235-
self.scroll_pan = self._previous_scroll_pan
236-
self.marker = self._previous_marker
237-
if clear_markers:
238-
self.remove_markers(self._interactive_marker_name)
239-
240189
def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
241190
skycoord_colname: str = 'coord', use_skycoord: bool = False,
242191
marker_name: str | None = None) -> None:

src/astro_image_display_api/interface_definition.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
ALLOWED_CURSOR_LOCATIONS = ('top', 'bottom', None)
1414

1515
DEFAULT_MARKER_NAME = 'default-marker-name'
16-
DEFAULT_INTERACTIVE_MARKER_NAME = 'interactive-markers'
1716

1817
# List of marker names that are for internal use only
1918
RESERVED_MARKER_SET_NAMES = ('all',)
@@ -34,7 +33,6 @@ class ImageViewerInterface(Protocol):
3433
image_width: int
3534
image_height: int
3635
zoom_level: float
37-
is_marking: bool
3836
stretch_options: tuple
3937
autocut_options: tuple
4038
cursor: str
@@ -52,9 +50,6 @@ class ImageViewerInterface(Protocol):
5250
# Default marker name for marking via API
5351
DEFAULT_MARKER_NAME: str = DEFAULT_MARKER_NAME
5452

55-
# Default marker name for interactive marking
56-
DEFAULT_INTERACTIVE_MARKER_NAME: str = DEFAULT_INTERACTIVE_MARKER_NAME
57-
5853
# The methods, grouped loosely by purpose
5954

6055
# Methods for loading data
@@ -113,37 +108,6 @@ def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None:
113108
"""
114109
raise NotImplementedError
115110

116-
# Marker-related methods
117-
@abstractmethod
118-
def start_marking(self, marker_name: str | None = None, marker: Any = None) -> None:
119-
"""
120-
Start interactive marking of points on the image.
121-
122-
Parameters
123-
----------
124-
marker_name : str, optional
125-
The name of the marker set to use. If not given, a unique
126-
name will be generated.
127-
128-
marker : Any, optional
129-
The marker to use. If not given, a default marker will be
130-
used.
131-
"""
132-
raise NotImplementedError
133-
134-
@abstractmethod
135-
def stop_marking(self, clear_markers: bool = False) -> None:
136-
"""
137-
Stop interactive marking of points on the image.
138-
139-
Parameters
140-
----------
141-
clear_markers : bool, optional
142-
If `True`, clear the markers that were created during
143-
interactive marking. Default is `False`.
144-
"""
145-
raise NotImplementedError
146-
147111
@abstractmethod
148112
def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
149113
skycoord_colname: str = 'coord', use_skycoord: bool = False,

src/astro_image_display_api/widget_api_test.py

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# TODO: How to enable switching out backend and still run the same tests?
2-
import warnings
32

43
import pytest
54

@@ -65,7 +64,6 @@ def _get_marker_names_as_set(self):
6564
def test_default_marker_names(self):
6665
# Check only that default names are set to a non-empty string
6766
assert self.image.DEFAULT_MARKER_NAME
68-
assert self.image.DEFAULT_INTERACTIVE_MARKER_NAME
6967

7068
def test_width_height(self):
7169
assert self.image.image_width == 250
@@ -125,75 +123,15 @@ def test_zoom(self):
125123
self.image.zoom(2)
126124
assert self.image.zoom_level == 6 # 3 x 2
127125

128-
def test_marking_operations(self):
129-
marks = self.image.get_markers(marker_name="all")
130-
self._assert_empty_marker_table(marks)
131-
assert not self.image.is_marking
132-
133-
# Ensure you cannot set it like this.
134-
with pytest.raises(AttributeError):
135-
self.image.is_marking = True
136-
137-
# Setting these to check that start_marking affects them.
138-
self.image.click_center = True # Disables click_drag
139-
assert self.image.click_center
140-
self.image.scroll_pan = False
141-
assert not self.image.scroll_pan
142-
126+
def test_marker_properties(self):
143127
# Set the marker style
144128
marker_style = {'color': 'yellow', 'radius': 10, 'type': 'cross'}
145129
self.image.marker = marker_style
146130
m_str = str(self.image.marker)
147131
for key in marker_style.keys():
148132
assert key in m_str
149133

150-
self.image.start_marking(marker_name='markymark', marker=marker_style)
151-
assert self.image.is_marking
152-
assert self.image.marker == marker_style
153-
assert not self.image.click_center
154-
assert not self.image.click_drag
155-
156-
# scroll_pan better activate when marking otherwise there is
157-
# no way to pan while interactively marking
158-
assert self.image.scroll_pan
159-
160-
# Make sure that when we stop_marking we get our old controls back.
161-
self.image.stop_marking()
162-
assert self.image.click_center
163-
assert not self.image.click_drag
164-
assert not self.image.scroll_pan
165-
166-
# Make sure no warning is issued when trying to retrieve markers
167-
# with a name that does not exist.
168-
with warnings.catch_warnings():
169-
warnings.simplefilter("error")
170-
t = self.image.get_markers(marker_name='markymark')
171-
172-
self._assert_empty_marker_table(t)
173-
174-
self.image.click_drag = True
175-
self.image.start_marking()
176-
assert not self.image.click_drag
177-
178-
# Add a marker to the interactive marking table
179-
self.image.add_markers(
180-
Table(data=[[50], [50]], names=['x', 'y'], dtype=('float', 'float')),
181-
marker_name=self.image.DEFAULT_INTERACTIVE_MARKER_NAME,
182-
)
183-
assert self._get_marker_names_as_set() == set([self.image.DEFAULT_INTERACTIVE_MARKER_NAME])
184-
185-
# Clear markers to not pollute other tests.
186-
self.image.stop_marking(clear_markers=True)
187-
188-
assert self.image.is_marking is False
189-
self._assert_empty_marker_table(self.image.get_markers(marker_name="all"))
190-
191-
# Hate this, should add to public API
192-
marknames = self._get_marker_names_as_set()
193-
assert len(marknames) == 0
194-
195-
# Make sure that click_drag is restored as expected
196-
assert self.image.click_drag
134+
# TODO: add test that checks that retrieving markers with an unknown name issues no error
197135

198136
def test_add_markers(self):
199137
original_marker_name = self.image.DEFAULT_MARKER_NAME
@@ -391,29 +329,21 @@ def test_click_drag(self):
391329

392330
# If is_marking is true then trying to enable click_drag should fail
393331
self.image.click_drag = False
394-
self.image.start_marking()
395-
with pytest.raises(ValueError, match=r'([Ii]nteractive marking)|(while in marking mode)|(while marking is active)'):
396-
self.image.click_drag = True
397-
self.image.stop_marking()
398332

399333
def test_click_center(self):
400334
# Set this to ensure that click_center turns it off
401335
self.image.click_drag = True
402336

403337
# Make sure that setting click_center to False does not turn off
404-
# click_draf.
338+
# click_drag.
405339
self.image.click_center = False
406340
assert self.image.click_drag
407341

408342
self.image.click_center = True
409343
assert not self.image.click_drag
410344

411345
self.image.click_center = False
412-
# If is_marking is true then trying to enable click_center should fail
413-
self.image.start_marking()
414-
with pytest.raises(ValueError, match=r'([Ii]nteractive marking)|(while marking is active)'):
415-
self.image.click_center = True
416-
self.image.stop_marking()
346+
417347

418348
def test_scroll_pan(self):
419349
# Make sure scroll_pan is actually settable

0 commit comments

Comments
 (0)