コード例 #1
0
ファイル: spiki.py プロジェクト: threeme3/spiki
 def showInvalidParametersErrorMsg(self):
     msg = QMessageBox()
     msg.setIcon(QMessageBox.Critical)
     msg.setText('It is physically impossible to produce an inductor from the given inductor parameters')
     msg.setInformativeText('Please adjust one or more of the inductor parameters and try again')
     msg.setWindowTitle("Error")
     msg.exec()
コード例 #2
0
ファイル: errors.py プロジェクト: JustDreamer7/reportSW
def dataError():
    msg = QMessageBox()
    # msg.setIcon(QMessageBox.icon())
    msg.setText("Date-time Error")
    msg.setInformativeText('Начальная дата обработки данных больше конечной')
    msg.setWindowTitle("Error")
    msg.exec()
コード例 #3
0
def excepthook(exc_type, exc_value, traceback_obj):
    # "redirect" stderr to an in memory buffer in order to capture output of sys.excepthook() for use in GUI message
    sys.stderr = _text_buffer
    _original_hook(exc_type, exc_value, traceback_obj)

    # This is for me using PyCharm.
    # It will cause the traceback to be printed in the "Run" window,
    # providing a clickable link to the offending line.
    print(_text_buffer.getvalue(), file=_original_stderr)

    # make traceback visible in GUI
    font = QFont("non-existent")
    font.setStyleHint(QFont.StyleHint.TypeWriter)
    error_box = QMessageBox()
    error_box.setFont(font)
    error_box.setIcon(QMessageBox.Critical)
    error_box.setWindowTitle(
        "Warning: Something Wicked This Way Comes...\t\t\t\t\t\t\t\t\t")
    error_box.setText("<h2>An unhandled exception occurred.</h2>")
    error_box.setInformativeText(_text_buffer.getvalue())
    error_box.exec()

    # prevent accumulation of messages cluttering output
    _text_buffer.truncate(0)

    sys.stderr = _original_stderr
コード例 #4
0
    def closeEvent(self, event):
        if self.isEdited:
            # pop up dialog to alert user of unsaved edits.
            # offer then a chance to save before exiting.
            #
            messageBox = QMessageBox(self)
            messageBox.setIcon(QMessageBox.Icon.Question)
            messageBox.setWindowTitle("Close Check")
            messageBox.setText("You Have Unsaved Edits")
            messageBox.setInformativeText(
                "You have made edits that have not been saved.\nReally close and not save?"
            )
            messageBox.setStandardButtons(QMessageBox.StandardButtons.Yes
                                          | QMessageBox.StandardButtons.No)
            #
            # change the default Yes and No buttons to really say
            # what then mean: Yes = Save and No = Quit.
            # the button actions then match exactly what the dialog
            # is saying and there should be no disonnance.
            #
            buttonSave = messageBox.button(QMessageBox.StandardButtons.Yes)
            buttonSave.setText("Save")
            buttonQuit = messageBox.button(QMessageBox.StandardButtons.No)
            buttonQuit.setText("Close")
            messageBox.setDefaultButton(QMessageBox.StandardButtons.Yes)
            buttonReply = messageBox.exec()

            if buttonReply == QMessageBox.StandardButtons.Yes:
                print("QMessageBox.Save")
                event.accept()
            else:
                print("QMessageBox.Close")
        else:
            print("Close event")
            event.accept()
コード例 #5
0
    def _select_bridge(self, index):
        bridge = self._bridges[index]
        self._settings.setValue('selected_bridge', index)
        self._manager = DiscoBall(bridge['value'])

        try:
            self._lights = self._manager.get_light_list()
            self.lightsList.clear()
            for light in self._lights:
                self.lightsList.addItem(light['value'])
            self._select_light(0)

        except BridgeNotRegisteredException as e:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Icon.Warning)
            msg.setText(
                "This application is not registered with this Hue Bridge")
            msg.setInformativeText(
                "Please press the register button on top of the bridge and click the retry button"
            )
            msg.setWindowTitle("Error")
            msg.show()
コード例 #6
0
    def loadGraphics(self):
        dbfilename = self.obsTb.dbFilename
        if dbfilename != None:
            self.session = connectDatabase(dbfilename)
        else:
            msg = QMessageBox()
            # msg.setIcon(QMessageBox.Icon.Information)
            msg.setText('The database file is not defined.')
            msg.setInformativeText(
                'In order to set the database file, open the Observation Toolbox'
            )
            msg.setIcon(QMessageBox.Icon.Critical)
            msg.exec()
            return

        for gitem in self.gView.scene().items():
            if isinstance(gitem, QGraphicsItemGroup):
                self.gView.scene().removeItem(gitem)

        q_line = self.session.query(Line)
        q_zone = self.session.query(Zone)
        if q_line.all() == [] and q_zone.all() == []:
            QMessageBox.information(self, 'Warning!',
                                    'There is no graphics to load!')
            return

        line_items = []
        for line in q_line:
            p1 = line.points[0]
            p2 = line.points[1]

            if line.type != None:
                lineType = line.type.name
            else:
                lineType = None
            gItmGroup = self.generate_itemGroup([p1.x, p2.x], [p1.y, p2.y],
                                                str(line.idx), lineType)
            self.gScene.addItem(gItmGroup)

            line_items.append(str(line.idx))

        self.obsTb.line_list_wdgt.clear()
        self.obsTb.line_list_wdgt.addItems(line_items)
        self.obsTb.line_list_wdgt.setCurrentRow(0)

        self.obsTb.line_newRecButton.setEnabled(False)
        self.obsTb.line_saveButton.setEnabled(True)
        self.obsTb.line_saveButton.setText('Edit line(s)')
        self.obsTb.line_saveButton.setIcon(QIcon('icons/edit.png'))

        zone_items = []
        for zone in q_zone:
            if zone.type != None:
                zoneType = zone.type.name
            else:
                zoneType = None
            gItmGroup = self.generate_itemGroup(
                [point.x for point in zone.points],
                [point.y for point in zone.points], str(zone.idx), zoneType)
            self.gScene.addItem(gItmGroup)

            zone_items.append(str(zone.idx))

        self.obsTb.zone_list_wdgt.clear()
        self.obsTb.zone_list_wdgt.addItems(zone_items)
        self.obsTb.zone_list_wdgt.setCurrentRow(0)

        self.obsTb.zone_newRecButton.setEnabled(False)
        self.obsTb.zone_saveButton.setEnabled(True)
        self.obsTb.zone_saveButton.setText('Edit zone(s)')
        self.obsTb.zone_saveButton.setIcon(QIcon('icons/edit.png'))
コード例 #7
0
    def saveGraphics(self):
        dbfilename = self.obsTb.dbFilename
        if dbfilename != None:
            self.session = connectDatabase(dbfilename)
        else:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)
            msg.setText('The database file is not defined.')
            msg.setInformativeText(
                'In order to set the database file, open the Observation Toolbox'
            )
            msg.setIcon(QMessageBox.Critical)
            msg.exec_()
            return

        if self.gView.unsavedLines == [] and self.gView.unsavedZones == [] and \
                self.gView.unsavedPoints == []:
            QMessageBox.information(self, 'Save',
                                    'No new graphical items to save!')
            return

        for item in self.gView.unsavedLines:
            x1 = round(item.line().x1(), 2)
            y1 = round(item.line().y1(), 2)
            x2 = round(item.line().x2(), 2)
            y2 = round(item.line().y2(), 2)
            line = Line(None, None, x1, y1, x2, y2)
            self.session.add(line)
            self.session.flush()
            label = self.generate_itemGroup([x1, x2], [y1, y2], line.idx)
            self.gView.scene().addItem(label)

        for item in self.gView.unsavedZones:
            xs = []
            ys = []
            for p in item.polygon():
                xs.append(round(p.x(), 2))
                ys.append(round(p.y(), 2))
            zone = Zone(None, None, xs, ys)
            self.session.add(zone)
            self.session.flush()

            label = self.generate_itemGroup(xs, ys, zone.idx)
            self.gView.scene().addItem(label)

        for item in self.gView.unsavedPoints:
            x = round(item.rect().center().x(), 2)
            y = round(item.rect().center().y(), 2)

            point = Point(x, y)
            self.session.add(point)
            self.session.flush()

            label = self.generate_itemGroup([x], [y], point.idx)
            self.gView.scene().removeItem(item)
            self.gView.scene().addItem(label)

        QMessageBox.information(
            self, 'Save',
            '{} point(s), {} line(s) and {} zone(s) saved to database successfully!'
            .format(len(self.gView.unsavedPoints),
                    len(self.gView.unsavedLines),
                    len(self.gView.unsavedZones)))
        self.gView.unsavedLines = []
        self.gView.unsavedZones = []
        self.gView.unsavedPoints = []

        self.session.commit()