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

Plugin schema are now just plugin forms (requires eV 1.2)

parent 0d7a5f71
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,6 +8,6 @@ Developing Plugins
   ./plugins/structure.rst
   ./plugins/routes.rst
   ./plugins/hardware.rst
   ./plugins/schema.rst
   ./plugins/form.rst
   ./plugins/example.rst
   ./plugins/class.rst
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ plugin.py
.. literalinclude:: example/plugin.py
  :language: python

schema.json
form.json
+++++++++++

.. literalinclude:: example/schema.json
.. literalinclude:: example/form.json
  :language: JSON

Notes
+2 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
        "isTask": false,
        "selfUpdate": true,
        "route": "/hello",
        "schema": [
        "form": [
          {
            "fieldType": "textInput",
            "placeholder": "Enter a string",
@@ -21,7 +21,7 @@
        "isTask": true,
        "route": "/timelapse",
        "submitLabel": "Start timelapse",
        "schema": [
        "form": [
            {
              "fieldType": "numberInput",
              "name": "n_images",
+4 −4
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import json
from flask import request, Response, escape, jsonify

HERE = os.path.dirname(os.path.realpath(__file__))
SCHEMA_PATH = os.path.join(HERE, "schema.json")
FORM_PATH = os.path.join(HERE, "forms.json")

### MICROSCOPE PLUGIN ###

@@ -18,10 +18,10 @@ class MyPluginClass(MicroscopePlugin):
    A set of default plugins
    """

    global SCHEMA_PATH
    global FORM_PATH

    with open(SCHEMA_PATH, 'r') as sc:
        api_schema = json.load(sc)
    with open(FORM_PATH, 'r') as sc:
        api_form = json.load(sc)

    api_views = {
        '/identify': IdentifyAPI,
+13 −13
Original line number Diff line number Diff line
@@ -4,39 +4,39 @@ Adding a GUI
Introduction
------------

In order to bind user-interface elements to your plugin, an ``api_schema`` variable must be included in your microscope plugin, similar to your ``api_views``.
In order to bind user-interface elements to your plugin, an ``api_form`` variable must be included in your microscope plugin, similar to your ``api_views``.

This variable must be in the form of a dictionary, with all data able to be parsed into JSON. Because of this requirement, it is suggested that you create your API schema as a JSON file, and load that file as a dictionary into your plugin. For example:
This variable must be in the form of a dictionary, with all data able to be parsed into JSON. Because of this requirement, it is suggested that you create your API form as a JSON file, and load that file as a dictionary into your plugin. For example:

.. code-block:: python

    import json

    HERE = os.path.dirname(os.path.realpath(__file__))  # Find the full path of your plugin Python file
    SCHEMA_PATH = os.path.join(HERE, "schema.json")  # Find the full path of the adjascent JSON file
    FORM_PATH = os.path.join(HERE, "form.json")  # Find the full path of the adjascent JSON file

    class MyPluginClass(MicroscopePlugin):

        with open(SCHEMA_PATH, 'r') as sc:  # Open the JSON file
            api_schema = json.load(sc)  # Load the JSON file into the api_schema dictionary
        with open(FORM_PATH, 'r') as sc:  # Open the JSON file
            api_form = json.load(sc)  # Load the JSON file into the api_form dictionary

Throughout this documentation, all example of ``api_schema`` sections will be in JSON format. Keep in mind however that it is possible to directly define your ``api_schema`` as a dictionary, without loading an external file.
Throughout this documentation, all example of ``api_form`` sections will be in JSON format. Keep in mind however that it is possible to directly define your ``api_form`` as a dictionary, without loading an external file.


Forms from ``api_schema``
Forms from ``api_form``
-------------------------

The ``api_schema`` object essentially describes HTML forms, which it is up to the client to render. The form is constructed by specifying a set of components, and their values. A form can update it's values by sending a GET request to the API route bound to that form, and can send it's current values via a POST request to *this same API route*.
The ``api_form`` object essentially describes HTML forms, which it is up to the client to render. The form is constructed by specifying a set of components, and their values. A form can update it's values by sending a GET request to the API route bound to that form, and can send it's current values via a POST request to *this same API route*.

Each component in the form has a ``name`` property, which must match up to a property your API route expects in JSON POST requests, and returns in JSON GET requests.

Structure of ``api_schema``
Structure of ``api_form``
---------------------------

Root level
++++++++++

The root of your ``api_schema`` expects 3 properties:
The root of your ``api_form`` expects 3 properties:

``id`` - A unique ID to give your client-side plugin

@@ -61,7 +61,7 @@ Each form is described by a JSON object, with the following properties:

``submitLabel`` *(optional)* - String to place inside of the form's submit button

``schema`` - An array of form components as described below
``form`` - An array of form components as described below

Component level
+++++++++++++++
@@ -182,11 +182,11 @@ Overview of components
JSON form example
-----------------

.. literalinclude:: schema_example.json
.. literalinclude:: forms_example.json
  :language: JSON


.. toctree::
   :maxdepth: 1

   ./schema/json_schema.rst
 No newline at end of file
   ./form/json_form.rst
 No newline at end of file
Loading