From 22cd451b24d0f43d24f78e6b8452339a65ca384f Mon Sep 17 00:00:00 2001 From: brahim Date: Fri, 14 Mar 2025 11:52:27 +0100 Subject: [PATCH] Error message is added when user click on import/compute calibration without acoustic data #37 --- View/sediment_calibration_tab.py | 104 ++++++++++++++++++------------- 1 file changed, 61 insertions(+), 43 deletions(-) diff --git a/View/sediment_calibration_tab.py b/View/sediment_calibration_tab.py index 7105d99..2ff5b12 100644 --- a/View/sediment_calibration_tab.py +++ b/View/sediment_calibration_tab.py @@ -1716,32 +1716,47 @@ class SedimentCalibrationTab(QWidget): self.animaiton_groupbox_compute.start() def import_calibration_file(self): - filename = QFileDialog.getOpenFileName( - self, "Open calibration", - [ - stg.path_calibration_file - if stg.path_calibration_file - else stg.path_BS_raw_data[-1] - if self.combobox_acoustic_data_choice.count() > 0 - else "" - ][0], - "Calibration file (*.xls, *.ods, *csv)", - options=QFileDialog.DontUseNativeDialog - ) - dir_name = os.path.dirname(filename[0]) - name = os.path.basename(filename[0]) + if self.combobox_acoustic_data_choice.count() == 0: + msgBox = QMessageBox() + msgBox.setWindowTitle("Calibration import error") + msgBox.setIconPixmap( + QPixmap( + self._path_icon("no_approved.png") + ).scaledToHeight(32, Qt.SmoothTransformation) + ) + msgBox.setText("Update data before importing calibration") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() - stg.path_calibration_file = dir_name - stg.filename_calibration_file = name + else: - self.lineEdit_import_calibration.clear() - self.lineEdit_import_calibration.setText(name) + filename = QFileDialog.getOpenFileName( + self, "Open calibration", + [ + stg.path_calibration_file + if stg.path_calibration_file + else stg.path_BS_raw_data[-1] + if self.combobox_acoustic_data_choice.count() > 0 + else "" + ][0], + "Calibration file (*.xls, *.ods, *csv)", + options=QFileDialog.DontUseNativeDialog + ) - self.lineEdit_import_calibration.setToolTip(dir_name) + dir_name = os.path.dirname(filename[0]) + name = os.path.basename(filename[0]) - self.compute_depth_2D() - self.read_calibration_file_and_fill_parameter() + stg.path_calibration_file = dir_name + stg.filename_calibration_file = name + + self.lineEdit_import_calibration.clear() + self.lineEdit_import_calibration.setText(name) + + self.lineEdit_import_calibration.setToolTip(dir_name) + + self.compute_depth_2D() + self.read_calibration_file_and_fill_parameter() def update_label_freq1_for_calibration(self): self.label_freq1.clear() @@ -1784,19 +1799,8 @@ class SedimentCalibrationTab(QWidget): ) def read_calibration_file_and_fill_parameter(self): - if self.combobox_acoustic_data_choice.count() == 0: - msgBox = QMessageBox() - msgBox.setWindowTitle("Calibration import error") - msgBox.setIconPixmap( - QPixmap( - self._path_icon("no_approved.png") - ).scaledToHeight(32, Qt.SmoothTransformation) - ) - msgBox.setText("Update data before importing calibration") - msgBox.setStandardButtons(QMessageBox.Ok) - msgBox.exec() - elif stg.filename_calibration_file == "": + if stg.filename_calibration_file == "": pass @@ -1996,17 +2000,31 @@ class SedimentCalibrationTab(QWidget): def function_pushbutton_compute_calibration(self): - self.label_temperature.clear() - self.label_temperature.setText("T = " + str(stg.temperature) + " °C") + if self.combobox_acoustic_data_choice.count() == 0: + msgBox = QMessageBox() + msgBox.setWindowTitle("Calibration computation error") + msgBox.setIconPixmap( + QPixmap( + self._path_icon("no_approved.png") + ).scaledToHeight(32, Qt.SmoothTransformation) + ) + msgBox.setText("Update data before importing calibration") + msgBox.setStandardButtons(QMessageBox.Ok) + msgBox.exec() - self.compute_depth_2D() - self.compute_ks() - self.compute_sv() - self.compute_X() - self.compute_kt2D_kt3D() - self.compute_J_cross_section() - self.compute_alpha_s() - self.compute_zeta() + else: + + self.label_temperature.clear() + self.label_temperature.setText("T = " + str(stg.temperature) + " °C") + + self.compute_depth_2D() + self.compute_ks() + self.compute_sv() + self.compute_X() + self.compute_kt2D_kt3D() + self.compute_J_cross_section() + self.compute_alpha_s() + self.compute_zeta() def compute_ks(self): data_id = self.combobox_acoustic_data_choice.currentIndex()