Example #1
0
    def __init__(self,
                 text,
                 font,
                 pen,
                 position,
                 maxSize,
                 alignment=QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft):
        DisplayShape.__init__(self, position, maxSize)

        self.font = QtGui.QFont(font)
        self.text = QtCore.QString(text)
        self.pen = pen
        self.alignment = alignment

        fm = QtGui.QFontMetricsF(self.font)
        self.textRect = fm.boundingRect(
            QtCore.QRectF(QtCore.QPointF(0, 0), maxSize), self.alignment,
            self.text)

        textWidth = max(fm.width(self.text), self.textRect.width())
        textHeight = max(fm.height(), self.textRect.height())

        scale = min(maxSize.width() / textWidth, maxSize.height() / textHeight)

        self.font.setPointSizeF(self.font.pointSizeF() * scale)
        fm = QtGui.QFontMetricsF(self.font)
        self.textRect = fm.boundingRect(
            QtCore.QRectF(QtCore.QPointF(0, 0), maxSize), self.alignment,
            self.text)
        self.baselineStart = QtCore.QPointF(
            self.textRect.left(),
            self.textRect.bottom() - fm.descent())
Example #2
0
 def minimumSizeHint(self) -> QtCore.QSize:
     font = QtGui.QFont(self.font())
     font.setPointSize(font.pointSize() - 1)
     fm = QtGui.QFontMetricsF(font)
     return QtCore.QSize(
         fm.width(FractionSlider.WSTRING) * self.__denominator,
         (fm.height() * 4 + FractionSlider.YMARGIN))
Example #3
0
    def _recalculate_header(self):
        fnt_title = bold_font(self._system_font)
        font_metric = QtG.QFontMetricsF(fnt_title)

        if self._full_title == str():
            prop = self.property('title')
            if prop is not None:
                self._title_bound_rect = font_metric.boundingRect(prop)
                self._full_title = prop
            else:
                self._title_bound_rect = font_metric.boundingRect("UNTITLED")
        else:
            self._title_bound_rect = font_metric.boundingRect(self._full_title)

        title_space = self.width() - (self._icon_width +
                                      self._base_margin.right() +
                                      self._base_margin.left())

        # If the title is too big to fit in the box
        if self._title_bound_rect.width() > title_space:
            self._title = chop_title(self._full_title, title_space,
                                     self._title_bound_rect.width())
            self._title_bound_rect = font_metric.boundingRect(self._title)
        else:
            self._title = self._full_title

        self._header_rect = QRect(
            self._base_margin.left(), self._base_margin.top(),
            self.width() -
            (self._base_margin.left() - self._base_margin.right()),
            self._title_bound_rect.height() + self._base_margin.top())
Example #4
0
    def paintEvent(self, event: QtGui.QPaintEvent):
        font = QtGui.QFont(self.font())
        font.setPointSize(font.pointSize() - 1)
        fm = QtGui.QFontMetricsF(font)
        fracWidth = fm.width(FractionSlider.WSTRING)
        indent = fm.boundingRect("9").width() / 2.0
        # if not X11:
        #     FracWidth *= 1.5
        span = self.width() - (FractionSlider.XMARGIN * 2)
        value = self.__numerator / float(self.__denominator)

        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
        painter.setPen(self.palette().color(QtGui.QPalette.Mid))
        painter.setBrush(self.palette().brush(QtGui.QPalette.AlternateBase))
        painter.drawRect(self.rect())

        segColor = QtGui.QColor(QtCore.Qt.green).dark(120)
        segLineColor = segColor.dark()
        painter.setPen(segLineColor)
        painter.setBrush(segColor)
        painter.drawRect(FractionSlider.XMARGIN, FractionSlider.YMARGIN, span,
                         fm.height())

        textColor = self.palette().color(QtGui.QPalette.Text)
        segWidth = span / self.__denominator
        segHeight = fm.height() * 2
        nRect = fm.boundingRect(FractionSlider.WSTRING)
        x = FractionSlider.XMARGIN
        yoffset = segHeight + fm.height()

        for i in range(self.__denominator + 1):
            painter.setPen(segLineColor)
            painter.drawLine(x, FractionSlider.YMARGIN, x, segHeight)
            painter.setPen(textColor)
            y = segHeight
            rect = QtCore.QRectF(nRect)
            rect.moveCenter(QtCore.QPointF(x, y + fm.height() / 2.0))
            painter.drawText(rect, QtGui.Qt.AlignCenter, str(i))
            y = yoffset
            rect.moveCenter(QtCore.QPointF(x, y + fm.height() / 2.0))
            painter.drawText(rect, QtCore.Qt.AlignCenter,
                             str(self.__denominator))
            painter.drawLine(QtCore.QPointF(rect.left() + indent, y),
                             QtCore.QPointF(rect.right() - indent, y))
            x += segWidth

        span = int(span)
        y = FractionSlider.YMARGIN - 0.5
        triangle = [
            QtCore.QPointF(value * span, y),
            QtCore.QPointF((value * span) + (2 * FractionSlider.XMARGIN), y),
            QtCore.QPointF((value * span) + FractionSlider.XMARGIN,
                           fm.height())
        ]
        painter.setPen(QtGui.Qt.yellow)
        painter.setBrush(QtGui.Qt.darkYellow)
        painter.drawPolygon(triangle)
Example #5
0
    def setupSceneItems(self):
        if Colors.showFps:
            self.fpsLabel = DemoTextItem("FPS: --", Colors.buttonFont(),
                                         QtCore.Qt.white, -1, self.scene, None,
                                         DemoTextItem.DYNAMIC_TEXT)
            self.fpsLabel.setZValue(100)
            self.fpsLabel.setPos(
                Colors.stageStartX,
                600 - QtGui.QFontMetricsF(Colors.buttonFont()).height() - 5)

        self.trolltechLogo = ImageItem(
            QtGui.QImage(':/images/trolltech-logo.png'), 1000, 1000,
            self.scene, None, True, 0.5)
        self.qtLogo = ImageItem(QtGui.QImage(':/images/qtlogo_small.png'),
                                1000, 1000, self.scene, None, True, 0.5)
        self.trolltechLogo.setZValue(100)
        self.qtLogo.setZValue(100)
        self.pausedLabel = DemoTextItem("PAUSED", Colors.buttonFont(),
                                        QtCore.Qt.white, -1, self.scene, None)
        self.pausedLabel.setZValue(100)
        fm = QtGui.QFontMetricsF(Colors.buttonFont())
        self.pausedLabel.setPos(Colors.stageWidth - fm.width("PAUSED"),
                                590 - fm.height())
        self.pausedLabel.setRecursiveVisible(False)
Example #6
0
    def paintEvent(self, event):
        painter = QtGui.QPainter(self)

        font = painter.font()
        font.setPointSize(75)
        font.setWeight(QtGui.QFont.Bold)
        painter.setFont(font)

        metrics = QtGui.QFontMetricsF(self.font())
        rect = metrics.boundingRect(f'{self.daysRemaining}')
        rect.translate(-rect.center())

        painter.setPen(QtGui.QPen(QtCore.Qt.black))
        # painter.translate(100, 100)
        painter.drawText(QtCore.QRectF(0, 0, self.width(), self.height()),
                         QtCore.Qt.AlignCenter, f'{self.daysRemaining}')
        settings.setValue("mainWindow/Position", self.pos())
        settings.setValue("mainWindow/State", self.saveState())

        settings.setValue("colorDialog/Size", self.colorDialog.size())
        settings.setValue("colorDialog/Position", self.colorDialog.pos())
        visible = int(self.colorDialog.isVisible())
        settings.setValue("colorDialog/Visible", visible)

        if len(self.model.previousViews) > 10:
            self.model.previousViews = self.model.previousViews[-10:]
        if len(self.model.subsequentViews) > 10:
            self.model.subsequentViews = self.model.subsequentViews[-10:]

        with open('plot_settings.pkl', 'wb') as file:
            pickle.dump(self.model, file)


if __name__ == '__main__':

    app = QApplication(sys.argv)
    app.setOrganizationName("OpenMC")
    app.setOrganizationDomain("xxxxxgithub.com/openmc-dev/")
    app.setApplicationName("xxxxxOpenMC Plot Explorer")
    app.setWindowIcon(QtGui.QIcon('openmc_logo.png'))
    app.setAttribute(QtCore.Qt.AA_DontShowIconsInMenus, True)

    FM = QtGui.QFontMetricsF(app.font())
    mainWindow = MainWindow()
    mainWindow.show()
    sys.exit(app.exec_())