Skip to content

Commit e629de4

Browse files
committed
Added pop-up warning windows
Warning windows appear to ask for confirmation to: stop the ongoing measurement; exit the program
1 parent 9804675 commit e629de4

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

GUI.pyw

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,23 @@ class MainWindow(QMainWindow, MainWindow.Ui_MainWindow):
118118
self.delay_acq = 0 ## time that acquisition takes
119119
###########################################
120120

121+
def closeEvent(self, event):
122+
box = QMessageBox()
123+
box.setIcon(QMessageBox.Question)
124+
box.setWindowTitle('Warning')
125+
box.setText('Are you sure you want to exit the program?')
126+
box.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
127+
buttonY = box.button(QMessageBox.Yes)
128+
buttonY.setText('Yes, exit')
129+
buttonN = box.button(QMessageBox.No)
130+
buttonN.setText('No, stay')
131+
box.exec_()
132+
133+
if box.clickedButton() == buttonY: ## yes
134+
event.accept()
135+
elif box.clickedButton() == buttonN: ## no
136+
event.ignore()
137+
121138
###########################################
122139
###########################################
123140
@pyqtSlot()
@@ -686,9 +703,25 @@ class MainWindow(QMainWindow, MainWindow.Ui_MainWindow):
686703
@pyqtSlot()
687704
def on_StopMeasBtn_clicked(self):
688705
print("=== StopMeasBtn clicked ===")
689-
self.cancel.emit() ## connected to cancel_meas(self)
690-
time.sleep(1)
691-
self.update_after_Meas(how="stopped")
706+
707+
box = QMessageBox()
708+
box.setIcon(QMessageBox.Question)
709+
box.setWindowTitle('Warning')
710+
box.setText('Are you sure you want to stop the measurement?')
711+
box.setStandardButtons(QMessageBox.Yes|QMessageBox.No)
712+
buttonY = box.button(QMessageBox.Yes)
713+
buttonY.setText('Yes, stop')
714+
buttonN = box.button(QMessageBox.No)
715+
buttonN.setText('No, continue')
716+
box.exec_()
717+
718+
if box.clickedButton() == buttonY: ## yes
719+
self.cancel.emit() ## connected to cancel_meas(self)
720+
time.sleep(1)
721+
self.update_after_Meas(how="stopped")
722+
elif box.clickedButton() == buttonN: ## no
723+
pass
724+
692725
return
693726

694727
@pyqtSlot()

0 commit comments

Comments
 (0)