diff --git a/src/openflexure_microscope_server/things/camera/__init__.py b/src/openflexure_microscope_server/things/camera/__init__.py index 8a2644f1..5a39f11c 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -295,11 +295,6 @@ class BaseCamera(OFMThing, ABC): # Register with gallery. _show_data_in_gallery = True - @property - def gallery_data_name(self) -> str: - """Name under which data shows up in gallery.""" - return "Captures" - @property def gallery_data_schema(self) -> type[CaptureInfo]: """The schema (BaseModel) for passing data to the gallery.""" diff --git a/src/openflexure_microscope_server/things/gallery.py b/src/openflexure_microscope_server/things/gallery.py index 2f701c73..2b1fd4ef 100644 --- a/src/openflexure_microscope_server/things/gallery.py +++ b/src/openflexure_microscope_server/things/gallery.py @@ -23,14 +23,14 @@ class GalleryCompatibleThing(Protocol): be picked up, but may throw an error when used. """ + name: str + # Ensure it is a Thing: _thing_server_interface: lt.ThingServerInterface # Ensure it is an OFMThing: show_data_in_gallery: bool - gallery_data_name: str - gallery_data_schema: type[BaseModel] # Ignore D102: No docstrings for the protocol. @@ -45,6 +45,7 @@ class GalleryThing(lt.Thing): all_ofm_things: Mapping[str, OFMThing] = lt.thing_slot() _gallery_providing_things: Optional[Mapping[str, GalleryCompatibleThing]] = None + _card_types: Optional[Mapping[str, GalleryCompatibleThing]] = None @property def gallery_providing_things(self) -> Mapping[str, GalleryCompatibleThing]: @@ -58,6 +59,7 @@ class GalleryThing(lt.Thing): def __enter__(self) -> Self: """Check for all gallery providing things on server startup.""" self._set_gallery_providers() + self._set_card_types() return self def _set_gallery_providers(self) -> None: @@ -86,6 +88,29 @@ class GalleryThing(lt.Thing): Mapping[str, GalleryCompatibleThing], gallery_providers ) + def _set_card_types(self) -> None: + """Find the card types from each provider.""" + card_types: list[str] = [] + for thing in self.gallery_providing_things.values(): + card_schema = thing.gallery_data_schema.schema() + props = card_schema["properties"] + if "card_type" not in props or "const" not in props["card_type"]: + raise TypeError( + f"Gallery data card for {thing.name} doesn't have a staticcard_type" + ) + card_type = props["card_type"]["const"] + if card_type not in card_types: + card_types.append(card_type) + + self._card_types = card_types + + @lt.property + def card_types(self) -> list[str]: + """Names for the card types in the gallery.""" + if self._card_types is None: + raise RuntimeError("Cannot access card_types before server has started.") + return self._card_types + @lt.property def list_data(self) -> list[dict[str, Any]]: """List the data from all registered things. diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index e51c84eb..d22cb55f 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -170,11 +170,6 @@ class SmartScanThing(OFMThing): # Register with gallery. _show_data_in_gallery = True - @property - def gallery_data_name(self) -> str: - """Name under which data shows up in gallery.""" - return "Scans" - @property def gallery_data_schema(self) -> type[scan_directories.ScanInfo]: """The schema (BaseModel) for passing data to the gallery.""" diff --git a/tests/unit_tests/test_gallery.py b/tests/unit_tests/test_gallery.py index 7baf8f2f..eedc3fc6 100644 --- a/tests/unit_tests/test_gallery.py +++ b/tests/unit_tests/test_gallery.py @@ -42,8 +42,6 @@ class MinimalGalleryClass: This should fail the protocol check as it is not an OFMThing """ - gallery_data_name: str = "Mock" - gallery_data_schema: type[BaseModel] = MockGalleryData def get_data_for_gallery(self) -> list[BaseModel]: @@ -66,13 +64,11 @@ class MinimalGallerySource(OFMThing, MinimalGalleryClass): class BadGallerySource(OFMThing): """An OFMThing that almost defines enough to show in the gallery. - Shouldn't match the protocol as ``gallery_data_name`` is missing. + Shouldn't match the protocol as ``gallery_data_schema`` is missing. """ show_data_in_gallery = True - gallery_data_schema: type[BaseModel] = MockGalleryData - def get_data_for_gallery(self) -> list[BaseModel]: """Return a list of Mock Gallery Data.""" return [MockGalleryData(mock="mock", foobar="foobar")] diff --git a/tests/unit_tests/test_simulated_camera.py b/tests/unit_tests/test_simulated_camera.py index 0be10c6d..cc8f5bba 100644 --- a/tests/unit_tests/test_simulated_camera.py +++ b/tests/unit_tests/test_simulated_camera.py @@ -297,7 +297,6 @@ def test_gallery_responses(camera, mocker, caplog): with tempfile.TemporaryDirectory() as tmpdir, caplog.at_level(logging.INFO): camera._data_dir = tmpdir - assert camera.gallery_data_name == "Captures" assert camera.gallery_data_schema == CaptureInfo # When we start there are no captures diff --git a/webapp/src/components/tabContentComponents/galleryContent.vue b/webapp/src/components/tabContentComponents/galleryContent.vue index 106d17f3..5bef578c 100644 --- a/webapp/src/components/tabContentComponents/galleryContent.vue +++ b/webapp/src/components/tabContentComponents/galleryContent.vue @@ -7,8 +7,8 @@
There is no captured data to show..
+There is no captured data to show.