Skip to content

Commit f10e03b

Browse files
committed
Initial draft on interface definition
1 parent c594308 commit f10e03b

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from typing import Protocol, runtime_checkable, Any
2+
from abc import abstractmethod
3+
4+
5+
@runtime_checkable
6+
class ImageViewerInterface(Protocol):
7+
# This are attributes, not methods. The type annotations are there
8+
# to make sure Protocol knows they are attributes. Python does not
9+
# do any checking at all of these types.
10+
click_center: bool
11+
click_drag: bool
12+
scroll_pan: bool
13+
image_width: int
14+
image_height: int
15+
zoom_level: float
16+
marker: Any
17+
cuts: Any
18+
stretch: str
19+
# viewer: Any
20+
21+
# The methods, grouped loosely by purpose
22+
23+
# Methods for loading data
24+
@abstractmethod
25+
def load_fits(self, file):
26+
raise NotImplementedError
27+
28+
@abstractmethod
29+
def load_array(self, array):
30+
raise NotImplementedError
31+
32+
@abstractmethod
33+
def load_nddata(self, data):
34+
raise NotImplementedError
35+
36+
# Saving contents of the view and accessing the view
37+
@abstractmethod
38+
def save(self, filename):
39+
raise NotImplementedError
40+
41+
# Marker-related methods
42+
@abstractmethod
43+
def start_marking(self):
44+
raise NotImplementedError
45+
46+
@abstractmethod
47+
def stop_marking(self):
48+
raise NotImplementedError
49+
50+
@abstractmethod
51+
def add_markers(self):
52+
raise NotImplementedError
53+
54+
@abstractmethod
55+
def get_markers(self):
56+
raise NotImplementedError
57+
58+
@abstractmethod
59+
def remove_markers(self):
60+
raise NotImplementedError
61+
62+
# @abstractmethod
63+
# def get_all_markers(self):
64+
# raise NotImplementedError
65+
66+
# @abstractmethod
67+
# def get_markers_by_name(self, marker_name=None):
68+
# raise NotImplementedError
69+
70+
# Methods that modify the view
71+
@abstractmethod
72+
def center_on(self):
73+
raise NotImplementedError
74+
75+
@abstractmethod
76+
def offset_to(self):
77+
raise NotImplementedError
78+
79+
@abstractmethod
80+
def zoom(self):
81+
raise NotImplementedError

astrowidgets/tests/test_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
from ginga.ColorDist import ColorDistBase
1212

13-
from ..core import ImageWidget, ALLOWED_CURSOR_LOCATIONS
13+
from astrowidgets.core import ImageWidget, ALLOWED_CURSOR_LOCATIONS
14+
from astrowidgets.interface_definition import ImageViewerInterface
15+
16+
17+
def test_consistent_interface():
18+
iw = ImageWidget()
19+
assert isinstance(iw, ImageViewerInterface)
1420

1521

1622
def test_load_fits():

0 commit comments

Comments
 (0)