def __init__(self) -> None:
"""Create a new ScriptControl."""
super().__init__("Script control")
create_btn = QPushButton("Create new script")
create_btn.clicked.connect(self._create_btn_clicked)
edit_btn = QPushButton("Edit script")
edit_btn.clicked.connect(self._edit_btn_clicked)
self.script_path = OpenFileWidget(
initial_file_path=_get_previous_script_path(),
extension="yaml",
parent=self,
caption="Choose measure script to load",
dir=str(DEFAULT_SCRIPT_PATH),
)
run_btn = QPushButton("Run script")
run_btn.clicked.connect(self._run_btn_clicked)
run_btn.setEnabled(False)
self._enable_counter = EventCounter(
lambda: run_btn.setEnabled(True),
lambda: run_btn.setEnabled(False),
target_count=2,
device_names=(STEPPER_MOTOR_TOPIC,),
)
"""A counter to enable/disable the "Run" button."""
layout = QGridLayout()
layout.addWidget(create_btn, 0, 0)
layout.addWidget(edit_btn, 0, 1)
layout.addWidget(self.script_path, 1, 0)
layout.addWidget(run_btn, 1, 1)
self.setLayout(layout)
# Enable the run button when the spectrometer is connected and not already
# measuring and disable otherwise
self._spectrometer_ready = False
pub.subscribe(
self._on_spectrometer_status_changed,
f"device.{SPECTROMETER_TOPIC}.status",
)
pub.subscribe(
self._on_spectrometer_disconnect, f"device.closed.{SPECTROMETER_TOPIC}"
)
# Show/hide self.run_dialog on measure script begin/end
pub.subscribe(self._show_run_dialog, "measure_script.begin")
pub.subscribe(self._hide_run_dialog, "measure_script.end")
# Keep track of whether recording is taking place, so we can remind user to
# start recording
pub.subscribe(self._on_recording_start, "data_file.opened")
pub.subscribe(self._on_recording_stop, "data_file.close")
self._data_file_recording = False
"""Whether data file is currently being recorded."""
self.edit_dialog: ScriptEditDialog
"""A dialog for editing the contents of a measure script."""
self.run_dialog: ScriptRunDialog
"""A dialog showing the progress of a running measure script."""