QAbstractInstrument#
- class QInstrument.lib.QAbstractInstrument.QAbstractInstrument(**kwargs)[source]#
Bases:
QObjectAbstract base class for scientific instruments.
Models instrument state as named properties registered via
registerProperty()and accessed through the thread-safeget()andset()slots. Methods are registered viaregisterMethod()and invoked by name viaexecute().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 = bool | int | float | 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
_namebacking-attribute convention: the getter readsself._nameand the setter writesptype(value)back toself._name. Pass an explicit callable to override either, or passsetter=Noneto make the property read-only.- Parameters:
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.
Nonemarks 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, orstr). 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:
- registerMethod(name, method)[source]#
Register a named zero-argument callable.
Registered methods can be invoked by name via
execute().
- 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 emitpropertyValuefor 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
QProscanfor an example.
- 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
propertyValuewith the name and value. Logs an error and returnsNoneif the key is not registered.
- 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
propertyValuewith 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:
- 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:
- Returns:
dict – Metadata dict (e.g.
ptype,minimum,maximum,step,debounce).