stoner_measurement.plugins.command.alert.AlertCommand

class stoner_measurement.plugins.command.alert.AlertCommand(parent=None)[source]

Bases: CommandPlugin

Show a blocking message box during a sequence.

Use this command when you want the sequence to stop and wait for the user to acknowledge an important message. Typical uses include prompting the user to change a sample, check cryogen levels, confirm a manual wiring change, or simply acknowledge that a particular stage has completed.

In the configuration panel, set the message expression to the text you want to show. This can be a fixed string or a Python expression that builds a message from current sequence variables, for example:

"f'Measurement {run_index} complete — check sample temperature'"

The configuration tab otherwise only contains the standard instance-name field. The Help/About tab uses this docstring to explain both the purpose of the command and how the message expression is interpreted at runtime.

When the step runs, an alert dialog is shown and the sequence does not continue until the user presses OK.

Variables:
  • message_expr (str) – Python expression string that evaluates to the alert message at runtime. Defaults to "'Alert'".

  • show_alert (pyqtSignal[str]) – Emitted by execute() with the resolved message string. The execute() and __call__() methods also accept an optional keyword parameter message that, when provided, overrides the evaluated message_expr setting for that call. Connected with BlockingQueuedConnection to _display_alert() so that the sequence thread waits for the user to dismiss the dialog.

  • 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.

Examples

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

alert.message_expr = "'Check the sample wiring before continuing'"
config_widget(parent: QWidget | None = None) → QWidget[source]

Return a settings widget with a message-expression editor.

Displays a QFormLayout containing a QLineEdit that accepts a Python expression string for the alert message, and a brief description label.

Keyword Parameters:

parent (QWidget | None) – Optional Qt parent widget.

Returns:

The settings widget for the Settings tab.

Return type:

(QWidget)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.alert import AlertCommand
>>> from qtpy.QtWidgets import QWidget
>>> isinstance(AlertCommand().config_widget(), QWidget)
True
execute(*, message: str | None = None) → None[source]

Evaluate message_expr and display a blocking alert dialog.

Emits show_alert with the resolved message string, which triggers _display_alert() in the main thread via a BlockingQueuedConnection. The sequence thread is blocked until the user clicks OK.

Keyword Parameters:

message (str | None) – When provided, this string is used directly as the alert message, overriding the evaluated message_expr setting.

Raises:

RuntimeError – If the plugin is not attached to a sequence engine and message is not provided.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.alert import AlertCommand
>>> cmd = AlertCommand()
>>> cmd.message_expr = "'Test alert'"
property name: str

Unique identifier for the alert command.

Returns:

"Alert".

Return type:

(str)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.alert import AlertCommand
>>> AlertCommand().name
'Alert'
show_alert

Signal emitted by execute() — the resolved alert message string.

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

Serialise the alert command configuration to a JSON-compatible dict.

Returns:

Base dict from to_json() extended with "message_expr".

Return type:

(dict[str, Any])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.alert import AlertCommand
>>> d = AlertCommand().to_json()
>>> d["type"]
'command'
>>> "message_expr" in d
True