stoner_measurement.plugins.monitor.base.MonitorPlugin

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

Bases: QObject, BasePlugin

Abstract base class for plugins that passively record experimental state.

A MonitorPlugin polls hardware at a configurable interval and emits data_available with the latest readings. Subclasses must implement name, quantity_names, units, and read().

The class provides:

  • Synchronous read — read() returns the latest reading as a {quantity: value} dict.

  • Autonomous polling — start_monitoring() starts an internal QTimer; stop_monitoring() stops it.

  • Reading cache — last_reading returns the most recent successful read() result without re-querying the hardware.

Variables:
  • data_available (pyqtSignal[dict]) – Emitted after each successful read() call with the reading dictionary as its argument.

  • read_error (pyqtSignal[str]) – Emitted with a descriptive message if read() raises an exception during polling.

  • _last_reading (dict[str, float]) – Internal cache updated after each successful read; exposed read-only via the last_reading property.

Keyword Parameters:

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

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _DummyMonitor(MonitorPlugin):
...     @property
...     def name(self): return "DummyMonitor"
...     @property
...     def quantity_names(self): return ["temperature"]
...     @property
...     def units(self): return {"temperature": "K"}
...     def read(self): return {"temperature": 300.0}
>>> m = _DummyMonitor()
>>> m.plugin_type
'monitor'
>>> m.monitor_interval
1000
>>> m.last_reading
{}
>>> m.read()
{'temperature': 300.0}
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 monitor configuration tabs with General first.

data_available

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.
declared_outputs() → PluginOutputs[source]

Declare monitor readings with their configured physical units.

disconnect(a0: QMetaObject.Connection) → bool
disconnect(self)
generate_action_code(indent: int, sub_steps: list, render_sub_step: Callable) → list[str][source]

Return action code lines that call read() and retain the result.

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

  • sub_steps (list) – Ignored for MonitorPlugin (leaf node).

  • render_sub_step (Callable) – Ignored for MonitorPlugin.

Returns:

Lines calling read() and assigning the reading dict to data.

Return type:

(list[str])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _M(MonitorPlugin):
...     @property
...     def name(self): return "M"
...     @property
...     def quantity_names(self): return ["v"]
...     @property
...     def units(self): return {"v": "au"}
...     def read(self): return {"v": 0.0}
>>> m = _M()
>>> lines = m.generate_action_code(1, [], lambda s, i: [])
>>> "    data = m.read()" in lines
True
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 last_reading: dict[str, float]

Cached result of the most recent successful read() call.

Returns an empty dict if read() has not been called yet (either directly or via the polling timer).

Returns:

Copy of the most recently cached reading.

Return type:

(dict[str, float])

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _TM(MonitorPlugin):
...     @property
...     def name(self): return "TM"
...     @property
...     def quantity_names(self): return ["v"]
...     @property
...     def units(self): return {"v": "au"}
...     def read(self): return {"v": 7.0}
>>> m = _TM()
>>> m.last_reading
{}
>>> _ = m.read()
>>> m.last_reading
{'v': 7.0}
property monitor_interval: int

Polling period in milliseconds used by start_monitoring().

Returns:

Interval in milliseconds; default 1000.

Return type:

(int)

property plugin_type: str

Short tag identifying this plugin as a monitor.

Returns:

Always "monitor".

Return type:

(str)

abstract property quantity_names: list[str]

Ordered list of quantity identifiers returned by read().

Returns:

Names matching the keys in the dict returned by read().

Return type:

(list[str])

abstractmethod read() → dict[str, float][source]

Perform a single synchronous hardware read and return the results.

Subclasses implement acquisition only. The base class wraps overrides to cache a copy and emit data_available once after a successful outermost read. Direct, timer and generated calls share this behaviour. Failed reads propagate without replacing the last successful reading; the polling callback additionally emits read_error.

Returns:

Mapping of quantity name to measured value.

Return type:

(dict[str, float])

Raises:

Exception – Any hardware communication error; callers should handle exceptions appropriately.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _ConstMonitor(MonitorPlugin):
...     @property
...     def name(self): return "Const"
...     @property
...     def quantity_names(self): return ["x"]
...     @property
...     def units(self): return {"x": "au"}
...     def read(self): return {"x": 42.0}
>>> m = _ConstMonitor()
>>> m.read()
{'x': 42.0}
read_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.
start_monitoring(interval_ms: int | None = None) → None[source]

Start the internal polling timer.

Calls read() every interval_ms milliseconds (or every monitor_interval milliseconds if interval_ms is None). Results are cached in last_reading and emitted via data_available. Errors from read() are emitted via read_error rather than propagated.

Keyword Parameters:

interval_ms (int | None) – Override for the polling interval in milliseconds. If None, monitor_interval is used.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _TM(MonitorPlugin):
...     @property
...     def name(self): return "TM"
...     @property
...     def quantity_names(self): return ["v"]
...     @property
...     def units(self): return {"v": "au"}
...     def read(self): return {"v": 1.0}
>>> m = _TM()
>>> m.start_monitoring(500)
>>> m._timer.isActive()
True
>>> m.stop_monitoring()
stop_monitoring() → None[source]

Stop the internal polling timer.

Examples

>>> from qtpy.QtWidgets import QApplication
>>> _ = QApplication.instance() or QApplication([])
>>> from stoner_measurement.plugins.monitor import MonitorPlugin
>>> class _TM(MonitorPlugin):
...     @property
...     def name(self): return "TM"
...     @property
...     def quantity_names(self): return ["v"]
...     @property
...     def units(self): return {"v": "au"}
...     def read(self): return {"v": 1.0}
>>> m = _TM()
>>> m.start_monitoring()
>>> m.stop_monitoring()
>>> m._timer.isActive()
False
abstract property units: dict[str, str]

Mapping of quantity name to physical unit string.

Returns:

E.g. {"temperature": "K", "pressure": "Pa"}.

Return type:

(dict[str, str])