From c7bb3e3c11f7e7946826d801f815de80742797c5 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Thu, 7 May 2026 09:47:55 +0100 Subject: [PATCH] Improve some attribute/method names --- src/openflexure_microscope_server/things/__init__.py | 6 +++--- src/openflexure_microscope_server/things/gallery.py | 8 ++++---- .../things/smart_scan.py | 12 +++++++----- tests/unit_tests/test_gallery.py | 8 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/openflexure_microscope_server/things/__init__.py b/src/openflexure_microscope_server/things/__init__.py index 896c2e70..b35f1fdf 100644 --- a/src/openflexure_microscope_server/things/__init__.py +++ b/src/openflexure_microscope_server/things/__init__.py @@ -15,12 +15,12 @@ class OFMThing(lt.Thing): _data_dir: Optional[str] = None - _show_in_gallery: bool = False + _show_data_in_gallery: bool = False @property - def show_in_gallery(self) -> bool: + def show_data_in_gallery(self) -> bool: """Whether to show in the Gallery.""" - return self._show_in_gallery + return self._show_data_in_gallery def __enter__(self) -> Self: """Set the data directory when the Thing is entered.""" diff --git a/src/openflexure_microscope_server/things/gallery.py b/src/openflexure_microscope_server/things/gallery.py index cfb73ae1..88a6eaed 100644 --- a/src/openflexure_microscope_server/things/gallery.py +++ b/src/openflexure_microscope_server/things/gallery.py @@ -27,14 +27,14 @@ class GalleryCompatibleThing(Protocol): _thing_server_interface: lt.ThingServerInterface # Ensure it is an OFMThing: - show_in_gallery: bool + show_data_in_gallery: bool gallery_data_name: str gallery_data_schema: type[BaseModel] # Ignore D102: No docstrings for the protocol. - def get_gallery_data(self) -> list[BaseModel]: ... # noqa: D102 + def get_data_for_gallery(self) -> list[BaseModel]: ... # noqa: D102 class GalleryThing(lt.Thing): @@ -66,7 +66,7 @@ class GalleryThing(lt.Thing): gallery_providers = { name: thing for name, thing in self.all_ofm_things.items() - if thing.show_in_gallery + if thing.show_data_in_gallery } # cache initial list of keys as it may change in the loop keys = list(gallery_providers.keys()) @@ -95,5 +95,5 @@ class GalleryThing(lt.Thing): """ data_list = [] for thing in self.gallery_providing_things.values(): - data_list += [model.model_dump() for model in thing.get_gallery_data()] + data_list += [model.model_dump() for model in thing.get_data_for_gallery()] return data_list diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 5b4c8f3a..5b2e54af 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -167,7 +167,7 @@ class SmartScanThing(OFMThing): """ # Register with gallery. - _show_in_gallery = True + _show_data_in_gallery = True @property def gallery_data_name(self) -> str: @@ -179,7 +179,7 @@ class SmartScanThing(OFMThing): """The schema (BaseModel) for passing data to the gallery.""" return scan_directories.ScanInfo - def get_gallery_data(self) -> list[scan_directories.ScanInfo]: + def get_data_for_gallery(self) -> list[scan_directories.ScanInfo]: """Return all the information from the scan directories. It is preferable to use the method rather than calling @@ -622,8 +622,8 @@ class SmartScanThing(OFMThing): @lt.action def purge_empty_scans(self) -> None: """Delete all scan folders containing no images at the top level.""" - # JSON is ignored as it's created before any images are captured - for scan_info in self.get_gallery_data(): + # Use the scan list (the data read by the gallery) to check for empty scans. + for scan_info in self.get_data_for_gallery(): if scan_info.number_of_images == 0: self._delete_scan(scan_info.name) @@ -738,6 +738,8 @@ class SmartScanThing(OFMThing): """ if self._scan_lock.locked(): raise RuntimeError("Can't stitch previous scans while a scan is ongoing") - for scan in self.get_gallery_data(): + # Use the scan list (the data read by the gallery) to find any scans that + # need stitching. + for scan in self.get_data_for_gallery(): if scan.dzi is None: self.stitch_scan(scan_name=scan.name) diff --git a/tests/unit_tests/test_gallery.py b/tests/unit_tests/test_gallery.py index 043b03a3..10bc246d 100644 --- a/tests/unit_tests/test_gallery.py +++ b/tests/unit_tests/test_gallery.py @@ -32,7 +32,7 @@ class MinimalGalleryClass: gallery_data_schema: type[BaseModel] = MockGalleryData - def get_gallery_data(self) -> list[BaseModel]: + def get_data_for_gallery(self) -> list[BaseModel]: """Return a list of Mock Gallery Data.""" return [MockGalleryData(mock="mock", foobar="foobar")] @@ -43,7 +43,7 @@ class MinimalGallerySource(OFMThing, MinimalGalleryClass): Mixes MinimalGalleryClass into OFMThing to be recognised by the protocol. """ - show_in_gallery = True + show_data_in_gallery = True class BadGallerySource(OFMThing): @@ -52,11 +52,11 @@ class BadGallerySource(OFMThing): Shouldn't match the protocol as ``gallery_data_name`` is missing. """ - show_in_gallery = True + show_data_in_gallery = True gallery_data_schema: type[BaseModel] = MockGalleryData - def get_gallery_data(self) -> list[BaseModel]: + def get_data_for_gallery(self) -> list[BaseModel]: """Return a list of Mock Gallery Data.""" return [MockGalleryData(mock="mock", foobar="foobar")]