Skip to content
Snippets Groups Projects
Commit bb72a4a5 authored by Lan Dam's avatar Lan Dam
Browse files

use has_abort flag to add/not add abort button to create_multi_buttons_dialog;...

use has_abort flag to add/not add abort button to create_multi_buttons_dialog; adjust code to use this has_abort button
parent 7e3bc1fc
No related branches found
No related tags found
2 merge requests!190let user select one of the folders data/, sdata/,!189Fix return when user select Abort in multi button dialog
Pipeline #3036 passed with stage
in 2 minutes and 14 seconds
This commit is part of merge request !190. Comments created here will be created in the context of that merge request.
...@@ -239,5 +239,5 @@ class DataLoader(QtCore.QObject): ...@@ -239,5 +239,5 @@ class DataLoader(QtCore.QObject):
:type button_labels: List[str] :type button_labels: List[str]
""" """
chosen_idx = create_multi_buttons_dialog( 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) self.worker.button_chosen.emit(chosen_idx)
...@@ -266,7 +266,7 @@ class GeneralData(): ...@@ -266,7 +266,7 @@ class GeneralData():
loaded. loaded.
""" """
msg = "Please select one of the following keys:" 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: if ret == -1:
return False return False
self.selected_key = self.keys[ret] self.selected_key = self.keys[ret]
......
...@@ -4,16 +4,16 @@ from PySide2 import QtWidgets ...@@ -4,16 +4,16 @@ from PySide2 import QtWidgets
def create_multi_buttons_dialog( 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 Create a modal dialog with buttons. Show the dialog and send the user's
choice to the data object being created. choice to the data object being created.
:param msg: the instruction shown to the user :param msg: the instruction shown to the user
:param button_labels: the list of labels that are shown on the buttons :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 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 = QtWidgets.QMessageBox()
msg_box.setText(msg) msg_box.setText(msg)
...@@ -30,11 +30,14 @@ def create_multi_buttons_dialog( ...@@ -30,11 +30,14 @@ def create_multi_buttons_dialog(
buttons.append( buttons.append(
msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole) 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_() msg_box.exec_()
if msg_box.clickedButton() == abort_button: try:
chosen_idx = -1 if msg_box.clickedButton() == abort_button:
else: return -1
chosen_idx = buttons.index(msg_box.clickedButton()) except UnboundLocalError:
pass
chosen_idx = buttons.index(msg_box.clickedButton())
return chosen_idx return chosen_idx
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment