Exemple #1
0
    def updateHighscores(self):
        time = round(self.totalTime, 2)
        displayString = 'Your time was: ' + str(time)
        path = os.path.dirname(os.path.realpath(__file__))

        try:
            with open(os.path.join(path, 'test.json'), 'r') as score_file:
                scores = json.load(score_file)
        except FileNotFoundError:
            scores = {'highscores': []}

        newEntry = {"date": str(datetime.date.today()), "score": time}
        for i, entry in enumerate(scores['highscores']):
            if time < entry['score']:
                scores['highscores'].insert(i, newEntry)
                if len(scores['highscores']) > 5:
                    scores['highscores'].pop()
                displayString += '\nNew Highscore! Wewt!'
                break
        else:
            if len(scores['highscores']) < 5:
                scores['highscores'].append(newEntry)
                displayString += '\nNew Highscore! Wewt!'

        with open(os.path.join(path, 'test.json'), 'w') as score_file:
            score_file.write(json.dumps(scores))

        displayString += '\n\nHighscores:\n'
        for i, sc in enumerate(scores['highscores']):
            displayString += '{}. {} ({})\n'.format(i + 1, sc["score"],
                                                    sc["date"])

        wnBox = Qt.QMessageBox(Qt.QMessageBox.NoIcon, 'You Win!',
                               displayString, Qt.QMessageBox.Ok)
        wnBox.exec_()
 def item_changed(self, Qitem):        
     try:
         test = float(Qitem.text())
     except ValueError:
         Msgbox = Qt.QMessageBox()
         Msgbox.setText("Value must be number! Use '.' for decimal places!")
         Msgbox.exec()
         try: 
             Qitem.setText(str(self.lookup_table_matrix[Qitem.row()][Qitem.column()]))
         except: 
             Qitem.setText('0')
    def abort_clicked(self):
        if self._thread is None or not self.programming:
            return

        msg = Qt.QMessageBox(self)
        msg.setIcon(Qt.QMessageBox.Question)
        msg.setText('Are you sure to abort the programming?\n'
                    'It can leave the icepap in bad condition')
        msg.setWindowTitle("Warning")
        msg.addButton(Qt.QMessageBox.Yes)
        msg.addButton(Qt.QMessageBox.No)
        result = msg.exec_()
        if result == Qt.QMessageBox.Yes:
            self._thread.kill()
            self._thread.join()
            self.programming = False
Exemple #4
0
 def dialog_critical(self, s):
     dlg = Qt.QMessageBox(self)
     dlg.setText(s)
     dlg.setIcon(Qt.QMessageBox.Critical)
     dlg.show()
Exemple #5
0
def show_exception(exception, **kwargs):
    """
    Process unhandled exception.

    If there's a main window (i.e. GUI has been started), the error
    message box showing details about the exception is displayed.
    Additionally, in debug mode, traceback is shown in the details area
    of the message box.

    If there is no main window, error is printed to the terminal.

    The following keyword arguments are accepted:

    - message (str): Custom error message text.
    - traceback (traceback): Traceback object.

    Arguments:
        exception (Exception): Exception object.
        **kwargs: Arbitrary keyword arguments.
    """
    message = kwargs.get("message")
    trace = kwargs.get("traceback")

    message_title = message if message \
        else translate("AsterStudy", "Unexpected error")
    message_type = translate("AsterStudy", "Type:")
    message_value = translate("AsterStudy", "Value:")
    message_traceback = translate("AsterStudy", "Traceback:")

    exc_type = type(exception).__name__
    exc_value = exception.args
    exc_traceback = message_traceback + "\n" + \
        "\n".join(traceback.format_tb(trace)) if trace else \
        traceback.format_exc(exception)

    windows = [i for i in Q.QApplication.topLevelWidgets() \
                   if isinstance(i, Q.QMainWindow)]
    window = windows[0] if windows else None

    if window is None:
        print message_title
        print message_type, exc_type
        print message_value, exc_value
        print exc_traceback
    else:
        wait_cursor(False, force=True)
        msg_box = Q.QMessageBox(
            Q.QMessageBox.Critical,  # icon
            "AsterStudy",  # title
            message_title,  # text
            Q.QMessageBox.Ok,  # buttons
            window)  # parent
        informative = "{tlab} {tval}<br>{vlab} {vval}".format(
            tlab=bold(message_type),
            tval=exc_type,
            vlab=bold(message_value),
            vval=exc_value)
        msg_box.setInformativeText(informative)
        if debug_mode():
            msg_box.setDetailedText(exc_traceback)
            textbox = msg_box.findChild(Q.QTextEdit)
            if textbox:
                textbox.setMinimumWidth(400)
        msg_box.setEscapeButton(msg_box.button(Q.QMessageBox.Ok))
        msg_box.show()
Exemple #6
0
 def createErrorMessage(self, parent):
     self.error_message = Qt.QMessageBox(parent)