Create basic gallery class that finds Things that want to show data

This commit is contained in:
Julian Stirling 2026-05-06 10:05:34 +01:00
parent 964a907edc
commit 93d7d75b0d
9 changed files with 97 additions and 35 deletions

View file

@ -15,6 +15,13 @@ class OFMThing(lt.Thing):
_data_dir: Optional[str] = None
_show_in_gallery: bool = False
@property
def show_in_gallery(self) -> bool:
"""Whether to show in the Gallery."""
return self._show_in_gallery
def __enter__(self) -> Self:
"""Set the data directory when the Thing is entered."""
# Note that the `application_config` was already validated when the

View file

@ -25,6 +25,7 @@ from pydantic import BaseModel, Field
import labthings_fastapi as lt
from labthings_fastapi.types.numpy import NDArray
from openflexure_microscope_server.things import OFMThing
from openflexure_microscope_server.things.background_detect import (
BackgroundDetectAlgorithm,
)
@ -164,7 +165,7 @@ class CameraMemoryBuffer:
del self._storage[key]
class BaseCamera(lt.Thing):
class BaseCamera(OFMThing):
"""The base class for all cameras. All cameras must directly inherit from this class.
The connection to the camera hardware should be added to the ``__enter__`` method not

View file

@ -0,0 +1,31 @@
"""Server-side gallery functionality.
The types of data that are captured and how they display in the gallery are defined by
the Things that capture the Data. This thing just provides a unified way for the gallery
front end to access the data.
"""
from typing import Mapping, Optional
import labthings_fastapi as lt
from openflexure_microscope_server.things import OFMThing
class GalleryThing(lt.Thing):
"""A Thing for communicating with the front end gallery."""
all_ofm_things: Mapping[str, OFMThing] = lt.thing_slot()
_gallery_providing_things: Optional[Mapping[str, OFMThing]] = None
@property
def gallery_providing_things(self) -> Mapping[str, OFMThing]:
"""All Things that provide data to the gallery."""
if self._gallery_providing_things is None:
self._gallery_providing_things = {
name: thing
for name, thing in self.all_ofm_things.items()
if thing.show_in_gallery
}
return self._gallery_providing_things

View file

@ -176,6 +176,9 @@ class SmartScanThing(OFMThing):
In this case it doesn't need to do anything.
"""
# Register with gallery.
_show_in_gallery = True
# Note that the default detector name is set at init. This is over written if
# setting is loaded from disk.
@lt.setting