Python PyQt5.QtWidgets.QMessageBox.Critical() Examples

The following are 18 code examples of PyQt5.QtWidgets.QMessageBox.Critical(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtWidgets.QMessageBox , or try the search function .
Example #1
Source File: test_error.py    From qutebrowser with GNU General Public License v3.0 7 votes vote down vote up
def test_err_windows(qtbot, qapp, pre_text, post_text, expected, caplog):

    def err_window_check():
        w = qapp.activeModalWidget()
        assert w is not None
        try:
            qtbot.add_widget(w)
            if not utils.is_mac:
                assert w.windowTitle() == 'title'
            assert w.icon() == QMessageBox.Critical
            assert w.standardButtons() == QMessageBox.Ok
            assert w.text() == expected
        finally:
            w.close()

    QTimer.singleShot(10, err_window_check)

    with caplog.at_level(logging.ERROR):
        error.handle_fatal_exc(ValueError("exception"), 'title',
                               pre_text=pre_text, post_text=post_text,
                               no_err_windows=False) 
Example #2
Source File: test_msgbox.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
def test_attributes(qtbot):
    """Test basic QMessageBox attributes."""
    title = 'title'
    text = 'text'
    parent = QWidget()
    qtbot.add_widget(parent)
    icon = QMessageBox.Critical
    buttons = QMessageBox.Ok | QMessageBox.Cancel

    box = msgbox.msgbox(parent=parent, title=title, text=text, icon=icon,
                        buttons=buttons)
    qtbot.add_widget(box)
    if not utils.is_mac:
        assert box.windowTitle() == title
    assert box.icon() == icon
    assert box.standardButtons() == buttons
    assert box.text() == text
    assert box.parent() is parent 
Example #3
Source File: tor.py    From gridsync with GNU General Public License v3.0 6 votes vote down vote up
def get_tor_with_prompt(reactor, parent=None):
    tor = yield get_tor(reactor)
    while not tor:
        msgbox = QMessageBox(parent)
        msgbox.setIcon(QMessageBox.Critical)
        msgbox.setWindowTitle("Tor Required")
        msgbox.setText(
            "This connection can only be made over the Tor network, however, "
            "no running Tor daemon was found or Tor has been disabled."
        )
        msgbox.setInformativeText(
            "Please ensure that Tor is running and try again.<p>For help "
            "installing Tor, visit "
            "<a href=https://torproject.org>https://torproject.org</a>"
        )
        msgbox.setStandardButtons(QMessageBox.Abort | QMessageBox.Retry)
        if msgbox.exec_() == QMessageBox.Retry:
            tor = yield get_tor(reactor)
        else:
            break
    return tor 
Example #4
Source File: core.py    From face_recognition_py with GNU General Public License v3.0 6 votes vote down vote up
def telegramBotSettings(self):
        cfg = ConfigParser()
        cfg.read('./config/telegramBot.cfg', encoding='utf-8-sig')
        read_only = cfg.getboolean('telegramBot', 'read_only')
        # read_only = False
        if read_only:
            text = '基于安全考虑,系统拒绝了本次请求。'
            informativeText = '<b>请联系设备管理员。</b>'
            CoreUI.callDialog(QMessageBox.Critical, text, informativeText, QMessageBox.Ok)
        else:
            token = cfg.get('telegramBot', 'token')
            chat_id = cfg.get('telegramBot', 'chat_id')
            proxy_url = cfg.get('telegramBot', 'proxy_url')
            message = cfg.get('telegramBot', 'message')

            self.telegramBotDialog = TelegramBotDialog()
            self.telegramBotDialog.tokenLineEdit.setText(token)
            self.telegramBotDialog.telegramIDLineEdit.setText(chat_id)
            self.telegramBotDialog.socksLineEdit.setText(proxy_url)
            self.telegramBotDialog.messagePlainTextEdit.setPlainText(message)
            self.telegramBotDialog.exec()

    # 设备响铃进程 
Example #5
Source File: DMatSetup.py    From pyleecan with Apache License 2.0 5 votes vote down vote up
def set_default(self, attr, attr_name):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Critical)
        msg.setText(
            "Material "
            + attr_name
            + " property is None.\nDefault values set. Please check values."
        )
        msg.setWindowTitle("Warning")
        msg.exec_()
        setattr(self.mat, attr, type(getattr(Material(), attr))()) 
Example #6
Source File: main.py    From MDT with GNU Lesser General Public License v3.0 5 votes vote down vote up
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_() 
Example #7
Source File: qt_main.py    From MDT with GNU Lesser General Public License v3.0 5 votes vote down vote up
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_() 
Example #8
Source File: qmessagebox.py    From linux-show-player with GNU General Public License v3.0 5 votes vote down vote up
def dcritical(title, text, detailed_text, parent=None):
        """MessageBox with "Critical" icon"""
        QDetailedMessageBox.dgeneric(title,
                                     text,
                                     detailed_text,
                                     QMessageBox.Critical,
                                     parent) 
Example #9
Source File: application.py    From vorta with GNU General Public License v3.0 5 votes vote down vote up
def _alert_missing_borg(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Critical)
        msg.setText(self.tr("No Borg Binary Found"))
        msg.setInformativeText(self.tr("Vorta was unable to locate a usable Borg Backup binary."))
        msg.setStandardButtons(QMessageBox.Ok)
        msg.exec_() 
Example #10
Source File: earlyinit.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def _die(message, exception=None):
    """Display an error message using Qt and quit.

    We import the imports here as we want to do other stuff before the imports.

    Args:
        message: The message to display.
        exception: The exception object if we're handling an exception.
    """
    from PyQt5.QtWidgets import QApplication, QMessageBox
    from PyQt5.QtCore import Qt
    if (('--debug' in sys.argv or '--no-err-windows' in sys.argv) and
            exception is not None):
        print(file=sys.stderr)
        traceback.print_exc()
    app = QApplication(sys.argv)
    if '--no-err-windows' in sys.argv:
        print(message, file=sys.stderr)
        print("Exiting because of --no-err-windows.", file=sys.stderr)
    else:
        if exception is not None:
            message = message.replace('%ERROR%', str(exception))
        msgbox = QMessageBox(QMessageBox.Critical, "qutebrowser: Fatal error!",
                             message)
        msgbox.setTextFormat(Qt.RichText)
        msgbox.resize(msgbox.sizeHint())
        msgbox.exec_()
    app.quit()
    sys.exit(1) 
Example #11
Source File: widgets.py    From Turing with MIT License 5 votes vote down vote up
def msg_box_error(text, *args, **kwargs):
    return msg_box(text, *args, **kwargs, buttons=QMessageBox.Ok, default=QMessageBox.Ok, type=QMessageBox.Critical) 
Example #12
Source File: qtapp.py    From autokey with GNU General Public License v3.0 5 votes vote down vote up
def show_error_dialog(message: str, details: str=None):
        """
        Convenience method for showing an error dialog.
        """
        # TODO: i18n
        message_box = QMessageBox(
            QMessageBox.Critical,
            "Error",
            message,
            QMessageBox.Ok,
            None
        )
        if details:
            message_box.setDetailedText(details)
        message_box.exec_() 
Example #13
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #14
Source File: tabMNConf.py    From PIVX-SPMT with MIT License 5 votes vote down vote up
def findPubKey(self):
        printDbg("Computing public key...")
        currSpath = self.ui.edt_spath.value()
        currHwAcc = self.ui.edt_hwAccount.value()
        # Check HW device
        if self.caller.hwStatus != 2:
            myPopUp_sb(self.caller, "crit", 'SPMT - hw device check', "Connect to HW device first")
            printDbg("Unable to connect to hardware device. The device status is: %d" % self.caller.hwStatus)
            return None

        result = self.caller.hwdevice.scanForPubKey(currHwAcc, currSpath, self.isTestnet())

        # Connection pop-up
        warningText = "Unable to find public key. The action was refused on the device or another application "
        warningText += "might have taken over the USB communication with the device.<br><br>"
        warningText += "To continue click the <b>Retry</b> button.\nTo cancel, click the <b>Abort</b> button."
        mBox = QMessageBox(QMessageBox.Critical, "WARNING", warningText, QMessageBox.Retry)
        mBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Abort);

        while result is None:
            ans = mBox.exec_()
            if ans == QMessageBox.Abort:
                return
            # we need to reconnect the device
            self.caller.hwdevice.clearDevice()
            self.caller.hwdevice.initDevice(self.caller.header.hwDevices.currentIndex())

            result = self.caller.hwdevice.scanForPubKey(currHwAcc, currSpath, self.isTestnet())

        mess = "Found public key:\n%s" % result
        myPopUp_sb(self.caller, "info", "SPMT - findPubKey", mess)
        printOK("Public Key: %s" % result)
        self.ui.edt_pubKey.setText(result) 
Example #15
Source File: core.py    From gridsync with GNU General Public License v3.0 5 votes vote down vote up
def show_message():
        message_settings = settings.get("message")
        if not message_settings:
            return
        if get_preference("message", "suppress") == "true":
            return
        logging.debug("Showing custom message to user...")
        msgbox = QMessageBox()
        icon_type = message_settings.get("type")
        if icon_type:
            icon_type = icon_type.lower()
            if icon_type == "information":
                msgbox.setIcon(QMessageBox.Information)
            elif icon_type == "warning":
                msgbox.setIcon(QMessageBox.Warning)
            elif icon_type == "critical":
                msgbox.setIcon(QMessageBox.Critical)
        if sys.platform == "darwin":
            msgbox.setText(message_settings.get("title"))
            msgbox.setInformativeText(message_settings.get("text"))
        else:
            msgbox.setWindowTitle(message_settings.get("title"))
            msgbox.setText(message_settings.get("text"))
        checkbox = QCheckBox("Do not show this message again")
        checkbox.stateChanged.connect(
            lambda state: set_preference(
                "message", "suppress", ("true" if state else "false")
            )
        )
        msgbox.setCheckBox(checkbox)
        msgbox.exec_()
        logging.debug("Custom message closed; proceeding with start...") 
Example #16
Source File: error.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def handle_fatal_exc(exc: BaseException,
                     title: str, *,
                     no_err_windows: bool,
                     pre_text: str = '',
                     post_text: str = '') -> None:
    """Handle a fatal "expected" exception by displaying an error box.

    If --no-err-windows is given as argument, the text is logged to the error
    logger instead.

    Args:
        exc: The Exception object being handled.
        no_err_windows: Show text in log instead of error window.
        title: The title to be used for the error message.
        pre_text: The text to be displayed before the exception text.
        post_text: The text to be displayed after the exception text.
    """
    if no_err_windows:
        lines = [
            "Handling fatal {} with --no-err-windows!".format(_get_name(exc)),
            "",
            "title: {}".format(title),
            "pre_text: {}".format(pre_text),
            "post_text: {}".format(post_text),
            "exception text: {}".format(str(exc) or 'none'),
        ]
        log.misc.exception('\n'.join(lines))
    else:
        log.misc.exception("Fatal exception:")
        if pre_text:
            msg_text = '{}: {}'.format(pre_text, exc)
        else:
            msg_text = str(exc)
        if post_text:
            msg_text += '\n\n{}'.format(post_text)
        msgbox = QMessageBox(QMessageBox.Critical, title, msg_text)
        msgbox.exec_() 
Example #17
Source File: msg.py    From gridsync with GNU General Public License v3.0 5 votes vote down vote up
def critical(title, text):
    msg = QMessageBox()
    msg.setIcon(QMessageBox.Critical)
    msg.setWindowTitle(title)
    msg.setText(text)
    return msg.exec_() 
Example #18
Source File: msg.py    From gridsync with GNU General Public License v3.0 5 votes vote down vote up
def error(parent, title, text, detailed_text=None):
    msg = QMessageBox(parent)
    msg.setIcon(QMessageBox.Critical)
    if sys.platform == "darwin":
        # Window titles are ignored for macOS "Alerts"; use setText() instead.
        # See https://doc.qt.io/qt-5/qmessagebox.html#the-property-based-api
        msg.setText(title)
        msg.setInformativeText(text)
    else:
        msg.setWindowTitle(title)
        msg.setText(text)
    msg.setDetailedText(detailed_text)
    return msg.exec_()