PySide6.QtScxml.QScxmlStateMachine¶
- class QScxmlStateMachine¶
The
QScxmlStateMachine
class provides an interface to the state machines created from SCXML files. More…Synopsis¶
Properties¶
dataModelᅟ
- Data model to be used for this state machineinitialValuesᅟ
- Initial values to be used for setting up the data modelinitializedᅟ
- Whether the state machine has been initializedinvokedᅟ
- Whether the state machine was invoked from an outer state machineinvokedServicesᅟ
- A list of SCXML services that were invoked from the main state machine (possibly recursively)loaderᅟ
- That is currently used to resolve and load URIs for the state machinenameᅟ
- Of the state machine as set by the name attribute of the <scxml> tagparseErrorsᅟ
- List of parse errors that occurred while creating a state machine from an SCXML filerunningᅟ
- The running state of this state machinesessionIdᅟ
- Session ID of the current state machinetableDataᅟ
- Table data that is used when generating C++ from an SCXML file
Methods¶
def
__init__()
def
connectToEvent()
def
connectToState()
def
dataModel()
def
initialValues()
def
isActive()
def
isInitialized()
def
isInvoked()
def
isRunning()
def
loader()
def
name()
def
parseErrors()
def
sessionId()
def
setDataModel()
def
setLoader()
def
setRunning()
def
setTableData()
def
stateNames()
def
submitEvent()
def
tableData()
Slots¶
Signals¶
def
finished()
def
loaderChanged()
def
log()
def
runningChanged()
Static functions¶
def
fromData()
def
fromFile()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
QScxmlStateMachine
is an implementation of the State Chart XML (SCXML) .All states that are defined in the SCXML file are accessible as properties of
QScxmlStateMachine
. These properties are boolean values and indicate whether the state is active or inactive.Note
The
QScxmlStateMachine
needs a QEventLoop to work correctly. The event loop is used to implement thedelay
attribute for events and to schedule the processing of a state machine when events are received from nested (or parent) state machines.Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property dataModelᅟ: QScxmlDataModel¶
This property holds The data model to be used for this state machine..
SCXML data models are described in SCXML Specification - 5 Data Model and Data Manipulation . For more information about supported data models, see SCXML Compliance .
Changing the data model when the state machine has been
initialized
is not specified in the SCXML standard and leads to undefined behavior.- Access functions:
- property initialValuesᅟ: Dictionary with keys of type .QString and values of type QVariant.¶
This property holds The initial values to be used for setting up the data model..
See also
- Access functions:
- property initializedᅟ: bool¶
This property holds Whether the state machine has been initialized..
It is
true
if the state machine has been initialized,false
otherwise.See also
- Access functions:
- property invokedᅟ: bool¶
This property holds Whether the state machine was invoked from an outer state machine..
true
when the state machine was started as a service with the<invoke>
element,false
otherwise.- Access functions:
- property invokedServicesᅟ: list of QScxmlInvokableService¶
This property holds A list of SCXML services that were invoked from the main state machine (possibly recursively)..
- Access functions:
This property holds The loader that is currently used to resolve and load URIs for the state machine..
- Access functions:
Signal
loaderChanged()
- property nameᅟ: str¶
This property holds The name of the state machine as set by the name attribute of the
<scxml>
tag..- Access functions:
- property parseErrorsᅟ: list of QScxmlError¶
This property holds The list of parse errors that occurred while creating a state machine from an SCXML file..
- Access functions:
- property runningᅟ: bool¶
This property holds the running state of this state machine.
See also
- Access functions:
- property sessionIdᅟ: str¶
This property holds The session ID of the current state machine..
The session ID is used for message routing between parent and child state machines. If a state machine is started by an
<invoke>
element, any event it sends will have theinvokeid
field set to the session ID. The state machine will use the origin of an event (which is set by the target or targetexpr attribute in a<send>
element) to dispatch messages to the correct child state machine.See also
- Access functions:
- property tableDataᅟ: QScxmlTableData¶
This property holds The table data that is used when generating C++ from an SCXML file..
The class implementing the state machine will use this property to assign the generated table data. The state machine does not assume ownership of the table data.
- Access functions:
- __init__(metaObject[, parent=None])¶
- Parameters:
metaObject –
QMetaObject
parent –
QObject
- activeStateNames([compress=true])¶
- Parameters:
compress – bool
- Return type:
list of strings
Retrieves a list of state names of all active states.
When a state is active, all its parent states are active by definition. When
compress
istrue
(the default), the parent states will be filtered out and only the leaf states will be returned. When it isfalse
, the full list of active states will be returned.- cancelDelayedEvent(sendId)¶
- Parameters:
sendId – str
Cancels a delayed event with the specified
sendId
.- connectToEvent(scxmlEventSpec, receiver, method[, type=Qt.AutoConnection])¶
- Parameters:
scxmlEventSpec – str
receiver –
QObject
method – str
type –
ConnectionType
- Return type:
Creates a connection of the specified
type
from the event specified byscxmlEventSpec
to themethod
in thereceiver
object. The receiver’smethod
may take aQScxmlEvent
as a parameter. For example:void mySlot(const QScxmlEvent &event);
In contrast to event specifications in SCXML documents, spaces are not allowed in the
scxmlEventSpec
here. In order to connect to multiple events with different prefixes,connectToEvent()
has to be called multiple times.Returns a handle to the connection, which can be used later to disconnect.
- connectToState(scxmlStateName, receiver, method[, type=Qt.AutoConnection])¶
- Parameters:
scxmlStateName – str
receiver –
QObject
method – str
type –
ConnectionType
- Return type:
Creates a connection of the given
type
from the state identified byscxmlStateName
to themethod
in thereceiver
object. The receiver’smethod
may take a boolean argument that indicates whether the state connected became active or inactive. For example:void mySlot(bool active);
Returns a handle to the connection, which can be used later to disconnect.
- dataModel()¶
- Return type:
Returns the data model used by the state machine.
See also
Getter of property
dataModelᅟ
.- dataModelChanged(model)¶
- Parameters:
model –
QScxmlDataModel
Notification signal of property
dataModelᅟ
.- finished()¶
This signal is emitted when the state machine reaches a top-level final state.
See also
running
Creates a state machine by reading from the QIODevice specified by
data
.This method will always return a state machine. If errors occur while reading the SCXML file,
fileName
, the state machine cannot be started. The errors can be retrieved by calling theparseErrors()
method.See also
- static fromFile(fileName)¶
- Parameters:
fileName – str
- Return type:
Creates a state machine from the SCXML file specified by
fileName
.This method will always return a state machine. If errors occur while reading the SCXML file, the state machine cannot be started. The errors can be retrieved by calling the
parseErrors()
method.See also
- init()¶
- Return type:
bool
Initializes the state machine.
State machine initialization consists of calling
setup()
, setting the initial values for<data>
elements, and executing any<script>
tags of the<scxml>
tag. The initial data values are taken from theinitialValues
property.Returns
false
if parse errors occur or if any of the initialization steps fail. Returnstrue
otherwise.- initialValues()¶
- Return type:
Dictionary with keys of type .QString and values of type QVariant.
See also
Getter of property
initialValuesᅟ
.- initialValuesChanged(initialValues)¶
- Parameters:
initialValues – Dictionary with keys of type .QString and values of type QVariant.
Notification signal of property
initialValuesᅟ
.- initializedChanged(initialized)¶
- Parameters:
initialized – bool
Notification signal of property
initializedᅟ
.- invokedServices()¶
- Return type:
.list of QScxmlInvokableService
Getter of property
invokedServicesᅟ
.- invokedServicesChanged(invokedServices)¶
- Parameters:
invokedServices – .list of QScxmlInvokableService
Notification signal of property
invokedServicesᅟ
.- isActive(scxmlStateName)¶
- Parameters:
scxmlStateName – str
- Return type:
bool
Returns
true
if the state specified byscxmlStateName
is active,false
otherwise.- isActive(stateIndex)
- Parameters:
stateIndex – int
- Return type:
bool
Returns
true
if the state with the IDstateIndex
is active.This method is part of the interface to the compiled representation of SCXML state machines. It should only be used internally and by state machines compiled from SCXML documents.
- isDispatchableTarget(target)¶
- Parameters:
target – str
- Return type:
bool
Returns
true
if a message totarget
can be dispatched by this state machine.Valid targets are:
#_parent
for the parent state machine if the current state machine is started by<invoke>
#_internal
for the current state machine#_scxml_sessionid
, wheresessionid
is the session ID of the current state machine#_servicename
, whereservicename
is the ID or name of a service started with<invoke>
by this state machine
- isInitialized()¶
- Return type:
bool
Getter of property
initializedᅟ
.- isInvoked()¶
- Return type:
bool
Getter of property
invokedᅟ
.- isRunning()¶
- Return type:
bool
Returns
true
if the state machine is running,false
otherwise.See also
Getter of property
runningᅟ
.- loader()¶
- Return type:
See also
Getter of property
loaderᅟ
.Notification signal of property
loaderᅟ
.- log(label, msg)¶
- Parameters:
label – str
msg – str
This signal is emitted if a
<log>
tag is used in the SCXML.label
is the value of the label attribute of the<log>
tag.msg
is the value of the evaluated expr attribute of the<log>
tag. If there is no expr attribute, a null string will be returned.- name()¶
- Return type:
str
Getter of property
nameᅟ
.- parseErrors()¶
- Return type:
.list of QScxmlError
Getter of property
parseErrorsᅟ
.- reachedStableState()¶
This signal is emitted when the event queue is empty at the end of a macro step or when a final state is reached.
- runningChanged(running)¶
- Parameters:
running – bool
This signal is emitted when the
running
property is changed withrunning
as argument.Notification signal of property
runningᅟ
.- sessionId()¶
- Return type:
str
Getter of property
sessionIdᅟ
.- setDataModel(model)¶
- Parameters:
model –
QScxmlDataModel
Sets the data model for this state machine to
model
. There is a 1:1 relation between state machines and models. After setting the model once you cannot change it anymore. Any further attempts to set the model using this method will be ignored.See also
Setter of property
dataModelᅟ
.- setInitialValues(initialValues)¶
- Parameters:
initialValues – Dictionary with keys of type .QString and values of type QVariant.
See also
Setter of property
initialValuesᅟ
.Setter of property
loaderᅟ
.- setRunning(running)¶
- Parameters:
running – bool
Starts the state machine if
running
istrue
, or stops it otherwise.See also
Setter of property
runningᅟ
.- setTableData(tableData)¶
- Parameters:
tableData –
QScxmlTableData
See also
Setter of property
tableDataᅟ
.- start()¶
Starts this state machine. When a final top-level state is entered, the machine will emit the
finished()
signal.Note
A state machine will not run without a running event loop, such as the main application event loop started with QCoreApplication::exec() or QApplication::exec().
Note
Calling start() after
stop()
will not result in a full reset of its configuration yet, hence it is strongly advised not to do it.Note
Starting a finished machine yields a warning.
See also
- stateNames([compress=true])¶
- Parameters:
compress – bool
- Return type:
list of strings
Retrieves a list of state names of all states.
When
compress
istrue
(the default), the states that contain child states will be filtered out and only the leaf states will be returned. When it isfalse
, the full list of all states will be returned.The returned list does not contain the states of possible nested state machines.
Note
The order of the state names in the list is the order in which the states occurred in the SCXML document.
- stop()¶
Stops this state machine. The machine will not execute any further state transitions. Its
running
property is set tofalse
.See also
- submitEvent(event)¶
- Parameters:
event –
QScxmlEvent
Submits the SCXML event
event
to the internal or external event queue depending on the priority of the event.When a delay is set, the event will be queued for delivery after the timeout has passed. The state machine takes ownership of
event
and deletes it after processing.- submitEvent(eventName)
- Parameters:
eventName – str
A utility method to create and submit an external event with the specified
eventName
as the name.- submitEvent(eventName, data)
- Parameters:
eventName – str
data – object
A utility method to create and submit an external event with the specified
eventName
as the name anddata
as the payload data.- tableData()¶
- Return type:
See also
Getter of property
tableDataᅟ
.- tableDataChanged(tableData)¶
- Parameters:
tableData –
QScxmlTableData
Notification signal of property
tableDataᅟ
.