stoner_measurement.plugins.command.details.DetailsCommand

class stoner_measurement.plugins.command.details.DetailsCommand(parent=None)[source]

Bases: CommandPlugin

Store user, sample, project, and notes information for a measurement.

Use this command near the start of a sequence to record the basic details that identify a run: who is performing it, which sample is being measured, which project it belongs to, and any free-form notes. This information is intended to be filled in from the configuration panel and then reused by later steps such as saving or labelling data.

When this command executes in the application, the window title also shows the user, project and sample alongside the sequence filename. The most recently executed Details command supplies these values.

In normal use, fill in User, Sample, and Project before running. These are treated as required fields. The Project field is pre-populated from top-level folders in the configured default data directory, but you can still type your own value. Notes can be used for anything that may help interpret the data later.

For script-oriented use, this plugin behaves a little differently from most command plugins. The generated sequence code does not call {instance_name}(). Instead it emits four attribute-assignment statements so that the values are set on the plugin instance in the engine namespace:

details.user = "Alice"
details.sample = "Nb_film_001"
details.project = "NbSC"
details.notes = "Cooled overnight; base pressure 5e-7 mbar."

The date, time, and rig attributes are read-only runtime properties rather than configuration fields. date and time return the current local date and time when accessed, while rig reads the local rig name from the application configuration.

Additional metadata can be configured on the Metadata tab as a name and Python value expression. Generated sequence code evaluates those expressions in the engine namespace and assigns the results as attributes on this instance. For example, a metadata row named temperature can be read by later sequence steps as details.temperature (or through the configured instance_name). The configured rows themselves are available through metadata_expressions.

Variables:
  • user (str) – Name of the person performing the measurement.

  • sample (str) – Identifier for the sample under test.

  • project (str) – Project name. The configuration combo box is pre-populated with the top-level subdirectories of the application default data directory (as configured in the application settings).

  • notes (str) – Free-form notes about the measurement.

  • date (str) – Read-only current local date in YYYYMMDD form.

  • time (str) – Read-only current local time in HHmmss form.

  • rig (str) – Read-only rig name from the local application configuration.

  • metadata_expressions (list[dict[str, str]]) – Additional attribute names and value expressions. Each entry has "name" and "expression" keys; generated code exposes the evaluated value as an attribute named by "name".

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

This design allows later sequence steps and data-saving plugins to read the metadata directly from the instance, for example details.sample or details.project.

Keyword Parameters:

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

Examples

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

details.sample = "Nb_film_001"
details.project = "Transport"
details.date
config_tabs(parent: QWidget | None = None) → list[tuple[str, QWidget]][source]

Return General, Metadata, and standard optional About tabs.

config_widget(parent: QWidget | None = None) → QWidget[source]

Return a settings widget with user, sample, project, and notes fields.

The widget contains a QFormLayout with:

  • A QLineEdit for the operator name.

  • A QLineEdit for the sample identifier.

  • An editable QComboBox for the project name, pre-populated with the top-level subdirectories of the application default data directory.

  • A QPlainTextEdit for free-form notes.

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.details import DetailsCommand
>>> isinstance(DetailsCommand().config_widget(), QWidget)
True
configure() → None[source]

Validate the configured details fields used by generated scripts.

property date: str

Current local date formatted as YYYYMMDD.

eval_metadata(expression: str) → Any[source]

Evaluate a metadata value, treating unknown identifiers as literal text.

Metadata is deliberately more forgiving than other runtime expression fields. A bare unquoted string is valid Python syntax, so the shared eval() path raises NameError rather than using its syntax-error fallback. For metadata only, warn and retry the original text as a quoted string. The retry still uses the shared evaluator, preserving runtime f-string interpolation for replacement fields.

Parameters:

expression (str) – Stored metadata expression or free-form literal text.

Returns:

Evaluated expression or literal-string fallback.

Return type:

(Any)

execute() → None[source]

Validate the stored metadata when the command is invoked directly.

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

Return attribute-assignment code lines for this plugin.

Instead of a {instance_name}() call, emits four assignment statements that set the metadata attributes on the plugin instance in the engine namespace. Additional metadata values are assigned through eval_metadata(), which delegates to the shared runtime evaluator so genuine Python expressions use the live engine namespace while syntactically invalid text follows the quoted-string and runtime f-string fallback. Metadata also treats an unknown identifier as likely unquoted literal text after logging a warning. A configure() call and blank separator line follow the assignments.

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

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

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

Returns:

Four fixed-detail assignments, any evaluated metadata assignments, one configure() call, and a trailing blank line.

Return type:

(list[str])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.details import DetailsCommand
>>> cmd = DetailsCommand()
>>> cmd.user = "Alice"
>>> cmd.sample = "Nb_001"
>>> cmd.project = "NbSC"
>>> cmd.notes = "Test run"
>>> lines = cmd.generate_action_code(0, [], lambda s, i: [])
>>> lines[0]
'details.user = "Alice"'
>>> lines[1]
'details.sample = "Nb_001"'
>>> lines[2]
'details.project = "NbSC"'
>>> lines[3]
'details.notes = "Test run"'
>>> lines[4]
'details.configure()'
>>> lines[5]
''
property name: str

Unique display name for the details command.

Returns:

"Details".

Return type:

(str)

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.details import DetailsCommand
>>> DetailsCommand().name
'Details'
property rig: str

Return the rig name from this machine’s application configuration.

show_validation_error

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 time: str

Current local time formatted as HHmmss at access time.

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

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

Returns:

Base dict from to_json() extended with "user", "sample", "project", and "notes".

Return type:

(dict[str, Any])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.command.details import DetailsCommand
>>> d = DetailsCommand().to_json()
>>> d["type"]
'command'
>>> all(k in d for k in ("user", "sample", "project", "notes"))
True