Refactored adding views, actions, props and components
This commit is contained in:
parent
7715c19305
commit
a4196b6765
10 changed files with 62 additions and 66 deletions
|
|
@ -69,7 +69,7 @@ app, labthing = create_app(
|
|||
app.json_encoder = JSONEncoder
|
||||
|
||||
# Attach lab devices
|
||||
labthing.register_device(api_microscope, "org.openflexure.microscope")
|
||||
labthing.add_component(api_microscope, "org.openflexure.microscope")
|
||||
|
||||
# Attach extensions
|
||||
if not os.path.isfile(USER_EXTENSIONS_PATH):
|
||||
|
|
@ -78,33 +78,27 @@ for extension in find_extensions(USER_EXTENSIONS_PATH):
|
|||
labthing.register_extension(extension)
|
||||
|
||||
# Attach captures resources
|
||||
labthing.add_resource(views.CaptureList, f"/captures")
|
||||
labthing.register_property(views.CaptureList)
|
||||
labthing.add_resource(views.CaptureResource, f"/captures/<id>")
|
||||
labthing.add_resource(views.CaptureDownload, f"/captures/<id>/download/<filename>")
|
||||
labthing.add_resource(views.CaptureTags, f"/captures/<id>/tags")
|
||||
labthing.add_resource(views.CaptureMetadata, f"/captures/<id>/metadata")
|
||||
labthing.add_view(views.CaptureList, f"/captures")
|
||||
labthing.add_view(views.CaptureResource, f"/captures/<id>")
|
||||
labthing.add_view(views.CaptureDownload, f"/captures/<id>/download/<filename>")
|
||||
labthing.add_view(views.CaptureTags, f"/captures/<id>/tags")
|
||||
labthing.add_view(views.CaptureMetadata, f"/captures/<id>/metadata")
|
||||
|
||||
# Attach settings and status resources
|
||||
labthing.add_resource(views.SettingsProperty, f"/settings")
|
||||
labthing.register_property(views.SettingsProperty)
|
||||
labthing.add_resource(views.NestedSettingsProperty, "/settings/<path:route>")
|
||||
labthing.add_resource(views.StatusProperty, "/status")
|
||||
labthing.register_property(views.StatusProperty)
|
||||
labthing.add_resource(views.NestedStatusProperty, "/status/<path:route>")
|
||||
labthing.add_view(views.SettingsProperty, f"/settings")
|
||||
labthing.add_view(views.NestedSettingsProperty, "/settings/<path:route>")
|
||||
labthing.add_view(views.StatusProperty, "/status")
|
||||
labthing.add_view(views.NestedStatusProperty, "/status/<path:route>")
|
||||
|
||||
# Attach streams resources
|
||||
labthing.add_resource(views.MjpegStream, f"/streams/mjpeg")
|
||||
labthing.register_property(views.MjpegStream)
|
||||
labthing.add_resource(views.SnapshotStream, f"/streams/snapshot")
|
||||
labthing.register_property(views.SnapshotStream)
|
||||
labthing.add_view(views.MjpegStream, f"/streams/mjpeg")
|
||||
labthing.add_view(views.SnapshotStream, f"/streams/snapshot")
|
||||
|
||||
# Attach microscope action resources
|
||||
for name, action in views.enabled_root_actions().items():
|
||||
view_class = action["view_class"]
|
||||
rule = action["rule"]
|
||||
labthing.add_resource(view_class, f"/actions{rule}")
|
||||
labthing.register_action(view_class)
|
||||
labthing.add_view(view_class, f"/actions{rule}")
|
||||
|
||||
|
||||
@app.route("/routes")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
from openflexure_microscope.common.flask_labthings.find import find_device
|
||||
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 (
|
||||
ThingAction,
|
||||
ThingProperty,
|
||||
)
|
||||
|
||||
from openflexure_microscope.devel import JsonResponse, request, jsonify, taskify, abort
|
||||
from openflexure_microscope.utilities import set_properties
|
||||
|
|
@ -298,6 +302,7 @@ class MeasureSharpnessAPI(Resource):
|
|||
return jsonify({"sharpness": measure_sharpness(microscope)})
|
||||
|
||||
|
||||
@ThingAction
|
||||
class AutofocusAPI(Resource):
|
||||
"""
|
||||
Run a standard autofocus
|
||||
|
|
@ -324,6 +329,7 @@ class AutofocusAPI(Resource):
|
|||
abort(503, "No stage connected. Unable to autofocus.")
|
||||
|
||||
|
||||
@ThingAction
|
||||
class FastAutofocusAPI(Resource):
|
||||
"""
|
||||
Run a fast autofocus
|
||||
|
|
@ -359,9 +365,5 @@ autofocus_extension_v2.add_method(fast_autofocus, "fast_autofocus")
|
|||
autofocus_extension_v2.add_method(autofocus, "autofocus")
|
||||
|
||||
autofocus_extension_v2.add_view(MeasureSharpnessAPI, "/measure_sharpness")
|
||||
|
||||
autofocus_extension_v2.add_view(AutofocusAPI, "/autofocus")
|
||||
autofocus_extension_v2.register_action(AutofocusAPI)
|
||||
|
||||
autofocus_extension_v2.add_view(FastAutofocusAPI, "/fast_autofocus")
|
||||
autofocus_extension_v2.register_action(FastAutofocusAPI)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ from openflexure_microscope.common.flask_labthings.find import (
|
|||
from openflexure_microscope.common.flask_labthings.extensions import BaseExtension
|
||||
from openflexure_microscope.common.flask_labthings.decorators import (
|
||||
marshal_task,
|
||||
marshal_with,
|
||||
use_args,
|
||||
ThingAction,
|
||||
)
|
||||
from openflexure_microscope.common.flask_labthings import fields
|
||||
|
||||
|
|
@ -340,6 +340,7 @@ def stack(
|
|||
### Web views
|
||||
|
||||
|
||||
@ThingAction
|
||||
class TileScanAPI(Resource):
|
||||
@use_args(
|
||||
{
|
||||
|
|
@ -398,4 +399,3 @@ class TileScanAPI(Resource):
|
|||
scan_extension_v2 = BaseExtension("scan")
|
||||
|
||||
scan_extension_v2.add_view(TileScanAPI, "/tile")
|
||||
scan_extension_v2.register_action(TileScanAPI)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ import logging
|
|||
from openflexure_microscope.common.flask_labthings.find import find_device
|
||||
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 (
|
||||
ThingAction,
|
||||
ThingProperty,
|
||||
)
|
||||
|
||||
|
||||
class ZipManager:
|
||||
|
|
@ -91,6 +95,7 @@ class ZipManager:
|
|||
default_zip_manager = ZipManager()
|
||||
|
||||
|
||||
@ThingAction
|
||||
class ZipBuilderAPIView(Resource):
|
||||
def post(self):
|
||||
|
||||
|
|
@ -103,6 +108,7 @@ class ZipBuilderAPIView(Resource):
|
|||
return jsonify(task.state), 201
|
||||
|
||||
|
||||
@ThingProperty
|
||||
class ZipListAPIView(Resource):
|
||||
def get(self):
|
||||
return jsonify(default_zip_manager.session_zips)
|
||||
|
|
@ -146,4 +152,3 @@ zip_extension_v2.add_view(ZipGetterAPIView, "/get/<string:session_id>")
|
|||
zip_extension_v2.add_view(ZipListAPIView, "/get")
|
||||
|
||||
zip_extension_v2.add_view(ZipBuilderAPIView, "/build")
|
||||
zip_extension_v2.register_action(ZipBuilderAPIView)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
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 (
|
||||
ThingAction,
|
||||
ThingProperty,
|
||||
)
|
||||
|
||||
from openflexure_microscope.api.utilities.gui import expand_routes
|
||||
|
||||
|
|
@ -72,6 +76,7 @@ static_form = {
|
|||
}
|
||||
|
||||
|
||||
@ThingProperty
|
||||
class TestAPIView(Resource):
|
||||
def get(self):
|
||||
global val_int
|
||||
|
|
@ -79,6 +84,7 @@ class TestAPIView(Resource):
|
|||
return jsonify({"val": True})
|
||||
|
||||
|
||||
@ThingAction
|
||||
class TestDoAPIView(Resource):
|
||||
def post(self):
|
||||
global val_int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue