This plugin looks for python files inside of '~/.mecodescripts' and then loads them in to be run from within OctoPrint. The scripts need to define a few magic variables:
A python object that contains the script logic. This object's __init__
method must take
three arguments:
g : An instance of a G
object from the mecode library.
This object is already connected to the printer.
logger : An instance of logging.Logger
that should be used to log data for the user.
settings : A dict containing the stored user settings for your script.
Your object must also define a run()
method. This method may optionally take keyword arguments.
The run()
method is called when the user clicks the button corresponding to your script. It is
expected to return two things: A boolean value representing whether or not the script completed
successfully, and a dictionary of settings items and their values to persist in the settings
store.
Finally, your object should have an attribute script_status
. If set to anything other than
None
this value will be echoed to OctoPrint while the script is running.
The identifier for this script. Must be globally unique and can not contain spaces or dashes.
The identifier also can not be the string cancel
.
The human-readble title for the script. Will be used for the button text and settings header.
A dictionary of values the user can feed into your script. The user can update these values in the OctoPrint settings dialog.
A callable taking as an argument your settings dict. Should return a string or list of strings that will be sent to the printer on connect.
This plugin also hooks into the OctoPrint Eventing system. Four new events are defined:
Fired when a script first starts.
payload keys:
id
: The id of the script that just started.title
: The title of the script that just started.
Fired when a script finishes.
payload keys:
id
: The id of the script that finished.title
: The title of the script that finished.result
: The values returned from the finished script.
Fired when a script encounter's an error.
payload keys:
id
: The id of the script that errored.title
: The title of the script that errored.error
: The error message from the script that errored.
Fired when a script's status message changes.
payload keys:
id
: The id of the script.title
: The title of the script.status
: The new status message.