Improve some attribute/method names

This commit is contained in:
Julian Stirling 2026-05-07 09:47:55 +01:00
parent 1b69b19ec3
commit c7bb3e3c11
4 changed files with 18 additions and 16 deletions

View file

@ -15,12 +15,12 @@ class OFMThing(lt.Thing):
_data_dir: Optional[str] = None _data_dir: Optional[str] = None
_show_in_gallery: bool = False _show_data_in_gallery: bool = False
@property @property
def show_in_gallery(self) -> bool: def show_data_in_gallery(self) -> bool:
"""Whether to show in the Gallery.""" """Whether to show in the Gallery."""
return self._show_in_gallery return self._show_data_in_gallery
def __enter__(self) -> Self: def __enter__(self) -> Self:
"""Set the data directory when the Thing is entered.""" """Set the data directory when the Thing is entered."""

View file

@ -27,14 +27,14 @@ class GalleryCompatibleThing(Protocol):
_thing_server_interface: lt.ThingServerInterface _thing_server_interface: lt.ThingServerInterface
# Ensure it is an OFMThing: # Ensure it is an OFMThing:
show_in_gallery: bool show_data_in_gallery: bool
gallery_data_name: str gallery_data_name: str
gallery_data_schema: type[BaseModel] gallery_data_schema: type[BaseModel]
# Ignore D102: No docstrings for the protocol. # 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): class GalleryThing(lt.Thing):
@ -66,7 +66,7 @@ class GalleryThing(lt.Thing):
gallery_providers = { gallery_providers = {
name: thing name: thing
for name, thing in self.all_ofm_things.items() 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 # cache initial list of keys as it may change in the loop
keys = list(gallery_providers.keys()) keys = list(gallery_providers.keys())
@ -95,5 +95,5 @@ class GalleryThing(lt.Thing):
""" """
data_list = [] data_list = []
for thing in self.gallery_providing_things.values(): 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 return data_list

View file

@ -167,7 +167,7 @@ class SmartScanThing(OFMThing):
""" """
# Register with gallery. # Register with gallery.
_show_in_gallery = True _show_data_in_gallery = True
@property @property
def gallery_data_name(self) -> str: def gallery_data_name(self) -> str:
@ -179,7 +179,7 @@ class SmartScanThing(OFMThing):
"""The schema (BaseModel) for passing data to the gallery.""" """The schema (BaseModel) for passing data to the gallery."""
return scan_directories.ScanInfo 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. """Return all the information from the scan directories.
It is preferable to use the method rather than calling It is preferable to use the method rather than calling
@ -622,8 +622,8 @@ class SmartScanThing(OFMThing):
@lt.action @lt.action
def purge_empty_scans(self) -> None: def purge_empty_scans(self) -> None:
"""Delete all scan folders containing no images at the top level.""" """Delete all scan folders containing no images at the top level."""
# JSON is ignored as it's created before any images are captured # Use the scan list (the data read by the gallery) to check for empty scans.
for scan_info in self.get_gallery_data(): for scan_info in self.get_data_for_gallery():
if scan_info.number_of_images == 0: if scan_info.number_of_images == 0:
self._delete_scan(scan_info.name) self._delete_scan(scan_info.name)
@ -738,6 +738,8 @@ class SmartScanThing(OFMThing):
""" """
if self._scan_lock.locked(): if self._scan_lock.locked():
raise RuntimeError("Can't stitch previous scans while a scan is ongoing") 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: if scan.dzi is None:
self.stitch_scan(scan_name=scan.name) self.stitch_scan(scan_name=scan.name)

View file

@ -32,7 +32,7 @@ class MinimalGalleryClass:
gallery_data_schema: type[BaseModel] = MockGalleryData 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 a list of Mock Gallery Data."""
return [MockGalleryData(mock="mock", foobar="foobar")] return [MockGalleryData(mock="mock", foobar="foobar")]
@ -43,7 +43,7 @@ class MinimalGallerySource(OFMThing, MinimalGalleryClass):
Mixes MinimalGalleryClass into OFMThing to be recognised by the protocol. Mixes MinimalGalleryClass into OFMThing to be recognised by the protocol.
""" """
show_in_gallery = True show_data_in_gallery = True
class BadGallerySource(OFMThing): class BadGallerySource(OFMThing):
@ -52,11 +52,11 @@ class BadGallerySource(OFMThing):
Shouldn't match the protocol as ``gallery_data_name`` is missing. 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 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 a list of Mock Gallery Data."""
return [MockGalleryData(mock="mock", foobar="foobar")] return [MockGalleryData(mock="mock", foobar="foobar")]