QAbstractInstrument#

class QInstrument.lib.QAbstractInstrument.QAbstractInstrument(**kwargs)[source]#

Bases: QObject

Abstract base class for scientific instruments.

Models instrument state as named properties registered via registerProperty() and accessed through the thread-safe get() and set() slots. Methods are registered via registerMethod() and invoked by name via execute().

This class has no concept of hardware communication. A concrete transport subclass (e.g. QSerialInstrument) provides the I/O layer and higher-level communication helpers.

Signals#

propertyValue(str, object)

Emitted by get() and set() with the property name and its current value.

PropertyValue = bool | int | float | str#
Settings#

alias of dict[str, bool | int | float | str]

propertyValue#

alias of str

registerProperty(name, getter=<object object>, setter=<object object>, ptype=<class 'float'>, **meta)[source]#

Register a named instrument property.

By default both getter and setter are auto-generated from the _name backing-attribute convention: the getter reads self._name and the setter writes ptype(value) back to self._name. Pass an explicit callable to override either, or pass setter=None to make the property read-only.

Parameters:
  • name (str) – Property name used with get() and set().

  • getter (callable, optional) – Zero-argument callable returning the current value. Default: lambda: getattr(self, f'_{name}').

  • setter (callable or None, optional) – Single-argument callable that applies a new value. None marks the property read-only. Default: lambda v: setattr(self, f'_{name}', ptype(v)).

  • ptype (type, optional) – Python type of the property value (int, float, bool, or str). Used for default setter coercion and stored as metadata for UI generators. Default: float.

  • **meta – Arbitrary metadata stored alongside the property (e.g. minimum, maximum, step).

Return type:

None

registerMethod(name, method)[source]#

Register a named zero-argument callable.

Registered methods can be invoked by name via execute().

Parameters:
  • name (str) – Method name used with execute().

  • method (callable) – Zero-argument callable to invoke.

Return type:

None

property properties: list[str]#

Names of all registered instrument properties.

property settings: dict[str, bool | int | float | str]#

Current values of all writable registered properties.

Getting this property calls every qualifying getter, which may issue instrument queries. A property qualifies when its setter is not None (writable).

Setting it calls each registered setter for keys present in the supplied dict, skipping unknown keys and read-only properties. Unlike set(), the setter does not emit propertyValue for each key; call _syncProperties() after a bulk restore if the UI must reflect the new values.

Subclasses that need to exclude specific properties from save/restore (e.g. motion-speed parameters that must not be silently overwritten on reconnect) should override both the getter and setter to filter those names. See QProscan for an example.

property methods: list[str]#

Names of all registered instrument methods.

get(key)#

Return the current value of a registered property.

Thread-safe Qt slot. The registry lock is released before calling the getter, so the getter may safely call other instrument methods without deadlocking. Emits propertyValue with the name and value. Logs an error and returns None if the key is not registered.

Parameters:

key (str) – Registered property name.

Return type:

bool | int | float | str | None

Returns:

PropertyValue or None – Current value, or None if key is unknown.

set(key, value)#

Set a registered property to the given value.

Thread-safe Qt slot. The registry lock is released before calling the setter, so the setter may safely call other instrument methods without deadlocking. Emits propertyValue with the new value on success. Logs a warning if the property is read-only and an error if the key is not registered.

Parameters:
  • key (str) – Registered property name.

  • value (PropertyValue) – New value to assign.

Return type:

None

propertyMeta(name)[source]#

Return a copy of the metadata for a registered property.

Returns an empty dict if name is not registered. Excludes the internal getter and setter callables.

Parameters:

name (str) – Registered property name.

Return type:

dict

Returns:

dict – Metadata dict (e.g. ptype, minimum, maximum, step, debounce).

execute(key)#

Call a registered method by name.

Thread-safe Qt slot. Logs an error if the key is not registered.

Parameters:

key (str) – Registered method name.

Return type:

None