Commit bde2e9de authored by Joel Collins's avatar Joel Collins
Browse files

Moved plugins up one level and added new view plugins

parent ac5f26ef
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
from .plugin import Plugin
 No newline at end of file
+20 −0
Original line number Diff line number Diff line
from openflexure_microscope.api.utilities import parse_payload
from openflexure_microscope.api.v1.views import MicroscopeViewPlugin

from flask import request, Response, escape

import logging


class IdentifyAPI(MicroscopeViewPlugin):

    def get(self):
        data = self.microscope.plugin.default.identify()  # Call a method from our plugin, using the full route
        return Response(escape(data))


class HelloWorldAPI(MicroscopeViewPlugin):

    def get(self):
        data = self.plugin.hello_world()  # Call a method from our plugin, using the MicroscopeViewPlugin.plugin shortcut
        return Response(data)
+30 −0
Original line number Diff line number Diff line
from openflexure_microscope.plugins import MicroscopePlugin

from .api import IdentifyAPI, HelloWorldAPI


class Plugin(MicroscopePlugin):
    """
    A set of default plugins
    """

    api_views = {
        '/identify': IdentifyAPI,
        '/hello': HelloWorldAPI,
    }

    def identify(self):
        """
        Demonstrate access to Microscope.camera, and Microscope.stage
        """

        response = "My parent camera is {}, and my parent stage is {}.".format(self.microscope.camera, self.microscope.stage)
        print(response)
        return response

    def hello_world(self):
        """
        Demonstrate passive method
        """

        return "Hello world!"
 No newline at end of file
+0 −2
Original line number Diff line number Diff line
from openflexure_microscope.plugins.default.test_plugin.api import ENDPOINTS
from openflexure_microscope.plugins.default.test_plugin.plugin import PLUGINS
 No newline at end of file
+0 −28
Original line number Diff line number Diff line
from openflexure_microscope.api.utilities import parse_payload
from openflexure_microscope.api.v1.views import MicroscopeView

from flask import request, Response

import logging


class PluginTestAPI(MicroscopeView):

    def get(self):
        data = self.microscope.plugin.test1.run()  # Call a method from our plugin
        return Response(data)

    def post(self):
        # Get payload
        state = parse_payload(request)
        logging.debug(state)

        # Handle absolute positioning
        if 'data' in state:  # If value is given in payload JSON
            data = str(state['data'])  # Process and store that value

        return Response(data)

ENDPOINTS = {
    'test1': PluginTestAPI
}
Loading