Commit 9ae2ae06 authored by Joel Collins's avatar Joel Collins
Browse files

Updated documentation to LT070 style

parent 83b3ea1d
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
Capture Object
=======================================================

By default, all image and video capture data are stored to instances of :py:class:`openflexure_microscope.camera.capture.CaptureObject`. This class mostly wraps up complexity associated with moving data between disk and memory. 
By default, all image and video capture data are stored to instances of :py:class:`openflexure_microscope.captures.CaptureObject`. This class mostly wraps up complexity associated with moving data between disk and memory. 

The class also includes some convenience features such as handling metadata tags and file names, and generating image thumbnails. Additionally, the class handles storing capture metadata to Exif tags in supported formats. 

Below are details of available methods and attributes.

.. automodule:: openflexure_microscope.camera.capture
.. automodule:: openflexure_microscope.captures.capture
    :members:
 No newline at end of file
+7 −4
Original line number Diff line number Diff line
@@ -17,11 +17,14 @@ Like properties, we use a special view class to identify a view as an action: ``
        """
        Take an image capture and return it without saving
        """

        # Expect a "use_video_port" boolean, which defaults to True if none is given
        @use_args({"use_video_port": fields.Boolean(missing=True)})
        args = {"use_video_port": fields.Boolean(missing=True)}

        # Our success response (200) returns an image (image/jpeg mimetype)
        @doc_response(200, mimetype="image/jpeg")
        responses = {
            200: {"content_type": "image/jpeg"}
        }

        def post(self, args):
            """
            Take a non-persistant image capture.
@@ -41,7 +44,7 @@ Like properties, we use a special view class to identify a view as an action: ``
                # Return our image data using Flasks send_file function
                return send_file(io.BytesIO(stream.read()), mimetype="image/jpeg")

In this example, we are also making use of the ``@doc_response`` decorator, to document that our successful response (HTTP code 200) will return data with a mimetype ``image/jpeg``, as well as ``@use_args`` to accept optional parameters with POST requests.
In this example, we are also making use of the ``responses`` attribute, to document that our successful response (HTTP code 200) will return data with a mimetype ``image/jpeg``, as well as ``args`` to accept optional parameters with POST requests.

Complete example
----------------
+6 −5
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View

from labthings.server.decorators import use_body
from labthings.server import fields

## Extension methods
@@ -44,11 +43,13 @@ class ExampleIdentifyView(View):


class ExampleRenameView(View):
    # Expect a request parameter called "name", which is a string. Pass to argument "args".
    @use_body(fields.String(required=True, example="My Example Microscope"))
    def post(self, body):
    # Expect a request parameter called "name", which is a string. 
    # Passed to the argument "args".
    args = fields.String(required=True, example="My Example Microscope")

    def post(self, args):
        # Look for our new name in the request body
        new_name = body
        new_name = args

        # Find our microscope component
        microscope = find_component("org.openflexure.microscope")
+5 −5
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View

from labthings.server.decorators import use_args, marshal_with
from labthings.server.schema import Schema
from labthings.server import fields

@@ -30,10 +29,10 @@ def rename(microscope, new_name):

## Extension views


class ExampleIdentifyView(View):
    # Format our returned object using MicroscopeIdentifySchema
    @marshal_with(MicroscopeIdentifySchema())
    schema = MicroscopeIdentifySchema()

    def get(self):
        # Find our microscope component
        microscope = find_component("org.openflexure.microscope")
@@ -45,9 +44,10 @@ class ExampleIdentifyView(View):

class ExampleRenameView(View):
    # Format our returned object using MicroscopeIdentifySchema
    @marshal_with(MicroscopeIdentifySchema())
    schema = MicroscopeIdentifySchema()
    # Expect a request parameter called "name", which is a string. Pass to argument "args".
    @use_args({"name": fields.String(required=True, example="My Example Microscope")})
    args = {"name": fields.String(required=True, example="My Example Microscope")}

    def post(self, args):
        # Look for our "name" parameter in the request arguments
        new_name = args.get("name")
+8 −12
Original line number Diff line number Diff line
@@ -2,12 +2,6 @@ from labthings.server.extensions import BaseExtension
from labthings.server.find import find_component
from labthings.server.view import View, PropertyView

from labthings.server.decorators import (
    use_args,
    marshal_with,
    ThingProperty,
    PropertySchema,
)
from labthings.server.schema import Schema
from labthings.server import fields

@@ -38,7 +32,8 @@ def rename(microscope, new_name):
# Since we only have a GET method here, it'll register as a read-only property
class ExampleIdentifyView(PropertyView):
    # Format our returned object using MicroscopeIdentifySchema
    @marshal_with(MicroscopeIdentifySchema())
    schema = MicroscopeIdentifySchema()

    def get(self):
        """
        Show identifying information about the current microscope object
@@ -47,14 +42,15 @@ class ExampleIdentifyView(PropertyView):
        microscope = find_component("org.openflexure.microscope")

        # Return our microscope object,
        # let @marshal_with handle formatting the output
        # let schema handle formatting the output
        return microscope


# We can use a single schema for all methods if the input and output will be formatted identically
# Eg. Here, we will always expect a "name" string argument, and always return a "name" string attribute
@PropertySchema({"name": fields.String(required=True, example="My Example Microscope")})
# We can use a single schema as the input and output will be formatted identically
# Eg. We always expect a "name" string argument, and always return a "name" string attribute
class ExampleRenameView(PropertyView):
    schema = {"name": fields.String(required=True, example="My Example Microscope")}

    def get(self):
        """
        Show the current microscope name
@@ -78,7 +74,7 @@ class ExampleRenameView(PropertyView):
        rename(microscope, new_name)

        # Return our microscope object,
        # let @marshal_with handle formatting the output
        # let schema handle formatting the output
        return microscope


Loading