Bases: QDialog
A dialog to create and edit measure scripts.
Create a new ScriptEditDialog.
Parameters:
Name |
Type |
Description |
Default |
script
|
Script | None
|
A loaded measure script or None
|
None
|
Source code in frog/gui/measure_script/script_edit_dialog.py
29
30
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 | def __init__(self, script: Script | None = None) -> None:
"""Create a new ScriptEditDialog.
Args:
script: A loaded measure script or None
"""
super().__init__()
self.setWindowTitle("Edit measurement script")
self.setModal(True)
initial_save_path: Path | None = None
if script:
self.count = CountWidget("Repeats", script.repeats)
self.sequence_widget = SequenceWidget(script.sequence)
initial_save_path = script.path
else:
self.count = CountWidget("Repeats")
self.sequence_widget = SequenceWidget()
self.script_path = SaveFileWidget(
initial_save_path,
extension="yaml",
parent=self,
caption="Choose destination for measure script",
dir=str(DEFAULT_SCRIPT_PATH),
)
# Put a label next to the script path
script_widget = QWidget()
script_layout = QFormLayout()
script_layout.addRow("Script file path:", self.script_path)
script_widget.setLayout(script_layout)
self.buttonBox = QDialogButtonBox(
QDialogButtonBox.StandardButton.Save
| QDialogButtonBox.StandardButton.Cancel
)
self.buttonBox.setCenterButtons(True)
self.buttonBox.accepted.connect(self._try_accept)
self.buttonBox.rejected.connect(self.reject)
layout = QVBoxLayout()
layout.addWidget(self.count)
layout.addWidget(self.sequence_widget)
layout.addWidget(script_widget)
layout.addWidget(self.buttonBox)
self.setLayout(layout)
|
Functions
closeEvent(event)
Check for unsaved data and if necessary save it.
Source code in frog/gui/measure_script/script_edit_dialog.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 | def closeEvent(self, event: QCloseEvent) -> None:
"""Check for unsaved data and if necessary save it."""
# Just close if the dialog is already closed or there aren't any instructions
# See bug: https://bugreports.qt.io/browse/QTBUG-43344
if not self.isVisible() or not self.sequence_widget.sequence:
self.setResult(QDialog.DialogCode.Accepted)
return
msg_box = QMessageBox(
QMessageBox.Icon.Question,
"Changes not saved",
"Do you want to save your changes?",
QMessageBox.StandardButton.Save
| QMessageBox.StandardButton.Discard
| QMessageBox.StandardButton.Cancel,
)
ret = msg_box.exec()
if ret == QMessageBox.StandardButton.Discard:
self.setResult(QDialog.DialogCode.Rejected)
elif ret == QMessageBox.StandardButton.Save and self._try_save():
self.setResult(QDialog.DialogCode.Accepted)
else:
# User cancelled; leave this dialog open
event.ignore()
|