Merge branch 'v2.1.0-dev' into stage-calibration
This commit is contained in:
commit
8a2a2abbec
12 changed files with 170 additions and 81 deletions
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
from gevent import monkey
|
||||
|
||||
# Patch most system modules. Leave threads untouched so we can still use them normally if needed.
|
||||
monkey.patch_all(thread=False)
|
||||
|
||||
import time
|
||||
import atexit
|
||||
|
|
@ -60,6 +64,7 @@ app, labthing = create_app(
|
|||
prefix="/api/v2",
|
||||
title=f"OpenFlexure Microscope {api_microscope.name}",
|
||||
description="Test LabThing-based API for OpenFlexure Microscope",
|
||||
types=["org.openflexure.microscope"],
|
||||
version=pkg_resources.get_distribution("openflexure_microscope").version,
|
||||
flask_kwargs={"static_url_path": ""},
|
||||
)
|
||||
|
|
@ -167,5 +172,9 @@ def cleanup():
|
|||
|
||||
atexit.register(cleanup)
|
||||
|
||||
# Start the app
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port="5000", threaded=True, debug=True, use_reloader=False)
|
||||
from labthings.server.wsgi import Server
|
||||
|
||||
server = Server(app)
|
||||
server.run(host="0.0.0.0", port=5000, debug=False)
|
||||
|
|
|
|||
|
|
@ -14,3 +14,5 @@ except Exception as e:
|
|||
logging.error(
|
||||
f"Exception loading builtin extension picamera_autocalibrate: \n{traceback.format_exc()}"
|
||||
)
|
||||
|
||||
from ..example_extensions.custom_element import customelement_extension_v2
|
||||
|
|
|
|||
|
|
@ -241,6 +241,7 @@ def dynamic_form():
|
|||
return {
|
||||
"icon": "sd_storage",
|
||||
"title": "Storage",
|
||||
"viewPanel": "gallery",
|
||||
"forms": [
|
||||
{
|
||||
"name": "Autostorage",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
from labthings.server.extensions import BaseExtension
|
||||
from labthings.server.view import View
|
||||
from labthings.server.decorators import ThingProperty, PropertySchema, use_args
|
||||
from labthings.server import fields
|
||||
from labthings.server.find import find_component
|
||||
from labthings.core.utilities import path_relative_to
|
||||
|
||||
from openflexure_microscope.paths import settings_file_path, check_rw
|
||||
from openflexure_microscope.config import OpenflexureSettingsFile
|
||||
from openflexure_microscope.camera.base import BASE_CAPTURE_PATH
|
||||
from openflexure_microscope.camera.capture import build_captures_from_exif
|
||||
|
||||
from openflexure_microscope.api.utilities.gui import build_gui
|
||||
|
||||
from flask import abort, url_for
|
||||
import logging
|
||||
import os
|
||||
import psutil
|
||||
|
||||
from sys import platform
|
||||
|
||||
|
||||
class CustomElementExtension(BaseExtension):
|
||||
def __init__(self):
|
||||
BaseExtension.__init__(
|
||||
self,
|
||||
"org.openflexure.customelement",
|
||||
description="Testing HTML components in an extension",
|
||||
static_folder=path_relative_to(__file__, "static"),
|
||||
)
|
||||
|
||||
# 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"CustomElementExtension found microscope {microscope_obj}")
|
||||
|
||||
|
||||
customelement_extension_v2 = CustomElementExtension()
|
||||
|
||||
|
||||
def wc_func():
|
||||
return {
|
||||
"href": customelement_extension_v2.static_file_url("my-custom-element.min.js"),
|
||||
"name": "my-custom-element",
|
||||
}
|
||||
|
||||
|
||||
def gui_func():
|
||||
return {"icon": "pets", "title": "Element", "viewPanel": "stream", "wc": wc_func()}
|
||||
|
||||
|
||||
customelement_extension_v2.add_meta("wc", wc_func)
|
||||
customelement_extension_v2.add_meta(
|
||||
"gui", build_gui(gui_func, customelement_extension_v2)
|
||||
)
|
||||
7
openflexure_microscope/api/example_extensions/custom_element/static/my-custom-element.min.js
vendored
Normal file
7
openflexure_microscope/api/example_extensions/custom_element/static/my-custom-element.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -207,7 +207,7 @@ class CaptureTags(View):
|
|||
|
||||
return jsonify(capture_obj.tags)
|
||||
|
||||
def delete(self, capture_id):
|
||||
def delete(self, id):
|
||||
"""
|
||||
Delete tags from a single image capture
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -18,7 +18,16 @@ class MjpegStream(View):
|
|||
@doc_response(200, mimetype="multipart/x-mixed-replace")
|
||||
def get(self):
|
||||
"""
|
||||
MJPEG stream from the microscope camera
|
||||
MJPEG stream from the microscope camera.
|
||||
|
||||
Note: While the code actually getting frame data from a camera and storing it in
|
||||
camera.frame runs in a thread, the gen(microscope.camera) generator does not.
|
||||
This response is therefore blocking. The generator just yields the most recent
|
||||
frame from the camera object, passed to the Flask response, and then repeats until
|
||||
the connection is closed.
|
||||
|
||||
Without monkey patching with gevent, or using a native threaded server, the stream
|
||||
will block all proceeding requests.
|
||||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
# Restart stream worker thread
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue