Skip to content

StateMachine

Base classes

Name Children Inherits
StateMixin
prettyqt.statemachine.state
QStateMachine
PySide6.QtStateMachine
QStateMachine(self, childMode: PySide6.QtStateMachine.QState.ChildMode, /, parent: PySide6.QtCore.QObject | None \= None, *, errorString: str | None \= None, globalRestorePolicy: PySide6.QtStateMachine.QState.RestorePolicy | None \= None, running: bool | None \= None, animated: bool | None \= None) -> None

⋔ Inheritance diagram

graph TD
  4107566309["statemachine.StateMachine"]
  351033638["statemachine.StateMixin"]
  2375005945["statemachine.AbstractStateMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  3179919832["QtStateMachine.QStateMachine"]
  825471685["QtStateMachine.QState"]
  1706596049["QtStateMachine.QAbstractState"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  351033638 --> 4107566309
  2375005945 --> 351033638
  3227531497 --> 2375005945
  2751680898 --> 3227531497
  2751680898 --> 2375005945
  2751680898 --> 351033638
  3179919832 --> 4107566309
  825471685 --> 3179919832
  1706596049 --> 825471685
  3984060476 --> 1706596049
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: StateMixin, QStateMachine

Source code in prettyqt/statemachine/statemachine.py
class StateMachine(statemachine.state.StateMixin, statemachine.QStateMachine):
    def _get_map(self):
        maps = super()._get_map()
        maps |= {"globalRestorePolicy": statemachine.state.RESTORE_POLICY}
        return maps

    def __add__(self, other: statemachine.QAbstractState) -> StateMachine:
        self.addState(other)
        return self

    def get_error(self) -> ErrorStr:
        return ERROR.inverse[self.error()]

    def post_event(
        self,
        event: QtCore.QEvent,
        priority: PriorityStr | statemachine.QStateMachine.EventPriority = "normal",
    ):
        self.postEvent(event, PRIORITY.get_enum_value(priority))

    def set_global_restore_policy(
        self,
        policy: statemachine.state.RestorePolicyStr | statemachine.State.RestorePolicy,
    ):
        """Set restore policy to use.

        Args:
            policy: restore policy to use
        """
        self.setGlobalRestorePolicy(
            statemachine.state.RESTORE_POLICY.get_enum_value(policy)
        )

    def get_global_restore_policy(self) -> statemachine.state.RestorePolicyStr:
        """Return current restore policy.

        Returns:
            restore policy
        """
        return statemachine.state.RESTORE_POLICY.inverse[self.globalRestorePolicy()]

get_global_restore_policy() -> statemachine.state.RestorePolicyStr

Return current restore policy.

Source code in prettyqt/statemachine/statemachine.py
def get_global_restore_policy(self) -> statemachine.state.RestorePolicyStr:
    """Return current restore policy.

    Returns:
        restore policy
    """
    return statemachine.state.RESTORE_POLICY.inverse[self.globalRestorePolicy()]

set_global_restore_policy(policy: statemachine.state.RestorePolicyStr | statemachine.State.RestorePolicy)

Set restore policy to use.

Parameters:

Name Type Description Default
policy RestorePolicyStr | RestorePolicy

restore policy to use

required
Source code in prettyqt/statemachine/statemachine.py
def set_global_restore_policy(
    self,
    policy: statemachine.state.RestorePolicyStr | statemachine.State.RestorePolicy,
):
    """Set restore policy to use.

    Args:
        policy: restore policy to use
    """
    self.setGlobalRestorePolicy(
        statemachine.state.RESTORE_POLICY.get_enum_value(policy)
    )

:fa-brands-github: Show source on GitHub