Blackened everything
This commit is contained in:
parent
e213647217
commit
5966ce29be
57 changed files with 1938 additions and 1414 deletions
|
|
@ -1,2 +1,2 @@
|
|||
from .plugin import ExamplePlugin
|
||||
from . import api
|
||||
from . import api
|
||||
|
|
|
|||
|
|
@ -1,7 +1,16 @@
|
|||
from openflexure_microscope.devel import MicroscopeViewPlugin, TaskDeniedException, JsonResponse, Response, request, escape, jsonify
|
||||
from openflexure_microscope.devel import (
|
||||
MicroscopeViewPlugin,
|
||||
TaskDeniedException,
|
||||
JsonResponse,
|
||||
Response,
|
||||
request,
|
||||
escape,
|
||||
jsonify,
|
||||
)
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
class DoAPI(MicroscopeViewPlugin):
|
||||
"""
|
||||
A simple example API plugin
|
||||
|
|
@ -15,27 +24,21 @@ class DoAPI(MicroscopeViewPlugin):
|
|||
payload = JsonResponse(request)
|
||||
|
||||
# Extract a values from the JSON payload.
|
||||
val_int = payload.param('val_int', default=None, convert=int)
|
||||
val_str = payload.param('val_str', default=None, convert=str)
|
||||
val_radio = payload.param('val_radio', default=None)
|
||||
val_check = payload.param('val_check', default=None)
|
||||
val_select = payload.param('val_select', default=None)
|
||||
val_disposable = payload.param('val_disposable', default=None)
|
||||
val_int = payload.param("val_int", default=None, convert=int)
|
||||
val_str = payload.param("val_str", default=None, convert=str)
|
||||
val_radio = payload.param("val_radio", default=None)
|
||||
val_check = payload.param("val_check", default=None)
|
||||
val_select = payload.param("val_select", default=None)
|
||||
val_disposable = payload.param("val_disposable", default=None)
|
||||
|
||||
self.plugin.set_values(
|
||||
val_int,
|
||||
val_str,
|
||||
val_radio,
|
||||
val_check,
|
||||
val_select,
|
||||
val_disposable
|
||||
val_int, val_str, val_radio, val_check, val_select, val_disposable
|
||||
)
|
||||
|
||||
print(self.plugin.get_values_dict())
|
||||
|
||||
return jsonify({
|
||||
'response': 'completed'
|
||||
})
|
||||
return jsonify({"response": "completed"})
|
||||
|
||||
|
||||
class TaskAPI(MicroscopeViewPlugin):
|
||||
"""
|
||||
|
|
@ -43,19 +46,19 @@ class TaskAPI(MicroscopeViewPlugin):
|
|||
"""
|
||||
|
||||
def get(self):
|
||||
return jsonify({
|
||||
'run_time': self.plugin.run_time
|
||||
})
|
||||
return jsonify({"run_time": self.plugin.run_time})
|
||||
|
||||
def post(self):
|
||||
# Get payload JSON
|
||||
payload = JsonResponse(request)
|
||||
|
||||
# Extract a values from the JSON payload.
|
||||
val_int = payload.param('run_time', default=5, convert=int)
|
||||
val_int = payload.param("run_time", default=5, convert=int)
|
||||
|
||||
logging.info("Running task...")
|
||||
task = self.microscope.task.start(self.plugin.generate_random_numbers_for_a_while, val_int)
|
||||
task = self.microscope.task.start(
|
||||
self.plugin.generate_random_numbers_for_a_while, val_int
|
||||
)
|
||||
|
||||
# return a handle on the autofocus task
|
||||
return jsonify(task.state), 202
|
||||
return jsonify(task.state), 202
|
||||
|
|
|
|||
|
|
@ -9,19 +9,18 @@ from .api import DoAPI, TaskAPI
|
|||
HERE = os.path.dirname(os.path.realpath(__file__))
|
||||
FORM_PATH = os.path.join(HERE, "forms.json")
|
||||
|
||||
|
||||
class ExamplePlugin(MicroscopePlugin):
|
||||
"""
|
||||
An example plugin using a comprehensive form
|
||||
"""
|
||||
|
||||
global FORM_PATH
|
||||
|
||||
with open(FORM_PATH, 'r') as sc:
|
||||
with open(FORM_PATH, "r") as sc:
|
||||
api_form = json.load(sc)
|
||||
|
||||
api_views = {
|
||||
'/do': DoAPI,
|
||||
'/task': TaskAPI
|
||||
}
|
||||
api_views = {"/do": DoAPI, "/task": TaskAPI}
|
||||
|
||||
def __init__(self):
|
||||
self.val_int = 10
|
||||
|
|
@ -33,7 +32,9 @@ class ExamplePlugin(MicroscopePlugin):
|
|||
|
||||
self.run_time = 5
|
||||
|
||||
def set_values(self, val_int, val_str, val_radio, val_check, val_select, val_disposable):
|
||||
def set_values(
|
||||
self, val_int, val_str, val_radio, val_check, val_select, val_disposable
|
||||
):
|
||||
"""
|
||||
Demonstrate a plugin with form
|
||||
"""
|
||||
|
|
@ -54,12 +55,12 @@ class ExamplePlugin(MicroscopePlugin):
|
|||
|
||||
def get_values_dict(self):
|
||||
return {
|
||||
'val_int': self.val_int,
|
||||
'val_str': self.val_str,
|
||||
'val_radio': self.val_radio,
|
||||
'val_check': self.val_check,
|
||||
'val_select': self.val_select,
|
||||
'val_unused': self.val_unused
|
||||
"val_int": self.val_int,
|
||||
"val_str": self.val_str,
|
||||
"val_radio": self.val_radio,
|
||||
"val_check": self.val_check,
|
||||
"val_select": self.val_select,
|
||||
"val_unused": self.val_unused,
|
||||
}
|
||||
|
||||
def generate_random_numbers_for_a_while(self, run_time: int):
|
||||
|
|
@ -68,5 +69,5 @@ class ExamplePlugin(MicroscopePlugin):
|
|||
for _ in range(run_time):
|
||||
vals.append(random.random())
|
||||
time.sleep(1)
|
||||
|
||||
return vals
|
||||
|
||||
return vals
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue