Added example dynamic form
This commit is contained in:
parent
45e7bcb167
commit
1db88548c8
3 changed files with 78 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
from .plugin import DynamicExamplePlugin
|
||||
from . import api
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
from openflexure_microscope.devel import (
|
||||
MicroscopeViewPlugin,
|
||||
JsonResponse,
|
||||
request,
|
||||
jsonify,
|
||||
taskify,
|
||||
)
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
class DoAPI(MicroscopeViewPlugin):
|
||||
"""
|
||||
A dynamic example API plugin
|
||||
"""
|
||||
|
||||
def get(self):
|
||||
values = {"val_int": self.plugin.val_int}
|
||||
return jsonify(values)
|
||||
|
||||
def post(self):
|
||||
self.plugin.val_int += 1
|
||||
|
||||
return jsonify({"response": "completed"})
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
import random
|
||||
import time
|
||||
import os
|
||||
import json
|
||||
from openflexure_microscope.devel import MicroscopePlugin, update_task_progress
|
||||
|
||||
from .api import DoAPI
|
||||
|
||||
|
||||
class DynamicExamplePlugin(MicroscopePlugin):
|
||||
"""
|
||||
An example plugin using a comprehensive form
|
||||
"""
|
||||
|
||||
api_views = {"/do": DoAPI}
|
||||
|
||||
def __init__(self):
|
||||
MicroscopePlugin.__init__(self)
|
||||
|
||||
self.val_int = 0
|
||||
self.val_str = "Hello"
|
||||
|
||||
self.set_gui(self.dynamic_form)
|
||||
|
||||
def dynamic_form(self):
|
||||
return {
|
||||
"id": "test-plugin",
|
||||
"icon": "pets",
|
||||
"forms": [
|
||||
{
|
||||
"name": "Simple request",
|
||||
"isCollapsible": False,
|
||||
"isTask": False,
|
||||
"selfUpdate": True,
|
||||
"route": "/do",
|
||||
"submitLabel": "Do things",
|
||||
"schema": [
|
||||
{
|
||||
"fieldType": "numberInput",
|
||||
"name": "val_int",
|
||||
"label": "Number value",
|
||||
"minValue": 0,
|
||||
},
|
||||
{
|
||||
"fieldType": "htmlBlock",
|
||||
"name": "html_block",
|
||||
"content": f"<i>Value is: </i><br>{self.val_int}.",
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue