def message_box(self, message: str, buttons: int = 1) -> int: ''' Message box with "Yes/No" or "OK" buttons. Defaults to "OK".\n Parameters:\n message (str): Message shown inside the message box. buttons (int): Amount of buttons, 1 - "OK" button, 2 - "Yes/No" buttons. Returns:\n choice (int): ID of the clicked button. ''' pixmap = QPixmap(resource_path('icon.ico')).scaledToWidth( 35, Qt.SmoothTransformation) msg_box = QMessageBox() msg_box.setFont(ui.font) msg_box.setText(message) if buttons == 2: msg_yes = msg_box.addButton(QMessageBox.Yes) msg_no = msg_box.addButton(QMessageBox.No) msg_yes.setText(self.dialog_yes) msg_no.setText(self.dialog_no) msg_yes.setProperty('class', 'button_yes') msg_no.setProperty('class', 'button_no') msg_box.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint) msg_box.setIconPixmap(pixmap) with open(resource_path('style.css'), 'r') as file: msg_box.setStyleSheet(file.read()) msg_box.move(ui.frameGeometry().center() - QRect(QPoint(), msg_box.sizeHint()).center()) choice = msg_box.exec_() return choice
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)
def on_firmwareInfoButton_clicked(self): infoBox = QMessageBox() infoBox.setText(self.remote_firmware_selection['description']) infoBox.setStyleSheet(self.style_text) infoBox.exec()