def warn_box(self, message: str, title: str, one_option=False):
     """
     Display a warning box
     """
     box = QMessageBox()
     box.setText(message)
     box.setWindowTitle(title)
     box.setStyleSheet(get_stylesheet(self.viewer.get_theme()))
     if one_option:
         box.setStandardButtons(QMessageBox.Cancel)
     else:
         box.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
     return box.exec_()
Example #2
0
def excepthook(exctype, excvalue, tracebackobj):
    """
    Global function to catch unhandled exceptions.

    @param exctype exception type
    @param excvalue exception value
    @param tracebackobj traceback object
    """
    app = SiriusApplication.instance()
    if app is None:
        app = SiriusApplication(None, sys.argv)

    separator = '-' * 120 + '\n'
    notice = \
        'An unhandled exception occurred. Please report the problem '\
        'via email to <{}>.\nA log has {{}}been written to "{}".\n\n'\
        'Error information:\n'.format("*****@*****.**", LOGFILE)
    timestring = time.strftime("%Y-%m-%d, %H:%M:%S") + '\n'

    tbinfofile = StringIO()
    traceback.print_tb(tracebackobj, None, tbinfofile)
    tbinfofile.seek(0)
    tbinfo = tbinfofile.read()

    errmsg = '%s: \n%s\n' % (str(exctype), str(excvalue))
    sections = [timestring, errmsg, tbinfo]
    msg = separator.join(sections)
    try:
        with open(LOGFILE, 'a') as fil:
            fil.write('\n' + msg + '\n')
        try:
            os.chmod(LOGFILE, 0o666)
        except OSError:
            pass
    except PermissionError:
        notice = notice.format('NOT ')
    else:
        notice = notice.format('')
    errorbox = QMessageBox()
    errorbox.setText(notice)
    errorbox.setInformativeText(msg)
    errorbox.setIcon(QMessageBox.Critical)
    errorbox.setWindowTitle('Error')
    errorbox.setStyleSheet('#qt_msgbox_informativelabel {min-width: 40em;}')
    errorbox.exec_()