Moved plugins up one level and added new view plugins
This commit is contained in:
parent
ac5f26ef6b
commit
bde2e9de2a
7 changed files with 53 additions and 36 deletions
|
|
@ -0,0 +1 @@
|
|||
from .plugin import Plugin
|
||||
20
openflexure_microscope/plugins/default/api.py
Normal file
20
openflexure_microscope/plugins/default/api.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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
openflexure_microscope/plugins/default/plugin.py
Normal file
30
openflexure_microscope/plugins/default/plugin.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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!"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
from openflexure_microscope.plugins.default.test_plugin.api import ENDPOINTS
|
||||
from openflexure_microscope.plugins.default.test_plugin.plugin import PLUGINS
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
from openflexure_microscope.plugins import MicroscopePlugin
|
||||
|
||||
|
||||
class FirstPlugin(MicroscopePlugin):
|
||||
"""
|
||||
An example Microscope plugin.
|
||||
"""
|
||||
def run(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)
|
||||
return response
|
||||
|
||||
|
||||
PLUGINS = {
|
||||
'test1': FirstPlugin,
|
||||
} #: dict: Dictionary describing the plugins. Keys are the names of the plugin's namescape, with a value corresponding to the class of that plugin.
|
||||
Loading…
Add table
Add a link
Reference in a new issue