diff --git a/sohstationviewer/model/data_loader.py b/sohstationviewer/model/data_loader.py index 31f8dd1fb260ebcb6356a257366dbc4a5214be71..7e8c600c39de6132b0f555dc727578b6bd5bd2aa 100644 --- a/sohstationviewer/model/data_loader.py +++ b/sohstationviewer/model/data_loader.py @@ -239,5 +239,5 @@ class DataLoader(QtCore.QObject): :type button_labels: List[str] """ chosen_idx = create_multi_buttons_dialog( - msg, button_labels, abort_is_0=True) + msg, button_labels, has_abort=False) self.worker.button_chosen.emit(chosen_idx) diff --git a/sohstationviewer/model/general_data/general_data.py b/sohstationviewer/model/general_data/general_data.py index be971f03bf6f1dd06e237e2066e7dd691ea2ba73..36c33da88cb47de13146566a27808aded3e28675 100644 --- a/sohstationviewer/model/general_data/general_data.py +++ b/sohstationviewer/model/general_data/general_data.py @@ -266,7 +266,7 @@ class GeneralData(): loaded. """ msg = "Please select one of the following keys:" - ret = create_multi_buttons_dialog(msg, self.keys, abort_is_0=False) + ret = create_multi_buttons_dialog(msg, self.keys, has_abort=True) if ret == -1: return False self.selected_key = self.keys[ret] diff --git a/sohstationviewer/view/create_muti_buttons_dialog.py b/sohstationviewer/view/create_muti_buttons_dialog.py index 991ae257f11c88aefbd4887cbd08d06bc27b26ce..b52ecec81284e82388c45e4448df19787f8c368d 100644 --- a/sohstationviewer/view/create_muti_buttons_dialog.py +++ b/sohstationviewer/view/create_muti_buttons_dialog.py @@ -4,16 +4,16 @@ from PySide2 import QtWidgets def create_multi_buttons_dialog( - msg: str, button_labels: List[str], abort_is_0) -> int: + msg: str, button_labels: List[str], has_abort) -> int: """ Create a modal dialog with buttons. Show the dialog and send the user's choice to the data object being created. :param msg: the instruction shown to the user :param button_labels: the list of labels that are shown on the buttons - + :param has_abort: flag to add Abort button or not :return chosen_idx: index of selected button. If abort_button is selected, - return 0 if abort_is_0=True or -1 otherwise. + return -1 """ msg_box = QtWidgets.QMessageBox() msg_box.setText(msg) @@ -30,17 +30,14 @@ def create_multi_buttons_dialog( buttons.append( msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole) ) - abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort) + if has_abort: + abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort) msg_box.exec_() - if msg_box.clickedButton() == abort_button: - if abort_is_0: - # The default choice is the first item, so we default to it if the - # user presses the abort button. An alternative choice is to stop - # when the user presses the abort button. - chosen_idx = 0 - else: - chosen_idx = -1 - else: - chosen_idx = buttons.index(msg_box.clickedButton()) + try: + if msg_box.clickedButton() == abort_button: + return -1 + except UnboundLocalError: + pass + chosen_idx = buttons.index(msg_box.clickedButton()) return chosen_idx diff --git a/sohstationviewer/view/save_plot_dialog.py b/sohstationviewer/view/save_plot_dialog.py index 53b1c741259bde9a1b1087ae355800e84f11e67b..3dacf9df79c498f1b686c4cf863fad1762fe8e2f 100644 --- a/sohstationviewer/view/save_plot_dialog.py +++ b/sohstationviewer/view/save_plot_dialog.py @@ -48,7 +48,7 @@ class SavePlotDialog(QDialog): if fmt == self.main_window.save_plot_format: self.format_radio_btns[fmt].setChecked(True) self.cancel_btn = QtWidgets.QPushButton('CANCEL', self) - self.continue_btn = QtWidgets.QPushButton('SAVE PLOT', self) + self.save_plot_btn = QtWidgets.QPushButton('SAVE PLOT', self) self.setup_ui() self.connect_signals() @@ -77,12 +77,12 @@ class SavePlotDialog(QDialog): rowidx += 1 main_layout.addWidget(self.cancel_btn, rowidx, 1, 1, 1) - main_layout.addWidget(self.continue_btn, rowidx, 3, 1, 1) + main_layout.addWidget(self.save_plot_btn, rowidx, 3, 1, 1) def connect_signals(self) -> None: self.save_dir_btn.clicked.connect(self.change_save_directory) self.cancel_btn.clicked.connect(self.close) - self.continue_btn.clicked.connect(self.on_continue) + self.save_plot_btn.clicked.connect(self.save_plot) @QtCore.Slot() def change_save_directory(self) -> None: @@ -96,12 +96,12 @@ class SavePlotDialog(QDialog): fd.exec() new_path = fd.selectedFiles()[0] self.save_dir_textbox.setText(new_path) - self.save_dir_path = new_path self.main_window.save_plot_dir = new_path @QtCore.Slot() - def on_continue(self): - if self.save_dir_textbox.text().strip() == '': + def save_plot(self): + self.save_dir_path = self.save_dir_textbox.text().strip() + if self.save_dir_path == '': QtWidgets.QMessageBox.warning( self, "Add Directory", "A directory need to be given before continue.") @@ -121,6 +121,17 @@ class SavePlotDialog(QDialog): self.save_file_path = Path(self.save_dir_path).joinpath( f"{self.save_filename_textbox.text()}.{save_format}") + + if not os.access(self.save_dir_path, os.W_OK): + self.save_file_path = None + QtWidgets.QMessageBox.information( + self, "No Write Permission", + "The directory to save file to doesn't have Write Permission." + "\n\nPlease change its permission or " + "select another directory." + ) + return + self.dpi = self.dpi_line_edit.value() self.close()