Skip to content

Commit 64aa05f

Browse files
committed
Remove interactive marking API
1 parent 65d5550 commit 64aa05f

File tree

3 files changed

+2
-149
lines changed

3 files changed

+2
-149
lines changed

src/astro_image_display_api/dummy_viewer.py

Lines changed: 0 additions & 48 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]
@@ -60,18 +59,12 @@ class ImageViewer:
6059
_center: tuple[float, float] = (0.0, 0.0)
6160

6261
# Some properties where we need to control what happens
63-
@property
64-
def is_marking(self) -> bool:
65-
return self._is_marking
66-
6762
@property
6863
def click_center(self) -> bool:
6964
return self._click_center
7065

7166
@click_center.setter
7267
def click_center(self, value: bool) -> None:
73-
if self.is_marking:
74-
raise ValueError("Cannot set click_center while marking is active.")
7568
self._click_center = value
7669
self._click_drag = not value
7770

@@ -80,8 +73,6 @@ def click_drag(self) -> bool:
8073
return self._click_drag
8174
@click_drag.setter
8275
def click_drag(self, value: bool) -> None:
83-
if self.is_marking:
84-
raise ValueError("Cannot set click_drag while marking is active.")
8576
self._click_drag = value
8677
self._click_center = not value
8778

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

200191
# 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-
240192
def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
241193
skycoord_colname: str = 'coord', use_skycoord: bool = False,
242194
marker_name: str | None = None) -> None:

src/astro_image_display_api/interface_definition.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class ImageViewerInterface(Protocol):
3434
image_width: int
3535
image_height: int
3636
zoom_level: float
37-
is_marking: bool
3837
stretch_options: tuple
3938
autocut_options: tuple
4039
cursor: str
@@ -113,37 +112,6 @@ def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None:
113112
"""
114113
raise NotImplementedError
115114

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-
147115
@abstractmethod
148116
def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
149117
skycoord_colname: str = 'coord', use_skycoord: bool = False,

src/astro_image_display_api/widget_api_test.py

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -125,75 +125,8 @@ def test_zoom(self):
125125
self.image.zoom(2)
126126
assert self.image.zoom_level == 6 # 3 x 2
127127

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-
143-
# Set the marker style
144-
marker_style = {'color': 'yellow', 'radius': 10, 'type': 'cross'}
145-
self.image.marker = marker_style
146-
m_str = str(self.image.marker)
147-
for key in marker_style.keys():
148-
assert key in m_str
149-
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
128+
# TODO: add test of marker properties
129+
# TODO: add test that checks that retrieving markers with an unknown name issues no error
197130

198131
def test_add_markers(self):
199132
original_marker_name = self.image.DEFAULT_MARKER_NAME

0 commit comments

Comments
 (0)