Skip to content

script_run_dialog

frog.gui.measure_script.script_run_dialog ¤

Provides a dialog to display the progress of a running measure script.

Classes¤

ScriptRunDialog(script_runner) ¤

Bases: QDialog

A dialog to display the progress of a running measure script.

Create a new ScriptRunDialog.

Parameters:

Name Type Description Default
script_runner ScriptRunner

The ScriptRunner managing the current script

required
Source code in frog/gui/measure_script/script_run_dialog.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(self, script_runner: ScriptRunner) -> None:
    """Create a new ScriptRunDialog.

    Args:
        script_runner: The ScriptRunner managing the current script
    """
    super().__init__()
    self.setWindowTitle("Running measure script")
    self.setModal(True)
    self.setMinimumSize(400, 100)

    # Keep a reference to prevent it being GC'd mid-run
    self._script_runner = script_runner

    self._stop_dlg = QMessageBox(
        QMessageBox.Icon.Warning,
        "Stop measure script?",
        "Do you want to cancel the currently running measure script?",
        QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
        self,
    )
    """A dialog to let the user confirm whether they want to cancel the script."""
    self._stop_dlg.accepted.connect(self.reject)

    layout = QVBoxLayout()
    self._progress_bar = QProgressBar()
    """Shows the progress of the measure script."""
    self._progress_bar.setMaximum(get_total_steps(script_runner.script))
    layout.addWidget(self._progress_bar)

    self._label = QLabel()
    """A text label describing what the measure script is currently doing."""
    layout.addWidget(self._label)

    self._pause_btn = QPushButton("Pause")
    self._pause_btn.setCheckable(True)
    self._pause_btn.clicked.connect(self._toggle_paused)

    buttonbox = QDialogButtonBox(QDialogButtonBox.StandardButton.Cancel)
    buttonbox.addButton(self._pause_btn, QDialogButtonBox.ButtonRole.ActionRole)
    buttonbox.rejected.connect(self._stop_dlg.show)
    self.rejected.connect(lambda: pub.sendMessage("measure_script.abort"))
    layout.addWidget(buttonbox)

    self.setLayout(layout)

    # Update dialog when measure script changes state
    pub.subscribe(self._on_start_moving, "measure_script.start_moving")
    pub.subscribe(self._on_start_measuring, "measure_script.start_measuring")
Functions¤
closeEvent(event) ¤

Abort the measure script.

Source code in frog/gui/measure_script/script_run_dialog.py
113
114
115
116
117
118
def closeEvent(self, event: QCloseEvent) -> None:
    """Abort the measure script."""
    if self.isVisible():
        # Make the user confirm before cancelling measure script
        event.ignore()
        self._stop_dlg.show()
hideEvent(event) ¤

Hide the dialog.

Source code in frog/gui/measure_script/script_run_dialog.py
120
121
122
123
def hideEvent(self, event: QHideEvent) -> None:
    """Hide the dialog."""
    super().hideEvent(event)
    self._stop_dlg.hide()
keyPressEvent(event) ¤

Intercept when user presses escape to confirm whether to close dialog.

Source code in frog/gui/measure_script/script_run_dialog.py
125
126
127
128
129
130
131
def keyPressEvent(self, event: QKeyEvent):
    """Intercept when user presses escape to confirm whether to close dialog."""
    if event.key() == Qt.Key.Key_Escape:
        # Show the confirmation dialog instead of directly closing
        self._stop_dlg.show()
    else:
        super().keyPressEvent(event)

Functions¤

get_total_steps(script) ¤

Get the total number of steps that a measure script will require.

Each Measurement is repeated n times, plus we have to move into position once per Measurement. The whole script is repeated m times.

Source code in frog/gui/measure_script/script_run_dialog.py
19
20
21
22
23
24
25
def get_total_steps(script: Script) -> int:
    """Get the total number of steps that a measure script will require.

    Each Measurement is repeated n times, plus we have to move into position once per
    Measurement. The whole script is repeated m times.
    """
    return script.repeats * sum(1 + m.measurements for m in script.sequence)