def prompt_calc_dvh(self):
        """
        Windows displays buttons in a different order from Linux. A check for
        platform is performed to ensure consistency of button positioning across
        platforms.
        """
        message = "DVHs not present in RTDOSE or do not correspond to ROIs. "
        message += "Would you like to calculate DVHs? (This may take up to "
        message += "several minutes on some systems.)"
        if platform.system() == "Linux":
            choice = QMessageBox.question(self, "Calculate DVHs?", message,
                                          QMessageBox.Yes | QMessageBox.No)

            if choice == QMessageBox.Yes:
                self.signal_advise_calc_dvh.emit(True)
            else:
                self.signal_advise_calc_dvh.emit(False)
        else:
            stylesheet_path = ""

            # Select appropriate style sheet
            if platform.system() == 'Darwin':
                stylesheet_path = Path.cwd().joinpath('res', 'stylesheet.qss')
            else:
                stylesheet_path = Path.cwd().joinpath(
                    'res', 'stylesheet-win-linux.qss')

            # Create a message box and add attributes
            mb = QMessageBox()
            mb.setIcon(QMessageBox.Question)
            mb.setWindowTitle("Calculate DVHs?")
            mb.setText(message)
            button_no = QtWidgets.QPushButton("No")
            button_yes = QtWidgets.QPushButton("Yes")

            # We want the buttons 'No' & 'Yes' to be displayed in that
            # exact order. QMessageBox displays buttons in respect to
            # their assigned roles. (0 first, then 1 and so on)
            # 'AcceptRole' is 0 and 'RejectRole' is 1 thus by assigning
            # 'No' to 'AcceptRole' and 'Yes' to 'RejectRole' the buttons
            # are positioned as desired.
            mb.addButton(button_no, QtWidgets.QMessageBox.AcceptRole)
            mb.addButton(button_yes, QtWidgets.QMessageBox.RejectRole)

            # Apply stylesheet to the message box and add icon to the window
            mb.setStyleSheet(open(stylesheet_path).read())
            mb.setWindowIcon(
                QtGui.QIcon(
                    resource_path(Path.cwd().joinpath('res', 'images',
                                                      'btn-icons',
                                                      'onkodicom_icon.png'))))
            mb.exec_()

            if mb.clickedButton() == button_yes:
                self.signal_advise_calc_dvh.emit(True)
            else:
                self.signal_advise_calc_dvh.emit(False)
Ejemplo n.º 2
0
 def showContinueSearchDialog(self, searchlimit: int) -> bool:
     messagebox = QMessageBox(self)
     messagebox.setWindowTitle('Unusual search depth')
     messagebox.setText(f'''
         <p>No mod detected after searching through {searchlimit} directories.</p>
         <p>Are you sure this is a valid mod?</p>
         ''')
     messagebox.setTextFormat(Qt.RichText)
     messagebox.setStandardButtons(QMessageBox.Cancel)
     yes: QPushButton = QPushButton(' Yes, continue searching ', messagebox)
     yes.setAutoDefault(True)
     yes.setDefault(True)
     messagebox.addButton(yes, QMessageBox.YesRole)
     messagebox.exec_()
     return messagebox.clickedButton() == yes
Ejemplo n.º 3
0
def choiceDialog(parent: Optional[QWidget],
                 message: str,
                 labels: Iterable[str],
                 choices: Iterable[T],
                 show_cancel_button=True) -> T:
    buttons_to_choices = {}
    message_box = QMessageBox(QMessageBox.Question, QApplication.applicationName(), message, QMessageBox.NoButton, parent)

    for label, choice in zip(labels, choices):
        button = message_box.addButton(label, QMessageBox.ActionRole)
        buttons_to_choices[button] = choice

    if show_cancel_button:
        button = message_box.addButton(QMessageBox.Cancel)
        buttons_to_choices[button] = None

    message_box.exec()
    return buttons_to_choices[message_box.clickedButton()]