QInstrumentRack#

class QInstrument.QInstrumentRack.QInstrumentRack(parent=None, instruments=None, editable=True, fake=False)[source]#

Bases: QWidget

A widget that holds multiple instrument widgets in a vertical layout.

The instrument list is persisted to ~/.QInstrument/QInstrumentRack.json via Configure. On first show, if no instruments were supplied at construction, the saved list is restored. On close, the current list is saved.

When editable is True (the default), the rack provides:

  • An “Add instrument…” toolbar button that opens a picker dialog listing all instruments found under instruments/.

  • A × close button overlaid on each slot to remove that instrument.

  • A ⋮ drag handle on each slot. Dragging highlights the target slot with a coloured bar and moves the dragged slot to that position on release.

Set editable to False to hide all of the above, for example when embedding the rack in an application where the instrument set should be fixed.

Parameters:
  • parent (QWidget | None) – Parent widget. Default: None.

  • instruments (list[str] | None) – Instrument names to load on construction. Each name is the bare instrument name without the Q prefix or Widget suffix (e.g. 'DS345'). Default: None (empty rack).

  • editable (bool) – If False, the toolbar, drag handles, and close buttons are all hidden. Default: True.

  • fake (bool) – If True, all instruments — including those added later via the “Add instrument…” dialog — use fake devices instead of probing for real hardware. Default: False.

property settings: dict#

instrument list as {'instruments': [...]}.

Getting returns instrument names in their current display order, preserving any reordering done by dragging. Setting clears the rack and reloads from the supplied dict.

Type:

dict

property editable: bool#

whether the user can add, remove, or reorder instruments.

When False, the toolbar, drag handles, and close buttons are all hidden. Defaults to True.

Type:

bool

addInstrument(instrument, name='')[source]#

Add an instrument widget instance to the rack.

Parameters:
  • instrument (QInstrumentWidget) – The instrument widget to add.

  • name (str) – Display name. Derived from the widget class name if omitted.

Return type:

None

addInstruments(instruments)[source]#

Add multiple instrument widget instances to the rack.

Parameters:

instruments (list[QInstrumentWidget]) – Instrument widget instances to add.

Return type:

None

addInstrumentByName(name, fake=False)[source]#

Add an instrument widget by its bare instrument name.

Searches manufacturer subdirectories under instruments/ for a package named name that contains a widget.py, then instantiates Q<name>Widget. Logs a warning and does nothing if the instrument or widget class cannot be found.

Parameters:
  • name (str) – Bare instrument name without the Q prefix or Widget suffix (e.g. 'DS345').

  • fake (bool) – If True, instantiate the widget with its fake device (from the sibling fake.py) instead of probing for real hardware. The widget will be fully enabled. Falls back to normal instantiation if no fake is available. Default: False.

Return type:

None

addInstrumentsByNames(names, fake=False)[source]#

Add multiple instruments by their bare names.

Parameters:
  • names (list[str] | None) – Bare instrument names to load. None is treated as an empty list.

  • fake (bool) – Passed to addInstrumentByName() for each name. Default: False.

Return type:

None

clearInstruments()[source]#

Remove and schedule deletion of all instrument widgets.

Return type:

None

classmethod availableInstruments()[source]#

Return names of all instruments that have a widget module.

Return type:

list[str]

Returns:

list[str] – Sorted list of bare instrument names.

showEvent(event)[source]#

Restore the instrument list on first show.

On the first show, if no instruments were loaded at construction, calls Configure.restore() to reload the previously saved instrument list.

Return type:

None

closeEvent(event)[source]#

Save the instrument list when the widget is closed.

Persists the current instrument list to ~/.QInstrument/QInstrumentRack.json. Only saves if the widget was previously shown, so test widgets closed during teardown do not overwrite saved configuration.

Return type:

None

classmethod example()[source]#

Display a rack populated with example instruments.

Accepts -f / --fake on the command line to load fake devices instead of probing for real hardware.

Return type:

None