Python PyQt5.QtWidgets.QMessageBox 模块,Critical() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用PyQt5.QtWidgets.QMessageBox.Critical()

项目:Gao-s-SB    作者:bioinformatist    | 项目源码 | 文件源码
def exception_message(log_lines, exc_info):
    stacktrace = traceback.format_exception(*exc_info) if exc_info else ""
    message = """
    {log_lines}

    ----
    {stacktrace}
    """.format(log_lines='\n'.join(log_lines), stacktrace='\n'.join(stacktrace))
    mb = QMessageBox()
    mb.setIcon(QMessageBox.Critical)
    mb.setWindowTitle("DUANG!!!")
    mb.setText('A critical error occurred. Select the details to display it.')
    mb.setInformativeText("Please report it to "
                          "<a href=https://github.com/bioinformatist/Gao-s-SB/issues/new>the owner's GitHub</a>")
    mb.setTextFormat(Qt.RichText)
    mb.setDetailedText(message)

    mb.setTextInteractionFlags(Qt.TextSelectableByMouse)
    mb.exec()
项目:MDT    作者:cbclab    | 项目源码 | 文件源码
def _export_image(self):
        output_file = self.outputFile_box.text()
        if not any(output_file.endswith(el[0]) for el in self._extension_filters):
            output_file += '.{}'.format(self._extension_filters[0][0])

        try:
            self._plotting_frame.export_image(output_file, self.width_box.value(), self.height_box.value(),
                                              dpi=self.dpi_box.value())
            self.previous_values['width'] = self.width_box.value()
            self.previous_values['height'] = self.height_box.value()
            self.previous_values['dpi'] = self.dpi_box.value()
            self.previous_values['output_file'] = self.outputFile_box.text()
            self.previous_values['writeScriptsAndConfig'] = self.writeScriptsAndConfig.isChecked()

            if self.writeScriptsAndConfig.isChecked():
                output_basename = os.path.splitext(output_file)[0]
                self._write_config_file(output_basename + '.conf')
                self._write_python_script_file(output_basename + '_script.py', output_basename + '.conf', output_file,
                                             self.width_box.value(), self.height_box.value(), self.dpi_box.value())
                self._write_bash_script_file(output_basename + '_script.sh', output_basename + '.conf', output_file,
                                             self.width_box.value(), self.height_box.value(), self.dpi_box.value())

        except PermissionError as error:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Critical)
            msg.setText("Could not write the file to the given destination.")
            msg.setInformativeText(str(error))
            msg.setWindowTitle("Permission denied")
            msg.exec_()
项目:MDT    作者:cbclab    | 项目源码 | 文件源码
def _write_example_data(self):
        try:
            mdt.utils.get_example_data(self.outputFile.text())
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText('The MDT example data has been written to {}.'.format(self.outputFile.text()))
            msg.setWindowTitle('Success')
            msg.exec_()
        except IOError as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Critical)
            msg.setText(str(e))
            msg.setWindowTitle("File writing error")
            msg.exec_()
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def displayMessageBox(self, errors_list):
        """
        Popup a message box in order to display an error message
        @param errors_list: a string that contains all the errors
        """
        errors_list = self.tr('Please correct the following error(s):\n') + errors_list
        error_message = QMessageBox(QMessageBox.Critical, self.tr('Invalid changes'), errors_list);
        error_message.exec_()
项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def error_dlg(parent,text):
    msgBox = QMessageBox(parent)
    msgBox.setIcon(QMessageBox.Critical)
    msgBox.setText("gpvdm error:")
    msgBox.setInformativeText(text)
    msgBox.setStandardButtons(QMessageBox.Ok )
    msgBox.setDefaultButton(QMessageBox.Ok)
    reply = msgBox.exec_()
项目:BigBrotherBot-For-UrT43    作者:ptitbigorneau    | 项目源码 | 文件源码
def run_gui():
    """
    Run B3 graphical user interface.
    Will raise an exception if the GUI cannot be initialized.
    """
    from b3.gui import B3App
    from b3.gui.misc import SplashScreen
    from PyQt5.QtWidgets import QMessageBox
    from PyQt5.QtWidgets import QSpacerItem, QSizePolicy

    # initialize outside try/except so if PyQt5 is not avaiable or there is
    # no display adapter available, this will raise an exception and we can
    # fallback into console mode
    app = B3App.Instance(sys.argv)

    try:
        with SplashScreen(min_splash_time=2):
            mainwindow = app.init()
    except Exception, e:
        box = QMessageBox()
        box.setIcon(QMessageBox.Critical)
        box.setWindowTitle('CRITICAL')
        box.setText('CRITICAL: B3 FAILED TO START!')
        box.setInformativeText('ERROR: %s' % e)
        box.setDetailedText(traceback.format_exc())
        box.setStandardButtons(QMessageBox.Ok)

        # this will trick Qt and resize a bit the QMessageBox to the exception stack trace is printed nice
        box.layout().addItem(QSpacerItem(400, 0, QSizePolicy.Minimum, QSizePolicy.Expanding),
                             box.layout().rowCount(), 0, 1, box.layout().columnCount())
        box.exec_()
        sys.exit(127)
    else:
        mainwindow.make_visible()
        sys.exit(app.exec_())
项目:BigBrotherBot-For-UrT43    作者:ptitbigorneau    | 项目源码 | 文件源码
def make_new_process(self, path):
        """
        Create a new B3 process using the provided configuration file path.
        NOTE: this actually handle also the repainting of the main table but
        since it's not a toolbar button handler it has been implemented here instead.
        :param path: the configuration file path
        """
        if path:

            try:
                abspath = b3.getAbsolutePath(path)
                config = MainConfig(load_config(abspath))
            except ConfigFileNotValid:
                msgbox = QMessageBox()
                msgbox.setIcon(QMessageBox.Critical)
                msgbox.setWindowTitle('WARNING')
                msgbox.setText('You selected an invalid configuration file')
                msgbox.setStandardButtons(QMessageBox.Ok)
                msgbox.exec_()
            else:
                analysis = config.analyze()
                if analysis:
                    msgbox = QMessageBox()
                    msgbox.setIcon(QMessageBox.Critical)
                    msgbox.setWindowTitle('ERROR')
                    msgbox.setText('One or more problems have been detected in your configuration file')
                    msgbox.setDetailedText('\n'.join(analysis))
                    msgbox.setStandardButtons(QMessageBox.Ok)
                    msgbox.exec_()
                else:
                    if not B3.exists(config.fileName):
                        process = B3(config=config)
                        process.insert()
                        main_table = self.centralWidget().main_table
                        main_table.repaint()
项目:BigBrotherBot-For-UrT43    作者:ptitbigorneau    | 项目源码 | 文件源码
def __init_storage(self):
        """
        Initialize the connection with the SQLite database.
        :raise DatabaseError: if the database schema is not consistent.
        """
        is_new_database = not os.path.isfile(B3_STORAGE)
        self.storage = sqlite3.connect(B3_STORAGE, check_same_thread=False)
        self.storage.isolation_level = None  # set autocommit mode
        self.storage.row_factory = sqlite3.Row  # allow row index by name
        if is_new_database:
            # create new schema
            self.__build_schema()
        else:
            # check database schema
            LOG.debug('checking database schema')
            cursor = self.storage.cursor()
            cursor.execute("""SELECT * FROM sqlite_master WHERE type='table'""")
            tables = [row[1] for row in cursor.fetchall()]
            cursor.close()

            if 'b3' not in tables:
                LOG.debug('database schema is corrupted: asking the user if he wants to rebuild it')

                msgbox = QMessageBox()
                msgbox.setIcon(QMessageBox.Critical)
                msgbox.setText('The database schema is corrupted and must be rebuilt. Do you want to proceed?')
                msgbox.setInformativeText('NOTE: all the previously saved data will be lost!')
                msgbox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
                msgbox.setDefaultButton(QMessageBox.No)
                msgbox.exec_()

                if msgbox.result() == QMessageBox.No:
                    # critical will raise an exception which will terminate the QApplication
                    LOG.critical('could not start B3: database schema is corrupted!')

                try:
                    os.remove(B3_STORAGE)
                    self.__build_schema()
                except Exception, err:
                    raise LOG.critical('could initialize SQLite database: %s (%s): make sure B3 has permissions to '
                                       'operate on this file, or remove it manually', B3_STORAGE, err)
项目:hue-plus    作者:kusti8    | 项目源码 | 文件源码
def excepthook(excType, excValue, tracebackobj):
    """Rewritten "excepthook" function, to display a message box with details about the exception.
    @param excType exception type
    @param excValue exception value
    @param tracebackobj traceback object
    """
    separator = '-' * 40
    notice = "An unhandled exception has occurred\n"

    tbinfofile = io.StringIO()
    traceback.print_tb(tracebackobj, None, tbinfofile)
    tbinfofile.seek(0)
    tbinfo = tbinfofile.read()
    errmsg = '%s: \n%s' % (str(excType), str(excValue))
    sections = [separator, errmsg, separator, tbinfo]
    msg = '\n'.join(sections)

    # Create a QMessagebox
    error_box = QMessageBox()

    error_box.setText(str(notice)+str(msg))
    error_box.setWindowTitle("Hue-plus - unhandled exception")
    error_box.setIcon(QMessageBox.Critical)
    error_box.setStandardButtons(QMessageBox.Ok)
    error_box.setTextInteractionFlags(Qt.TextSelectableByMouse)

    # Show the window
    error_box.exec_()
    sys.exit(1)