Skeleton for autostorage extension
This commit is contained in:
parent
356ff3336b
commit
7209700343
3 changed files with 40 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import traceback
|
||||||
from .autofocus import autofocus_extension_v2
|
from .autofocus import autofocus_extension_v2
|
||||||
from .scan import scan_extension_v2
|
from .scan import scan_extension_v2
|
||||||
from .zip_builder import zip_extension_v2
|
from .zip_builder import zip_extension_v2
|
||||||
|
from .autostorage import autostorage_extension_v2
|
||||||
|
|
||||||
# "Gracefully" handle cases where picamera cannot be imported (eg test server)
|
# "Gracefully" handle cases where picamera cannot be imported (eg test server)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
37
openflexure_microscope/api/default_extensions/autostorage.py
Normal file
37
openflexure_microscope/api/default_extensions/autostorage.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
from labthings.server.extensions import BaseExtension
|
||||||
|
from openflexure_microscope.paths import settings_file_path
|
||||||
|
from openflexure_microscope.config import OpenflexureSettingsFile
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
AS_SETTINGS_PATH = settings_file_path("autostorage_settings.json")
|
||||||
|
|
||||||
|
|
||||||
|
class AutostorageExtension(BaseExtension):
|
||||||
|
def __init__(self):
|
||||||
|
BaseExtension.__init__(
|
||||||
|
self,
|
||||||
|
"org.openflexure.autostorage",
|
||||||
|
version="2.0.0-beta.1",
|
||||||
|
description="Handle switching capture storage devices",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.settings = OpenflexureSettingsFile(
|
||||||
|
AS_SETTINGS_PATH, defaults={"preferred": None}
|
||||||
|
)
|
||||||
|
|
||||||
|
# We'll store a reference to a camera object, who's capture paths will be modified
|
||||||
|
self.camera = None
|
||||||
|
|
||||||
|
# Register the on_microscope function to run when the microscope is attached
|
||||||
|
self.on_component("org.openflexure.microscope", self.on_microscope)
|
||||||
|
|
||||||
|
def on_microscope(self, microscope_obj):
|
||||||
|
"""Function to automatically call when the parent LabThing has a microscope attached."""
|
||||||
|
logging.debug(f"Autostorage extension found microscope {microscope_obj}")
|
||||||
|
if hasattr(microscope_obj, "camera"):
|
||||||
|
self.camera = microscope_obj.camera
|
||||||
|
logging.debug(f"Autostorage extension bound to camera {self.camera}")
|
||||||
|
|
||||||
|
|
||||||
|
autostorage_extension_v2 = AutostorageExtension()
|
||||||
|
|
@ -32,7 +32,8 @@ class OpenflexureSettingsFile:
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
# Initialise basic config file with defaults if it doesn't exist
|
# Initialise basic config file with defaults if it doesn't exist
|
||||||
initialise_file(self.path, populate=defaults)
|
defaults_str = json.dumps(defaults, cls=JSONEncoder, indent=2, sort_keys=True)
|
||||||
|
initialise_file(self.path, populate=defaults_str)
|
||||||
|
|
||||||
def load(self) -> dict:
|
def load(self) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue