diff --git a/openflexure_microscope/api/default_extensions/autofocus.py b/openflexure_microscope/api/default_extensions/autofocus.py index 85c35e40..3c37caf0 100644 --- a/openflexure_microscope/api/default_extensions/autofocus.py +++ b/openflexure_microscope/api/default_extensions/autofocus.py @@ -1,4 +1,4 @@ -from openflexure_microscope.common.flask_labthings.find import find_device +from openflexure_microscope.common.flask_labthings.find import find_component from openflexure_microscope.common.flask_labthings.extensions import BaseExtension from openflexure_microscope.common.flask_labthings.resource import Resource from openflexure_microscope.common.flask_labthings.decorators import ( @@ -294,7 +294,7 @@ def fast_up_down_up_autofocus( class MeasureSharpnessAPI(Resource): def post(self): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") if not microscope: abort(503, "No microscope connected. Unable to measure sharpness.") @@ -310,7 +310,7 @@ class AutofocusAPI(Resource): def post(self): payload = JsonResponse(request) - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") if not microscope: abort(503, "No microscope connected. Unable to autofocus.") @@ -337,7 +337,7 @@ class FastAutofocusAPI(Resource): def post(self): payload = JsonResponse(request) - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") if not microscope: abort(503, "No microscope connected. Unable to autofocus.") diff --git a/openflexure_microscope/api/default_extensions/scan.py b/openflexure_microscope/api/default_extensions/scan.py index 1ba66b4b..5dd87446 100644 --- a/openflexure_microscope/api/default_extensions/scan.py +++ b/openflexure_microscope/api/default_extensions/scan.py @@ -6,7 +6,7 @@ from functools import reduce from openflexure_microscope.camera.base import generate_basename from openflexure_microscope.common.flask_labthings.find import ( - find_device, + find_component, find_extension, ) from openflexure_microscope.common.flask_labthings.extensions import BaseExtension @@ -360,7 +360,7 @@ class TileScanAPI(Resource): ) @marshal_task def post(self, args): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") if not microscope: abort(503, "No microscope connected. Unable to autofocus.") diff --git a/openflexure_microscope/api/default_extensions/zip_builder.py b/openflexure_microscope/api/default_extensions/zip_builder.py index 634a772c..9b1d8757 100644 --- a/openflexure_microscope/api/default_extensions/zip_builder.py +++ b/openflexure_microscope/api/default_extensions/zip_builder.py @@ -14,7 +14,7 @@ import zipfile import tempfile import logging -from openflexure_microscope.common.flask_labthings.find import find_device +from openflexure_microscope.common.flask_labthings.find import find_component from openflexure_microscope.common.flask_labthings.resource import Resource from openflexure_microscope.common.flask_labthings.extensions import BaseExtension from openflexure_microscope.common.flask_labthings.decorators import ( @@ -100,7 +100,7 @@ class ZipBuilderAPIView(Resource): def post(self): ids = list(JsonResponse(request).json) - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") task = taskify(default_zip_manager.build_zip_from_capture_ids)(microscope, ids) diff --git a/openflexure_microscope/api/example_extensions/ev_gui.py b/openflexure_microscope/api/example_extensions/ev_gui.py index 561e4acf..da6f9efc 100644 --- a/openflexure_microscope/api/example_extensions/ev_gui.py +++ b/openflexure_microscope/api/example_extensions/ev_gui.py @@ -93,7 +93,7 @@ class TestDoAPIView(Resource): # Using the dynamic form -dynamic_test_extension_v2 = BaseExtension("dynamic_test_extension") +dynamic_test_extension_v2 = BaseExtension("org.openflexure.examples.dynamic-gui") dynamic_test_extension_v2.add_view( TestAPIView, "/get", endpoint="dynamic_test_extension_get" ) @@ -107,7 +107,7 @@ dynamic_test_extension_v2.add_meta( # Using the static form -static_test_extension_v2 = BaseExtension("static_test_extension") +static_test_extension_v2 = BaseExtension("org.openflexure.examples.static-gui") static_test_extension_v2.add_view( TestAPIView, "/get", endpoint="static_test_extension_get" ) diff --git a/openflexure_microscope/api/v2/views/actions/camera.py b/openflexure_microscope/api/v2/views/actions/camera.py index cb458d9e..ef507fe5 100644 --- a/openflexure_microscope/api/v2/views/actions/camera.py +++ b/openflexure_microscope/api/v2/views/actions/camera.py @@ -1,6 +1,6 @@ from openflexure_microscope.api.utilities import get_bool, JsonResponse from openflexure_microscope.common.flask_labthings.resource import Resource -from openflexure_microscope.common.flask_labthings.find import find_device +from openflexure_microscope.common.flask_labthings.find import find_component from openflexure_microscope.common.flask_labthings.decorators import ( use_args, marshal_with, @@ -48,7 +48,7 @@ class CaptureAPI(Resource): """ Create a new capture """ - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") resize = args.get("resize", None) if resize: @@ -100,7 +100,7 @@ class GPUPreviewStartAPI(Resource): """ Start the onboard GPU preview. """ - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") window = args.get("window") logging.debug(window) @@ -124,7 +124,7 @@ class GPUPreviewStopAPI(Resource): """ Stop the onboard GPU preview. """ - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") microscope.camera.stop_preview() # TODO: Make schema for microscope status return jsonify(microscope.status) diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index cad4a776..c1fec897 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -1,6 +1,6 @@ from openflexure_microscope.api.utilities import JsonResponse from openflexure_microscope.common.flask_labthings.resource import Resource -from openflexure_microscope.common.flask_labthings.find import find_device +from openflexure_microscope.common.flask_labthings.find import find_component from openflexure_microscope.common.flask_labthings.decorators import ( use_args, marshal_with, @@ -32,7 +32,7 @@ class MoveStageAPI(Resource): """ Move the microscope stage in x, y, z """ - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") # Handle absolute positioning (calculate a relative move from current position and target) if (args.get("absolute")) and (microscope.stage): # Only if stage exists @@ -68,7 +68,7 @@ class ZeroStageAPI(Resource): Zero the stage coordinates. Does not move the stage, but rather makes the current position read as [0, 0, 0] """ - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") microscope.stage.zero_position() # TODO: Make schema for microscope status diff --git a/openflexure_microscope/api/v2/views/captures.py b/openflexure_microscope/api/v2/views/captures.py index 819b46e0..1ef852ab 100644 --- a/openflexure_microscope/api/v2/views/captures.py +++ b/openflexure_microscope/api/v2/views/captures.py @@ -11,7 +11,7 @@ from openflexure_microscope.common.flask_labthings.utilities import ( ) from openflexure_microscope.common.flask_labthings.decorators import marshal_with -from openflexure_microscope.common.flask_labthings.find import find_device +from openflexure_microscope.common.flask_labthings.find import find_component from marshmallow import pre_dump @@ -71,7 +71,7 @@ class CaptureList(Resource): @marshal_with(CaptureSchema(many=True)) def get(self): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") image_list = microscope.camera.images return image_list @@ -83,7 +83,7 @@ class CaptureResource(Resource): @marshal_with(CaptureSchema()) def get(self, id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -92,7 +92,7 @@ class CaptureResource(Resource): return capture_obj def delete(self, id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -110,7 +110,7 @@ class CaptureDownload(Resource): def get(self, id, filename): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -146,7 +146,7 @@ class CaptureTags(Resource): def get(self, id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -156,7 +156,7 @@ class CaptureTags(Resource): def put(self, id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -173,7 +173,7 @@ class CaptureTags(Resource): def delete(self, capture_id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -196,7 +196,7 @@ class CaptureMetadata(Resource): """ def get(self, id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: @@ -205,7 +205,7 @@ class CaptureMetadata(Resource): return jsonify(capture_obj.metadata) def put(self, id): - microscope = find_device("org.openflexure.microscope") + microscope = find_component("org.openflexure.microscope") capture_obj = microscope.camera.image_from_id(id) if not capture_obj: diff --git a/openflexure_microscope/common/flask_labthings/decorators.py b/openflexure_microscope/common/flask_labthings/decorators.py index e186a5e1..7d6bf2c6 100644 --- a/openflexure_microscope/common/flask_labthings/decorators.py +++ b/openflexure_microscope/common/flask_labthings/decorators.py @@ -148,22 +148,31 @@ tag = Tag class doc_response(object): - def __init__(self, code, description=None, **kwargs): + def __init__(self, code, description=None, mimetype=None, **kwargs): self.code = code self.description = description self.kwargs = kwargs + self.mimetype = mimetype + + self.response_dict = { + "responses": { + self.code: { + "description": self.description or HTTPStatus(self.code).phrase, + **self.kwargs, + } + } + } + + if self.mimetype: + self.response_dict.update({ + "responses": { + self.code: { + "content": {self.mimetype: {}} + } + } + }) def __call__(self, f): # Pass params to call function attribute for external access - update_spec( - f, - { - "responses": { - self.code: { - "description": self.description or HTTPStatus(self.code).phrase, - **self.kwargs, - } - } - }, - ) + update_spec(f, self.response_dict) return f diff --git a/openflexure_microscope/stage/base.py b/openflexure_microscope/stage/base.py index 4b591994..edb40158 100644 --- a/openflexure_microscope/stage/base.py +++ b/openflexure_microscope/stage/base.py @@ -49,6 +49,14 @@ class BaseStage(metaclass=ABCMeta): """The current position, as a list""" pass + @property + def position_map(self): + return { + "x": self.position[0], + "y": self.position[1], + "z": self.position[2], + } + @property @abstractmethod def backlash(self): diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index 92765ec3..fe2d2ac6 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -20,13 +20,10 @@ class MockStage(BaseStage): def status(self): """The general status dictionary of the board.""" status = { - "position": { - "x": self.position[0], - "y": self.position[1], - "z": self.position[2], - }, + "position": self.position_map, "board": None, - "version": "0", + "firmware": None, + "version": None } return status diff --git a/openflexure_microscope/stage/sanga.py b/openflexure_microscope/stage/sanga.py index 27b192a5..2c4fa6d9 100644 --- a/openflexure_microscope/stage/sanga.py +++ b/openflexure_microscope/stage/sanga.py @@ -34,11 +34,7 @@ class SangaStage(BaseStage): def status(self): """The general status dictionary of the board.""" status = { - "position": { - "x": self.position[0], - "y": self.position[1], - "z": self.position[2], - }, + "position": self.position_map, "board": self.board.board, "firmware": self.board.firmware, }