Creating the plugin form
The plugin form is a yaml file specifying the wizard behavior and looks. At a high level, it will take inputs from a user and send them to the plugin executable as arguments. YAML is "is a human-friendly data serialization language for all programming languages". It is commonly used for configuration files and in applications where data is being stored or transmitted.
Please refer to the section "Form" for a detailed description of the syntax and structure of the form file.
1. The "form.yml" file
Although a GUI isn’t strictly necessary for a plugin, it provides a more convenient way to interact with the user and gather inputs for the plugin’s executable component.
Let’s create an empty text file called "form.yaml" in the folder "dist". And then, copy and paste the following text in the file. Save when closing.
The complete version of the form file for the violinplot plugin is available here (Click to open).
wizard:
title: "ViolinPlot Plugin"
pages:
- name: "user_inputs"
title: "Example of a SAInt Plugin"
description: "This is minimum helpful example of a SAInt plugin."
page_sections:
- name: "inputs"
mode: "Fixed"
title: "Inputs"
fields:
- name: "network"
label: "Input network: "
type: "fileexplorer"
options:
- display_name: "SAInt Electric Network"
value: ".enet"
- display_name: "SAInt Gas Network"
value: ".gnet"
- display_name: "SAInt Thermal Network"
value: ".tnet"
validation_rules:
- type: "required"
- name: "scenario"
label: "Input scenario: "
type: "fileexplorer"
options:
- display_name: "SAInt Electric Scenario"
value: ".esce"
- display_name: "SAInt Gas Scenario"
value: ".gsce"
- display_name: "SAInt Thermal Scenario"
value: ".tsce"
validation_rules:
- type: "required"
- name: "expression"
label: "Input expression"
type: "textbox"
options: []
validation_rules:
- type: "required"
- name: "title"
label: "Title of the chart"
type: "textbox"
default_value: "ViolinPlot"
options: []
validation_rules:
- type: "required"
- name: "axis"
label: "Text for the y-axis"
type: "textbox"
options: []
validation_rules:
- type: "required"
- name: "output_folder"
label: "Output Folder"
type : "folderexplorer"
default_value: "%userprofile%/Desktop"
validation_rules:
- type: "required"
page_navigation:
show_submit: true
navigation_elements:
previous_button:
label: "← Back"
color: "#6c757d"
next_button:
label: "Next →"
color: "#007bff"
submit_button:
label: "Submit"
color: "#28a745"
After validation of the code, SAInt will render the content of the file "form.yaml" as in Figure 1.
As in the case of the execution of the script in the command line, we need to collect all required parameters and pass them to the executable. All parameters are mandatory and have a red asterisk next to their name.
In the form, the fields "network" and "scenario" are of type "fileexplorer", and can filter their objects based on the matching of the correct extension for the network or scenario types.
The field "expression", "title", and "axis" are all of type "textbox", with no default value.
Finally, the field "output-folder" is of "folderexplorer" type, with a default value pointing to the desktop folder of the user of the Windows session.