stoner_measurement.plugins.command.base.CommandPlugin

class stoner_measurement.plugins.command.base.CommandPlugin(parent: QObject | None = None)[source]

Bases: QObject, BasePlugin

Abstract base class for sequence-engine command plugins.

A CommandPlugin performs a single action (e.g. saving data, sending data to a plot) during the sequence without connecting to or configuring any hardware. The generated sequence script calls only execute(); no connect(), configure(), or disconnect() calls are emitted for command plugins.

Subclasses must implement name and execute(). They may optionally override config_widget() to provide a settings UI — the instance-name editor and plugin-type label are added automatically at the top of the single configuration tab. They may also override to_json() and _restore_from_json() to persist configuration across sessions.

Variables:

instance_name_changed (pyqtSignal[str, str]) – Emitted when instance_name is reassigned, carrying the old and new names.

Keyword Parameters:

parent (QObject | None) – Optional Qt parent object.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command import CommandPlugin
>>> class _Noop(CommandPlugin):
...     @property
...     def name(self): return "Noop"
...     def execute(self): pass
>>> p = _Noop()
>>> p.plugin_type
'command'
>>> p.has_lifecycle
False
comment_changed

Qt signal.

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

types is normally a sequence of individual types.  Each type is either a
type object or a string that is the name of a C++ type.  Alternatively
each type could itself be a sequence of types each describing a different
overloaded signal.
name is the optional C++ name of the signal.  If it is not specified then
the name of the class attribute that is bound to the signal is used.
revision is the optional revision of the signal that is exported to QML.
If it is not specified then 0 is used.
arguments is the optional sequence of the names of the signal's arguments.
config_tabs(parent: QWidget | None = None) → list[tuple[str, QWidget]][source]

Return configuration tabs combining general and plugin-specific settings.

Overrides the base-class implementation so that command plugins present a single tab rather than separate General and plugin-specific tabs. The tab shows the instance-name editor and plugin-type label at the top (from _general_config_widget()), followed by a horizontal separator and then the plugin-specific widget returned by config_widget(). An optional About tab is appended when _about_html() returns non-None content.

Keyword Parameters:

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

Returns:

A list containing ("General", combined_widget) and optionally an About tab.

Return type:

(list[tuple[str, QWidget]])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command import CommandPlugin
>>> class _Noop(CommandPlugin):
...     @property
...     def name(self): return "Noop"
...     def execute(self): pass
>>> tabs = _Noop().config_tabs()
>>> len(tabs)
1
>>> tabs[0][0]
'General'
declared_outputs() → PluginOutputs[source]

Declare no outputs unless a concrete command supplies them.

disconnect(a0: QMetaObject.Connection) → bool
disconnect(self)
abstractmethod execute() → None[source]

Perform the command action.

Called by the generated sequence script once per sequence step occurrence. The method has access to the full sequence engine namespace via engine_namespace and can evaluate Python expressions against it using eval().

The plugin instance is also callable — invoking plugin() is equivalent to calling plugin.execute().

Raises:

Exception – Any exception raised here propagates to the sequence engine and is reported as a script error attributed to this plugin.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command import CommandPlugin
>>> class _Log(CommandPlugin):
...     @property
...     def name(self): return "Logger"
...     def execute(self):
...         self.log.info("sequence step reached")
>>> p = _Log()
>>> p.execute()  # no error when detached (uses fallback logger)
>>> p()          # equivalent — __call__ delegates to execute()
generate_action_code(indent: int, sub_steps: list, render_sub_step: Callable) → list[str][source]

Return the action code line for this command plugin.

Emits a single {instance_name}() call at the requested indentation level, followed by a blank separator line. The generated call invokes __call__(), which in turn delegates to execute().

Parameters:
  • indent (int) – Number of four-space indentation levels for the emitted lines.

  • sub_steps (list) – Ignored — CommandPlugin is always a leaf node.

  • render_sub_step (Callable) – Ignored — CommandPlugin is always a leaf node.

Returns:

A single () call line followed by a blank line.

Return type:

(list[str])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command import CommandPlugin
>>> class _Noop(CommandPlugin):
...     @property
...     def name(self): return "Noop"
...     def execute(self): pass
>>> p = _Noop()
>>> lines = p.generate_action_code(1, [], lambda s, i: [])
>>> lines[0]
'    noop()'
>>> lines[1]
''
property has_lifecycle: bool

Command plugins have no instrument lifecycle.

Returns:

Always False. The sequence engine therefore omits connect(), configure(), and disconnect() calls for this plugin when generating sequence code.

Return type:

(bool)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command import CommandPlugin
>>> class _Noop(CommandPlugin):
...     @property
...     def name(self): return "Noop"
...     def execute(self): pass
>>> _Noop().has_lifecycle
False
instance_name_changed

Qt signal.

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

types is normally a sequence of individual types.  Each type is either a
type object or a string that is the name of a C++ type.  Alternatively
each type could itself be a sequence of types each describing a different
overloaded signal.
name is the optional C++ name of the signal.  If it is not specified then
the name of the class attribute that is bound to the signal is used.
revision is the optional revision of the signal that is exported to QML.
If it is not specified then 0 is used.
arguments is the optional sequence of the names of the signal's arguments.
property plugin_type: str

Short tag identifying this plugin as a command.

Returns:

Always "command".

Return type:

(str)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command import CommandPlugin
>>> class _Noop(CommandPlugin):
...     @property
...     def name(self): return "Noop"
...     def execute(self): pass
>>> _Noop().plugin_type
'command'