SGO Mistika: Python Extension
Loading...
Searching...
No Matches

The Cpython class provides functionality to manage Python Nodes. More...

Inheritance diagram for Cpython:
CbaseItem

Public Slots

Cconnector * addConnector (const QString &name, Cconnector::connectorType type, Cconnector::connectorMode mode)
 Adds a conector called name of type type and mode mode.
void addProperty (const QString &name, QVariant value=QVariant())
 Adds a property called name with default value value.
void addEncryptedProperty (const QString &name, QVariant value=QVariant())
 Adds an encrypted property to the node.
void setSupportedTypes (nodeType_t types)
 Sets the node types that this Python node supports.
QString getDropToProperty () const
 Returns the name of the property that will accept the drop file actions
an empty string disables the drop functionality.
void setDropToProperty (const QString &dropProperty)
 Assigns the name of the property that will accept the drop file actions
an empty value means no property is unassigned
.
int getDropSupportedTypes () const
 Returns the file types supported during the drop file actions.
QStringList getDropSupportedFileMasks () const
 Returns the list of File Masks supported by the node
An empty list accept all Files By default the list is empty.
void setDropSupportedTypes (int types)
 Set the File Types supported
.
void setDropSupportedFileMasks (const QStringList &dropSupportedFileMasks)
 Set the list of File Masks supported by the node
example: setDropSupportedFileMasks(["*.mov", "*.mp4"]).
void setAcceptConnectors (bool enabled, const QString &name, const QString label=QString())
 Enables/disables the ability to create connectors with drag and drop.
void rebuild ()
 Forces a call to the node init function.
void addActionToContextMenu (const QString &actionName)
 Adds an action to the Node Context Menu If there Action already exists, this function does nothing.
void removeActionFromContextMenu (const QString &actionName)
 Removes an action to the Node Context Menu If there Action does not exist, this function does nothing.
void setClassName (const QString &name)
 sets the Class name to display in the Finder The class ID will be the valid variable name related with this string (Removing space and other unsupported variable name characters) If this function is not called, the file Name will be used If called, it must be called from the init funcion.
bool addTemplateFromFile (const QString &filePath, const QString &property)
 adds a template manager for a property.
CpythonStore * getStore () const
 gets the node attribute's Store This repository can be used to store information inside the node
That information is persistant along multiple executions. So It is perfect to cache data that needs to be calculated only once. It can also be used to pass information between node functions (from init to process, or any other combination)
CexternalAppNodeLink * createExternalApp ()
 returns the new CexternalAppNodeLink instance
This link can be used to execute external applications from the python node using all the CexternalAppNodeLink functionality It is important to delete this instance when it is no longer needed by calling the deleteLater method
CexecutionQueue * createExecutionQueue (int maxThreads) const
 returns the new CexecutionQueue instance
This link can be used to Queue external applications to be multithreaded
It is important to delete this instance when it is no longer needed by calling the deleteLater method
bool addPermanentCritical (const QString &id, const QString &description, const QString &group=QString())
 Add a permanent critical error that will be reported when evaluating the isReady status. Permanent errors are stored and remain active until removed with clearAllPermanentErrors(), clearPermanentErrorById(), or clearPermanentErrorsByGroup().
bool addPermanentError (const QString &id, const QString &description, const QString &group=QString())
 Add a permanent error that will be reported when evaluating the isReady status. Permanent errors are stored and remain active until removed with clearAllPermanentErrors(), clearPermanentErrorById(), or clearPermanentErrorsByGroup().
void clearPermanentErrors ()
 Delete all permanent errors stored in the node.
void deletePermanentErrorById (const QString &id)
 Delete one permanent error with the specified id.
void deletePermanentErrorsByGroup (const QString &group)
 Delete all permanent errors included in the specified errors group.
Public Slots inherited from CbaseItem
QList< Cconnector * > getConnectors (Cconnector::connectorSpecialType special=Cconnector::CONNECTOR_SPECIALTYPE_NORMAL) const
 Returns the list of connectors available.
Cconnector * getFirstConnectorByName (const QString &name) const
 Returns the first connector found with a given name.
Cconnector * getFirstConnectorByType (Cconnector::connectorType type, const QString &name) const
 Returns the first connector found with a given type and name.
QList< Cconnector * > getConnectorsByName (const QString &name=QString()) const
 Returns the list of all connectors found with a given name This function returns a list of all connectors that match the specified name. If the name ends with '', it will match connectors with names that start with the prefix followed by a space and optional digits.
QList< Cconnector * > getConnectorsByName (const QRegularExpression &rx) const
 Returns the list of all connectors matching the given Regular Expression This function returns a list of all connectors that match the specified regular expression.
QList< Cconnector * > getConnectorsByType (Cconnector::connectorType type, const QString &name=QString()) const
 Returns the list of all connectors of the given type and matching the given name This function returns a list of all connectors that match both the specified type and name. If the name is empty, all connectors of the given type and special type will be returned.
QList< Cconnector * > getConnectorsByType (Cconnector::connectorType type, Cconnector::connectorSpecialType special, const QString &name=QString()) const
 Returns the list of all connectors of the given type and matching the given name.
QList< Cconnector * > getConnectorsByType (Cconnector::connectorType type, const QRegularExpression &rx) const
 Returns the list of all connectors of the given type and matching the given regular expression.
QList< Cconnector * > getConnectorsByType (Cconnector::connectorType type, Cconnector::connectorSpecialType special, const QRegularExpression &rx) const
 Returns the list of all connectors of the given type, special type and matching the given regular expression.
QList< Cconnector * > getVisibleConnectorsByType (Cconnector::connectorType type, const QString &name=QString(), Cconnector::connectorSpecialType specialType=Cconnector::CONNECTOR_SPECIALTYPE_ALL) const
 This function returns a list of all visible connectors that match the specified type, name, and special type. Connectors are filtered to only include those that are visible.
bool critical (const QString &identifier, const QString &description, const QString &property=QString()) const
 Reports a critical error.
bool error (const QString &identifier, const QString &description, const QString &property=QString()) const
 Reports an error.
bool warning (const QString &identifier, const QString &description, const QString &property=QString()) const
 Reports a warning message.
bool info (const QString &identifier, const QString &description, const QString &property=QString()) const
 Reports an information message.
QMap< QString, QVariant > getAllProperties () const
 Returns all the available Properties in the node.
void setPropertyVisible (const QString &propName, bool visible)
 CbaseItem::setPropertyVisible.
CnameConvention getNameConvention () const
 Returns the node name convention.
Cworkflow * getWorkflow () const
 Returns the workflow owner of the item.
CbaseItem * getRegisteredItem (const QString &id) const
 Gets a pointer to the registered version of a base Item This is a private function. do not use it unless you know what you are doing. the CbaseItem returned does not exist in any workflow instance, and it should be used carefully to access static funcctions only.
QList< CbaseItem * > getAllRegisteredNodes () const
 Gets a list of pointers to all the registered nodes
Function added in V10.12 This Function is equivalent to Workflows::getAllRegisteredNodes.
void dropConnector (Cconnector *connector) const
 emulates the behavior of droping a connector into the node
CuniversalPath composeDstFilePath (const QString &dstFilePath, const CuniversalPath &input, bool isSequence, int minPadFromInputs=0) const
 CbaseItem::composeDstFilePath.
void setPropertiesFromJson (const QJsonObject &json)
 set object properties from a json structure
void addRecentItem (const QString &id, const QVariant &value)
 Adds an item to the list of recent Items If this list is not empty, a submenu "recent files" will appear into the node contextual menu with links to the added values.
void setPropertiesFromUP (const CuniversalPath &up)
 set object properties from a json structure comming in the privateData of one UniversalPath
int getStatus () const
 Returns the latest registered status for the node
STATUS_UNKNOWN=-1, Unknown Status
STATUS_DISCONNECTED=0, The Item is disconnected
STATUS_OPTIONAL=1, The Item is optional (It does not need to be connected)
STATUS_CONNECTED=2, The Item is connected
STATUS_READY=3, The Item is ready to be processed
STATUS_PROCESSING=4, The Item is being processed
STATUS_FAILED=5, The process failed
STATUS_DONE=6 The process successfuly finished
.
QString getStatusName (int status) const
 CbaseItem::getStatusName.
QSet< QString > getTags ()
 getTags
void setTags (const QSet< QString > &newTags)
 setTags
bool addTag (const QString &tag)
 addTag
bool removeTag (const QString &tag)
 removeTag

Public Member Functions

virtual void workflowFinished (bool success) override
 If defined in Python, This function is called when the workflow finishes the execution.
virtual QVariant evaluate (const QString &exp) const override
 Allows the node to evaluate python code.
Public Member Functions inherited from CbaseItem
Cworkflow * findWorkflow () const
 Finds the workflow associated with this item.
CnameConvention getDefaultNameConvention () const
 Gets the default name convention for this item.
CuniversalPath fixUrlPathSimple (const QString &filePath, bool isSequence, bool filePathWithFrame=false) const
 Fixes a URL path using simple path fixing.
virtual CuniversalPath fixUrlPath (const QString &filePath) const
 Fixes a URL path This virtual function is used to complete the filePath when needed based on any external input such as connectors, etc. (adding the input fileName if local is empty, etc. The parent implementation (CfileHolder) returns the filePath as it is.
bool getFixChangesType () const

Additional Inherited Members

Public Types inherited from CbaseItem
enum  nodeType_t { NODETYPE_UNDEFINED =0x0 , NODETYPE_INPUT =0x01 , NODETYPE_TASK =0x2 , NODETYPE_OUTPUT =0x04 }
 The nodeType_t enum defines the different types a node can use.
Multiple values can be defined with a bitwise. i.e. NODETYPE_INPUT|NODETYPE_TASK for a node being in both Input and Task sections
. More...
Static Public Member Functions inherited from CbaseItem
static QList< CbaseItem * > getCopyFromItemList (const QList< CbaseItem * > &itemList, QObject *parentForCopy=nullptr)
static CnameConvention composeNameConvention (const CnameConvention &nc, const CnameConvention &defaultNC)
 Composes a name convention from two name conventions.
Protected Member Functions inherited from CbaseItem
CworkflowsMgr * findWorkflowsMgr () const
 Finds the workflows manager associated with this item.

Detailed Description

The Cpython class provides functionality to manage Python Nodes.

Creating a Node

To create a node, you need to generate three files:

  • A .py file (e.g., MyNode.py) Contains the node implementation. All properties are created in code (e.g. in init() via addProperty, addEncryptedProperty, etc.). Some properties may be internal and not exposed in the GUI.
  • An .xsd file (e.g., mynode.xsd) Defines the Property Editor UI for the node. Defines which properties are visible, their grouping/order, and which editor/control type is used (string, checkbox, pulldown, path, etc.). The XSD does not create properties; it only describes how already-defined properties are presented in the editor.
  • An .xml file (e.g., mynode.xml) Defines the default values used by the Node Preferences / Node Defaults system. IMPORTANT: This file should exist. Without it, the node will still work (falling back to code defaults), but the node properties will not appear in Node Preferences to edit their default values.

Naming Convention:

  • The .xsd and .xml files must have the same name as the .py file, but in lowercase and without spaces.
  • The .py file name determines the node's display name in the node finder unless overridden by the setClassName function. The .xsd and .xml files are used by the Property Editor and Node Defaults systems, so their base name must match the node identifier as described above.

Required Functions for a Node

Every Python-based node must define the following functions:

init(self)

  • Acts as the constructor of the node.
  • Creates and Initializes properties, connectors, and configuration settings.
  • Defines whether the node supports bypass, drop, etc.
  • Returns: True if the node is successfully initialized, False otherwise.

isReady(self)

  • Checks if the node has all necessary information for execution.
  • Ensures required properties have valid values.
  • Returns: True if the node is ready, False otherwise.

process(self)

  • The core execution function of the node.
  • Typically iterates through input connectors, processes data, and places the results in output connectors.
  • If an error occurs, it should be reported using addFailedUP.
  • Returns:
    • True if processing is successful.
    • False to stop the entire workflow execution in case of a critical failure.

Optional Functions

In addition to the required functions, the following optional functions can be implemented:

processDroppedFile(self, filePath)

  • Called when a file is dropped onto the node.
  • If not defined, the default behavior assigns filePath to a property using setDropToProperty("propertyName").
  • File type filtering can be set using setDropSupportedFileMasks(glob), e.g., "*.mov".

workflowFinished(self, success)

  • Called when the workflow execution is completed.
  • success indicates whether the workflow finished successfully.
  • Can be used for post-processing tasks.

onPropertyUpdated(self, name)

  • Called when a property value is updated.
  • The property name is passed as a parameter.
  • Important: Use try blocks to handle variable access, as this function may be called during node construction when not all properties are initialized.

onExternalAppHook(self, id, output, name, rx, line)

  • Called when an external application detects a line matching one of its hooks.

menuAction(self, actionName)

Additional Resources

For further details, refer to the official documentation: SGO Python API Documentation

The Cpython class provides functionality to manage Python Nodes.

The Cpython class extends Ctask to provide Python-based node functionality. It allows creating nodes with custom Python code that can be executed within the workflow system. This class handles the integration of Python code with the workflow system, including property management, connector handling, file drop operations, and execution queue management.

Member Function Documentation

◆ addActionToContextMenu

void Cpython::addActionToContextMenu ( const QString & actionName)
slot

Adds an action to the Node Context Menu If there Action already exists, this function does nothing.

Parameters
actionName

◆ addConnector

Cconnector * Cpython::addConnector ( const QString & name,
Cconnector::connectorType type,
Cconnector::connectorMode mode )
slot

Adds a conector called name of type type and mode mode.

Parameters
name
type
mode
Returns
A reference to the created Cconnector

◆ addEncryptedProperty

void Cpython::addEncryptedProperty ( const QString & name,
QVariant value = QVariant() )
slot

Adds an encrypted property to the node.

Encrypted properties can be included in the Property Editor via the node XSD like any other property. When shown in the GUI, they are displayed as a password/masked field (the clear-text value is never revealed). The value is stored encrypted when persisted (node defaults, projects, etc.), but can be accessed programmatically by the node at runtime.

Parameters
nameThe name of the property to add. If the name starts with an underscore (_), the property will be created as internal and will not be stored in the .mwf workflow file.
valueThe default value for the property (optional)

◆ addPermanentCritical

bool Cpython::addPermanentCritical ( const QString & id,
const QString & description,
const QString & group = QString() )
slot

Add a permanent critical error that will be reported when evaluating the isReady status. Permanent errors are stored and remain active until removed with clearAllPermanentErrors(), clearPermanentErrorById(), or clearPermanentErrorsByGroup().

Important: For errors in init, isReady, and process functions, use the regular critical and error methods instead. Permanent errors should only be used in functions that are not part of the core validation/execution process.

Parameters
idError ID
descriptionError description
groupOptional parameter used to group errors, so they can be removed later as a group
Returns
Same return value as the normal critical-error function

◆ addPermanentError

bool Cpython::addPermanentError ( const QString & id,
const QString & description,
const QString & group = QString() )
slot

Add a permanent error that will be reported when evaluating the isReady status. Permanent errors are stored and remain active until removed with clearAllPermanentErrors(), clearPermanentErrorById(), or clearPermanentErrorsByGroup().

Important: For errors in init, isReady, and process functions, use the regular critical and error methods instead. Permanent errors should only be used in functions that are not part of the core validation/execution process.

Parameters
idError ID
descriptionError description
groupOptional parameter used to group errors, so they can be removed later as a group
Returns
Same return value as the normal error function

◆ addProperty

void Cpython::addProperty ( const QString & name,
QVariant value = QVariant() )
slot

Adds a property called name with default value value.

Parameters
nameThe name of the property to add. If the name starts with an underscore (_), the property will be created as internal and will not be stored in the .mwf workflow file.
valueThe default value for the property (optional)

◆ addTemplateFromFile

bool Cpython::addTemplateFromFile ( const QString & filePath,
const QString & property )
slot

adds a template manager for a property.

Parameters
filePathto the template definition the obj file should look like this:
{ "myNodeProperty":
[
{"undefinedOption": {}},
{"option 1": {
"relatedProperty1": "property1 Value"
"relatedProperty2": "property2 Value",
}},
{"option 2": {
"relatedProperty1": "property1 Value"
"relatedProperty2": "property2 Value",
}}
]
}
This file will create a the following pull down:
"undefinedOption", "option 1", "option 2"

and selecting it will affect the properties:
"relatedProperty1" and "relatedProperty1"

Please notice the structure of "myNodeProperty" is an array of objects. The reason of using one array, is to preserve the order of the objects in the pull down list.
You can create an array of a single object, and add all the elements to it. but in that case the pull down list is not guranteed to maintain the file order
br> So, if you want to maintain the file order in the pulldown,it is recomended to create an array of single object elements.
propertyto attatch to In the previous file example, it it is "myNodeProperty"
Returns
true on success

◆ createExecutionQueue

CexecutionQueue * Cpython::createExecutionQueue ( int maxThreads) const
slot

returns the new CexecutionQueue instance
This link can be used to Queue external applications to be multithreaded
It is important to delete this instance when it is no longer needed by calling the deleteLater method

Parameters
maxThreads
Returns
a CexecutionQueue Object

◆ createExternalApp

CexternalAppNodeLink * Cpython::createExternalApp ( )
slot

returns the new CexternalAppNodeLink instance
This link can be used to execute external applications from the python node using all the CexternalAppNodeLink functionality It is important to delete this instance when it is no longer needed by calling the deleteLater method

Returns
a CexternalAppNodeLink Object

◆ deletePermanentErrorById

void Cpython::deletePermanentErrorById ( const QString & id)
slot

Delete one permanent error with the specified id.

Parameters
idto clear

◆ deletePermanentErrorsByGroup

void Cpython::deletePermanentErrorsByGroup ( const QString & group)
slot

Delete all permanent errors included in the specified errors group.

Parameters
groupto delete

◆ evaluate()

QVariant Cpython::evaluate ( const QString & exp) const
overridevirtual

Allows the node to evaluate python code.

Returns
The evaluation output.

Reimplemented from CbaseItem.

◆ getStore

CpythonStore * Cpython::getStore ( ) const
slot

gets the node attribute's Store This repository can be used to store information inside the node
That information is persistant along multiple executions. So It is perfect to cache data that needs to be calculated only once. It can also be used to pass information between node functions (from init to process, or any other combination)

Returns
a CpythonStore class with the attributes stores in the class

◆ removeActionFromContextMenu

void Cpython::removeActionFromContextMenu ( const QString & actionName)
slot

Removes an action to the Node Context Menu If there Action does not exist, this function does nothing.

Parameters
actionName

◆ setAcceptConnectors

void Cpython::setAcceptConnectors ( bool enabled,
const QString & name,
const QString label = QString() )
slot

Enables/disables the ability to create connectors with drag and drop.

Parameters
enabledboolean value to enable/Disable this mode
namethe connector name
labelthe label to use, if it is different to the name (Default value is name)

◆ setClassName

void Cpython::setClassName ( const QString & name)
slot

sets the Class name to display in the Finder The class ID will be the valid variable name related with this string (Removing space and other unsupported variable name characters) If this function is not called, the file Name will be used If called, it must be called from the init funcion.

Parameters
name

◆ setDropSupportedFileMasks

void Cpython::setDropSupportedFileMasks ( const QStringList & dropSupportedFileMasks)
slot

Set the list of File Masks supported by the node
example: setDropSupportedFileMasks(["*.mov", "*.mp4"]).

Parameters
dropSupportedFileMaskslist of masks to accept (i.e: ["jpg","jpeg"] if the list is empty, all Files are accepted To disable the acceptance set the dropToProperty name to empty an string

◆ setDropSupportedTypes

void Cpython::setDropSupportedTypes ( int types)
slot

Set the File Types supported
.

Parameters
typesbitwise of supported types:
1 = Directories 2 = Files

◆ setDropToProperty

void Cpython::setDropToProperty ( const QString & dropToProperty)
slot

Assigns the name of the property that will accept the drop file actions
an empty value means no property is unassigned
.

Parameters
dropToProperty

◆ setSupportedTypes

void Cpython::setSupportedTypes ( nodeType_t types)
slot

Sets the node types that this Python node supports.

Parameters
typesBitwise for the supported Node Types. The constants are defined in CbaseItem and the possible values are:
NODETYPE_INPUT=1
NODETYPE_TASK=2
NODETYPE_OUTPUT=4

◆ workflowFinished()

void Cpython::workflowFinished ( bool success)
overridevirtual

If defined in Python, This function is called when the workflow finishes the execution.

Parameters
successTrue if the workflow finished correctly

Generated for SGO Mistika: Python Extension by SGOdocBot