From 1dddad477b249a1f12566641bf8b032bb991478d Mon Sep 17 00:00:00 2001 From: Christina Bukas Date: Mon, 18 Dec 2023 11:52:50 +0100 Subject: [PATCH] updated create_warning_box to include cancel option --- src/client/dcp_client/gui/main_window.py | 6 +++--- src/client/dcp_client/gui/napari_window.py | 8 ++++---- src/client/dcp_client/gui/welcome_window.py | 6 +++--- src/client/dcp_client/utils/utils.py | 11 ++++++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/client/dcp_client/gui/main_window.py b/src/client/dcp_client/gui/main_window.py index 76264d4..d4463c6 100644 --- a/src/client/dcp_client/gui/main_window.py +++ b/src/client/dcp_client/gui/main_window.py @@ -132,11 +132,11 @@ def on_item_inprogr_selected(self, item): def on_train_button_clicked(self): message_text = self.app.run_train() - create_warning_box(message_text) + _ = create_warning_box(message_text) def on_run_inference_button_clicked(self): message_text, message_title = self.app.run_inference() - create_warning_box(message_text, message_title) + _ = create_warning_box(message_text, message_title) def on_launch_napari_button_clicked(self): ''' @@ -144,7 +144,7 @@ def on_launch_napari_button_clicked(self): ''' if not self.app.cur_selected_img or '_seg.tiff' in self.app.cur_selected_img: message_text = "Please first select an image you wish to visualise. The selected image must be an original images, not a mask." - create_warning_box(message_text, message_title="Warning") + _ = create_warning_box(message_text, message_title="Warning") else: self.nap_win = NapariWindow(self.app) self.nap_win.show() diff --git a/src/client/dcp_client/gui/napari_window.py b/src/client/dcp_client/gui/napari_window.py index ecef6a8..e0451dd 100644 --- a/src/client/dcp_client/gui/napari_window.py +++ b/src/client/dcp_client/gui/napari_window.py @@ -56,7 +56,7 @@ def on_add_to_curated_button_clicked(self): ''' if self.app.cur_selected_path == str(self.app.train_data_path): message_text = "Image is already in the \'Curated data\' folder and should not be changed again" - utils.create_warning_box(message_text, message_title="Warning") + _ = utils.create_warning_box(message_text, message_title="Warning") return # take the name of the currently selected layer (by the user) @@ -64,7 +64,7 @@ def on_add_to_curated_button_clicked(self): # TODO if more than one item is selected this will break! if '_seg' not in cur_seg_selected: message_text = "Please select the segmenation you wish to save from the layer list" - utils.create_warning_box(message_text, message_title="Warning") + _ = utils.create_warning_box(message_text, message_title="Warning") return seg = self.viewer.layers[cur_seg_selected].data @@ -87,7 +87,7 @@ def on_add_to_inprogress_button_clicked(self): # TODO: Do we allow this? What if they moved it by mistake? User can always manually move from their folders?) if self.app.cur_selected_path == str(self.app.train_data_path): message_text = "Images from '\Curated data'\ folder can not be moved back to \'Curatation in progress\' folder." - utils.create_warning_box(message_text, message_title="Warning") + _ = utils.create_warning_box(message_text, message_title="Warning") return # take the name of the currently selected layer (by the user) @@ -95,7 +95,7 @@ def on_add_to_inprogress_button_clicked(self): # TODO if more than one item is selected this will break! if '_seg' not in cur_seg_selected: message_text = "Please select the segmenation you wish to save from the layer list" - utils.create_warning_box(message_text, message_title="Warning") + _ = utils.create_warning_box(message_text, message_title="Warning") return # Move original image diff --git a/src/client/dcp_client/gui/welcome_window.py b/src/client/dcp_client/gui/welcome_window.py index 8886d7e..5c385a5 100644 --- a/src/client/dcp_client/gui/welcome_window.py +++ b/src/client/dcp_client/gui/welcome_window.py @@ -129,15 +129,15 @@ def start_main(self): self.mw = MainWindow(self.app) else: message_text = "You need to specify a folder both for your uncurated and curated dataset (even if the curated folder is currently empty). Please go back and select folders for both." - create_warning_box(message_text, message_title="Warning") + _ = create_warning_box(message_text, message_title="Warning") def start_upload(self): message_text = ("Your current configurations are set to run some operations on the cloud. \n" "For this we need to upload your data to our server." "We will now upload your data. Click ok to continue. \n" "If you do not agree close the application and contact your software provider.") - create_warning_box(message_text, message_title="Warning") - self.app.upload_data_to_server() + usr_response = create_warning_box(message_text, message_title="Warning", add_cancel_btn=True) + if usr_response: self.app.upload_data_to_server() self.hide() self.mw = MainWindow(self.app) \ No newline at end of file diff --git a/src/client/dcp_client/utils/utils.py b/src/client/dcp_client/utils/utils.py index c7ca5bf..594712d 100644 --- a/src/client/dcp_client/utils/utils.py +++ b/src/client/dcp_client/utils/utils.py @@ -23,13 +23,18 @@ def icon(self, type: 'QFileIconProvider.IconType'): else: return super().icon(type) -def create_warning_box(message_text, message_title="Warning"): +def create_warning_box(message_text, message_title="Warning", add_cancel_btn=False): msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText(message_text) msg.setWindowTitle(message_title) - msg.setStandardButtons(QMessageBox.Ok) - msg.exec() + if add_cancel_btn: + msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) + else: + msg.setStandardButtons(QMessageBox.Ok) + usr_response = msg.exec() + if usr_response == QMessageBox.Ok: return True + else: return False def read_config(name, config_path = 'config.cfg') -> dict: """Reads the configuration file