stoner_measurement.plugins.command.if_command.IfCommand

class stoner_measurement.plugins.command.if_command.IfCommand(parent=None, condition: str = 'True')[source]

Bases: CommandPlugin, SequencePlugin

Run nested sequence steps only when a Python expression is truthy.

Use this command as a branch in the sequence tree when only some nested actions should run for a point, segment, or step. The expression is evaluated against the live sequence namespace, so conditions can reference any plugin instance or variable already available to the generated script.

On General, enter Condition, a Python expression such as counter.value > 0. A blank condition is treated as True. Place the steps to run beneath this command in the sequence tree. The expression is evaluated each time execution reaches the branch; an empty branch does nothing. Calling execute() directly does nothing: the generated sequence supplies the conditional block. This command has no outputs.

Variables:
  • condition (str) – Runtime condition; defaults to “True”.

  • instance_name (str) – Inherited Python identifier for this instance in the Script tab and QtConsole.

  • comment (str) – Inherited optional note displayed beside this step.

  • sequence_engine (SequenceEngine | None) – Inherited owning engine and its live namespace; None while detached.

Keyword Parameters:
  • parent (QObject | None) – Optional Qt parent object.

  • condition (str) – Initial condition; defaults to “True”.

Examples

With an instance named if_command in the sequence, use the QtConsole to inspect or edit it before running. Substitute your instance name if different; result data reflects completed steps:

if_command.condition = "counter.value > 0"
config_widget(parent: QWidget | None = None) → QWidget[source]

Return the condition editor widget.

execute() → None[source]

No-op leaf execution.

IfCommand is intended to be used as a sequence container. If it is accidentally run as a leaf command it has no side effects.

execute_sequence(sub_steps: list) → None[source]

Run sub_steps when condition evaluates truthy.

generate_action_code(indent: int, sub_steps: list, render_sub_step: Callable) → list[str][source]

Return an if block containing the rendered sub-steps.

An empty If container is treated as a no-op to avoid emitting a branch with no executable body into generated scripts.

property name: str

Human-readable name for the command.

to_json() → dict[str, Any][source]

Serialise the condition command.