|
SGO Mistika: Python Extension
|
Copyright © 2019+ SGO (Soluciones Gráficas por Ordenador SL)
All Rights Reserved.
This documentation provides a complete guide to creating Python nodes for Workflows. It covers everything from basic concepts to advanced patterns and best practices.
Python nodes in Workflows are the core building blocks that define custom functionality within workflows. They are implemented as Python files that define specific functions to handle initialization, readiness checking, and processing logic.
This documentation is organized into several key sections:
To create a new Python node:
Every Python node must implement three required functions:
Called when the node is initialized. This is where you set up the node's properties, connectors, and other configurations.
Called before process to check if the node is ready to process. Returns True if ready, False if not ready, or use self.critical() for error messages.
Contains the main logic of the node. This is where the actual work happens.
Properties are defined using self.addProperty(name, defaultValue) and can be accessed directly as self.property_name. Properties are exposed in the node editor through the corresponding XSD schema file.
Connectors are used to connect nodes in a workflow:
Cconnector.CONNECTOR_TYPE_INPUT - Input connectorCconnector.CONNECTOR_TYPE_OUTPUT - Output connectorCconnector.MODE_OPTIONAL - Optional connectorCconnector.MODE_REQUIRED - Mandatory connectorEach node consists of:
MyNode.py) - Node implementation. All properties are created in code (typically in init() via addProperty(), addEncryptedProperty(), etc.). Some properties may be internal and not exposed in the GUI.mynode.xsd) - Property Editor schema. Defines how existing properties are presented in the GUI (visibility, grouping, ordering, and editor/control type). The XSD does not create properties.mynode.xml) Node Defaults (Node Preferences). Defines the default values used by the Node Preferences / Node Defaults system. Without this file, node defaults cannot be edited from Node Preferences (the node will fall back to defaults defined in code)Name Convention The .xsd and .xml base name must match the node identifier: same as the .py file name, lowercase and without spaces. The display name in the Finder can be overridden with setClassName() (must be called from init()).
Nodes should be tested in actual workflows:
self.critical() for critical errorsself.isCancelled() regularly to support cancellationself.setComplexity() for accurate progress reportingCommon issues:
Always check the workflow logs for error messages when debugging node issues.
Creating Python nodes for Workflows is a powerful way to extend functionality. By following the patterns and best practices outlined in this documentation, you can create robust, efficient, and maintainable nodes that integrate seamlessly with the existing workflows system.
The key is to understand the API, follow established patterns, and test thoroughly in actual workflow scenarios.