コード例 #1
0
    def _drawValue(self, painter, value, position, state):

        size = self.size()

        color = QtGui.QColor(
            120, 120, 120) if state == state.DisabledState else QtGui.QColor(
                240, 220, 40)
        painter.setPen(color)

        # Draw vertical line at position ensuring we don't clip it
        # at the edges of the widget.

        lineWidth = 2
        position = max(
            min(int(position) - (lineWidth / 2), size.x - lineWidth), 0)
        painter.fillRect(position, 0, lineWidth, size.y, color)

        # Draw frame number to the left of the playhead (unless we'd go off the
        # edge). Most cursors are pointing to the left so this makes it easier
        # to read the number when hovering.

        font = painter.font()
        font.setPixelSize(10)
        painter.setFont(font)

        frameText = GafferUI.NumericWidget.valueToString(value)
        frameTextSize = QtGui.QFontMetrics(painter.font()).size(
            QtCore.Qt.TextSingleLine, frameText)

        textMargin = 6
        textX = position - frameTextSize.width() - textMargin
        if textX < textMargin:
            textX = position + textMargin

        painter.drawText(textX, frameTextSize.height(), frameText)
コード例 #2
0
ファイル: _PlugTableDelegate.py プロジェクト: JeromR/gaffer
    def paint(self, painter, option, index):

        QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)

        flags = index.flags()
        enabled = flags & QtCore.Qt.ItemIsEnabled and flags & QtCore.Qt.ItemIsEditable
        cellPlugEnabled = index.data(_PlugTableModel.CellPlugEnabledRole)

        if enabled and cellPlugEnabled:
            return

        painter.save()

        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        overlayColor = QtGui.QColor(40, 40, 40, 200)

        if not cellPlugEnabled:

            painter.fillRect(option.rect, overlayColor)

            pen = QtGui.QPen(QtGui.QColor(20, 20, 20, 150))
            pen.setWidth(2)
            painter.setPen(pen)
            painter.drawLine(option.rect.bottomLeft(), option.rect.topRight())

        if not enabled:

            painter.fillRect(option.rect, overlayColor)

        painter.restore()
コード例 #3
0
ファイル: utils.py プロジェクト: phenom-films/dayu_widgets
def generate_text_pixmap(width, height, text, alignment=QtCore.Qt.AlignCenter):
    # Import local modules
    from dayu_widgets import dayu_theme

    # draw a pixmap with text
    pix_map = QtGui.QPixmap(width, height)
    pix_map.fill(QtGui.QColor(dayu_theme.background_in_color))
    painter = QtGui.QPainter(pix_map)
    painter.setRenderHints(QtGui.QPainter.TextAntialiasing)
    font = painter.font()
    font.setFamily(dayu_theme.font_family)
    painter.setFont(font)
    painter.setPen(QtGui.QPen(QtGui.QColor(dayu_theme.secondary_text_color)))

    font_metrics = painter.fontMetrics()
    text_width = font_metrics.horizontalAdvance(text)
    text_height = font_metrics.height()
    x = width / 2 - text_width / 2
    y = height / 2 - text_height / 2
    if alignment & QtCore.Qt.AlignLeft:
        x = 0
    elif alignment & QtCore.Qt.AlignRight:
        x = width - text_width
    elif alignment & QtCore.Qt.AlignTop:
        y = 0
    elif alignment & QtCore.Qt.AlignBottom:
        y = height - text_height

    painter.drawText(x, y, text)
    painter.end()
    return pix_map
コード例 #4
0
class SelectionRect(QtWidgets.QGraphicsWidget):
    __backgroundColor = QtGui.QColor(100, 100, 100, 50)
    __pen = QtGui.QPen(QtGui.QColor(255, 255, 255), 1.0, QtCore.Qt.DashLine)

    def __init__(self, graph, mouseDownPos):
        super(SelectionRect, self).__init__()
        self.setZValue(-1)

        self.__graph = graph
        self.__graph.scene().addItem(self)
        self.__mouseDownPos = mouseDownPos
        self.setPos(self.__mouseDownPos)
        self.resize(0, 0)

    def setDragPoint(self, dragPoint):
        topLeft = QtCore.QPointF(self.__mouseDownPos)
        bottomRight = QtCore.QPointF(dragPoint)
        if dragPoint.x() < self.__mouseDownPos.x():
            topLeft.setX(dragPoint.x())
            bottomRight.setX(self.__mouseDownPos.x())
        if dragPoint.y() < self.__mouseDownPos.y():
            topLeft.setY(dragPoint.y())
            bottomRight.setY(self.__mouseDownPos.y())
        self.setPos(topLeft)
        self.resize(bottomRight.x() - topLeft.x(),
                    bottomRight.y() - topLeft.y())

    def paint(self, painter, option, widget):
        rect = self.windowFrameRect()
        painter.setBrush(self.__backgroundColor)
        painter.setPen(self.__pen)
        painter.drawRect(rect)

    def destroy(self):
        self.__graph.scene().removeItem(self)
コード例 #5
0
ファイル: Slider.py プロジェクト: timlehr/gaffer
    def _drawPosition(self, painter, position, highlighted, opacity=1):

        size = self.size()

        pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 255 * opacity))
        pen.setWidth(1)
        painter.setPen(pen)

        ## \todo These colours need to come from the style, once we've
        # unified the Gadget and Widget styling.
        if highlighted:
            brush = QtGui.QBrush(QtGui.QColor(119, 156, 255, 255 * opacity))
        else:
            brush = QtGui.QBrush(QtGui.QColor(128, 128, 128, 255 * opacity))

        painter.setBrush(brush)

        if position < 0:
            painter.drawPolygon(
                QtGui.QPolygonF([
                    QtCore.QPointF(8, 4),
                    QtCore.QPointF(8, size.y - 4),
                    QtCore.QPointF(2, size.y / 2),
                ]))
        elif position > 1:
            painter.drawPolygon(
                QtGui.QPolygonF([
                    QtCore.QPointF(size.x - 8, 4),
                    QtCore.QPointF(size.x - 8, size.y - 4),
                    QtCore.QPointF(size.x - 2, size.y / 2),
                ]))
        else:
            painter.drawEllipse(QtCore.QPoint(position * size.x, size.y / 2),
                                size.y / 4, size.y / 4)
コード例 #6
0
    def refresh_all_task_statuses(self):
        """Refresh all available task statuses"""

        self.status.clear()

        for state in gazu.task.all_task_statuses():
            self.status.addItem(state['name'])
            index = self.status.count()-1
            self.status.setItemData(index, state, self.StatusRole)

            # Use color from the status
            color = QtGui.QColor(state['color'])

            # The "Todo" status is not user-defined and always returns the
            # bright online White Theme color which is near pure white.
            # So for that status we force the dark theme's grey.
            if state['name'] == "Todo":
                color = QtGui.QColor("#5F626A")

            self.status.setItemData(index, color, QtCore.Qt.BackgroundRole)

            # Force white text
            self.status.setItemData(index,
                                    QtGui.QColor("white"),
                                    QtCore.Qt.ForegroundRole)
コード例 #7
0
    def on_value_edited(self):
        """

        :return:
        """
        item = self.tree_widget.selectedItems()[0]
        if self.key != item.text(0):
            dict_ = self.get_dictionary(item, item.text(0), item.text(1))
            self.set_value(item, item.text(0), item.text(1))
            if self.project:
                self.save_globals(dict_)
                item.setForeground(0, QtGui.QBrush(QtGui.QColor(0, 255, 0)))
                return
            if self.company:
                self.save_globals(dict_)
                item.setForeground(0, QtGui.QBrush(QtGui.QColor(0, 0, 255)))
                return

            self.save_globals(dict_)
            return
        if self.value != item.text(1):
            dict_ = self.get_dictionary(item, item.text(0), item.text(1))
            self.set_value(item, item.text(0), item.text(1))
            if self.project:
                self.save_globals(dict_)
                item.setForeground(1, QtGui.QBrush(QtGui.QColor(0, 255, 0)))
                return
            if self.company:
                self.save_globals(dict_)
                item.setForeground(1, QtGui.QBrush(QtGui.QColor(0, 0, 255)))
                return
            self.save_globals(dict_)
            return
コード例 #8
0
ファイル: scene.py プロジェクト: zhollosy/NodeGraphQt
    def drawBackground(self, painter, rect):
        super(NodeScene, self).drawBackground(painter, rect)

        painter.save()
        painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
        painter.setBrush(self.backgroundBrush())

        if self._grid_mode is VIEWER_GRID_DOTS:
            pen = QtGui.QPen(QtGui.QColor(*self.grid_color), 0.65)
            self._draw_dots(painter, rect, pen, VIEWER_GRID_SIZE)

        elif self._grid_mode is VIEWER_GRID_LINES:
            zoom = self.viewer().get_zoom()
            if zoom > -0.5:
                pen = QtGui.QPen(QtGui.QColor(*self.grid_color), 0.65)
                self._draw_grid(painter, rect, pen, VIEWER_GRID_SIZE)

            color = QtGui.QColor(*self._bg_color).darker(150)
            if zoom < -0.0:
                color = color.darker(100 - int(zoom * 110))
            pen = QtGui.QPen(color, 0.65)
            self._draw_grid(painter, rect, pen, VIEWER_GRID_SIZE * 8)

        if not self.editable:
            pen = QtGui.QPen(QtGui.QColor(*(90, 90, 90)))
            self._draw_text(painter, pen)

        painter.restore()
コード例 #9
0
    def paintEvent(self, event):

        if not self.getBusy():
            return

        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        width, height = float(self.width()), float(self.height())
        centreX, centreY = width / 2, height / 2
        radius = self.__size / 2.0
        numCircles = 10
        circleRadius = radius / 5
        penWidth = circleRadius / 10

        for i in range(0, numCircles):

            theta = i * 360.0 / numCircles + time.time() * 10
            circleCentreX = centreX - (radius - circleRadius - penWidth
                                       ) * math.cos(math.radians(theta))
            circleCentreY = centreY + (radius - circleRadius - penWidth
                                       ) * math.sin(math.radians(theta))

            alpha = 1 - ((math.fmod(theta + time.time() * 270, 360)) / 360)

            ## \todo Colours (and maybe even drawing) should come from style
            brush = QtGui.QBrush(QtGui.QColor(119, 156, 189, alpha * 255))
            painter.setBrush(brush)

            pen = QtGui.QPen(QtGui.QColor(0, 0, 0, alpha * 255))
            pen.setWidth(penWidth)
            painter.setPen(pen)

            painter.drawEllipse(QtCore.QPointF(circleCentreX, circleCentreY),
                                circleRadius, circleRadius)
コード例 #10
0
    def paint(self, painter, option, widget):
        """
        Draws the backdrop sizer on the bottom right corner.

        Args:
            painter (QtGui.QPainter): painter used for drawing the item.
            option (QtGui.QStyleOptionGraphicsItem):
                used to describe the parameters needed to draw.
            widget (QtWidgets.QWidget): not used.
        """
        painter.save()

        rect = self.boundingRect()
        item = self.parentItem()
        if item and item.selected:
            color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
        else:
            color = QtGui.QColor(*item.color)
            color = color.darker(110)
        path = QtGui.QPainterPath()
        path.moveTo(rect.topRight())
        path.lineTo(rect.bottomRight())
        path.lineTo(rect.bottomLeft())
        painter.setBrush(color)
        painter.setPen(QtCore.Qt.NoPen)
        painter.fillPath(path, painter.brush())

        painter.restore()
コード例 #11
0
ファイル: Slider.py プロジェクト: sshrestha-fractal/gaffer
    def _drawValue(self, painter, value, position, state):

        size = self.size()

        pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 255))
        pen.setWidth(1)
        painter.setPen(pen)

        if state == state.NormalState:
            color = QtGui.QColor(128, 128, 128, 255)
        else:
            color = QtGui.QColor(119, 156, 255, 255)
        painter.setBrush(QtGui.QBrush(color))

        if state == state.DisabledState:
            painter.setOpacity(0.5)

        if position < 0:
            painter.drawPolygon(
                QtGui.QPolygonF([
                    QtCore.QPointF(8, 4),
                    QtCore.QPointF(8, size.y - 4),
                    QtCore.QPointF(2, size.y / 2),
                ]))
        elif position > size.x:
            painter.drawPolygon(
                QtGui.QPolygonF([
                    QtCore.QPointF(size.x - 8, 4),
                    QtCore.QPointF(size.x - 8, size.y - 4),
                    QtCore.QPointF(size.x - 2, size.y / 2),
                ]))
        else:
            painter.drawEllipse(QtCore.QPoint(position, size.y / 2),
                                size.y / 4, size.y / 4)
コード例 #12
0
def assert_images_are_equal(image1, image2):
    # type: (str, str) -> None
    assert os.path.exists(image1), "image1 does not exists!"
    assert os.path.exists(image2), "image1 does not exists!"

    from Qt import QtGui

    image_left = QtGui.QImage()
    image_left.load(image1)
    image_right = QtGui.QImage()
    image_right.load(image2)

    assert image_left.width() == image_right.width(
    ), "Images are different in width!"
    assert image_left.height() == image_right.height(
    ), "Images are different in height!"

    for x in range(image_left.width()):
        for y in range(image_left.height()):
            color_left = QtGui.QColor(image_left.pixel(x, y))
            color_right = QtGui.QColor(image_right.pixel(x, y))
            red_diff = (color_left.red() - color_right.red()) >= 50
            green_diff = color_left.green() - color_right.green() >= 50
            blue_diff = color_left.blue() - color_right.blue() >= 50
            assert not red_diff and not green_diff and not blue_diff, "Pixel {}x{} does not match!".format(
                x, y)
コード例 #13
0
ファイル: MSlider.py プロジェクト: mischakolbe/ncloth_ui
    def paintEvent(self, event):
        """
        Automatically executed method that draws elements in QWidget
        """
        painter = QtGui.QPainter(self)
        pen = QtGui.QPen(QtGui.QColor(255, 255, 255), 1)

        for i, circle_value in enumerate(self.circle_values[:-1]):
            circle_percentage = self.circle_percentage(circle_value)

            rate = (i + 1) / float(len(self.circle_values) - 1)

            color = [
                d + (b - d) * rate
                for d, b in zip(self.darkest_color, self.brightest_color)
            ]

            pen.setColor(QtGui.QColor(*color))
            painter.setPen(pen)
            dia = self.min_circle_dia + (self.max_circle_dia -
                                         self.min_circle_dia) * rate

            # Define min and max pixel values of slider. values 5 and 4 empirically determined
            min_slider_pos = 5
            max_slider_pos = self.slider.size().width() - 4
            # Determine x-position of circle
            pos = circle_percentage * (max_slider_pos -
                                       min_slider_pos) + min_slider_pos

            painter.drawEllipse(
                QtCore.QPoint(pos,
                              self.slider.height() + self.y_offset), dia, dia)
コード例 #14
0
    def paintEvent(self, event):

        # NOTE https://stackoverflow.com/questions/20802315/round-edges-corner-on-a-qwidget-in-pyqt
        painter = QtGui.QPainter(self)
        painter.setRenderHint(painter.Antialiasing)
        painter.begin(self)
        # NOTE 添加灰度过渡
        gradient = QtGui.QLinearGradient(
            QtCore.QRectF(self.rect()).topLeft(),
            QtCore.QRectF(self.rect()).bottomLeft(),
        )
        gradient.setColorAt(0.2, QtGui.QColor(34, 34, 34))
        gradient.setColorAt(0.5, QtGui.QColor(111, 111, 111))
        gradient.setColorAt(0.8, QtGui.QColor(34, 34, 34))
        painter.setBrush(gradient)
        painter.drawRoundedRect(self.rect(), 10.0, 10.0)

        path = QtGui.QPainterPath()
        pen = QtGui.QPen(QtGui.QColor(34, 34, 34), 5)
        painter.setPen(pen)
        path.addRoundedRect(self.rect(), 10, 10)
        painter.setClipPath(path)
        painter.strokePath(path, painter.pen())
        painter.end()

        super(LauncherBase, self).paintEvent(event)
コード例 #15
0
    def data(self, obj, row, role=QtCore.Qt.DisplayRole):
        """
        Dim/brighten text depending on the history's index.

        :param obj: History changes list.
        :type obj: objetto.objects.ListObject

        :param row: Row.
        :type row: int

        :param role: Role.
        :type role: QtCore.Qt.ItemDataRole

        :return: Data.
        :rtype: str or objetto.bases.BaseObject
        """

        # Dim/brighten text.
        history = obj._parent
        if isinstance(history, HistoryObject):
            if role == QtCore.Qt.ForegroundRole:
                if row > history.index:  # TODO: use system colors
                    return QtGui.QBrush(QtGui.QColor(128, 128, 138, 100))
                elif history.index == row:
                    return QtGui.QBrush(QtGui.QColor(255, 255, 255, 255))

        return super(OQHistoryWidgetDefaultHeader, self).data(obj,
                                                              row,
                                                              role=role)
コード例 #16
0
 def getStyleSheet(self):
     MainColor_Lighter = QtGui.QColor(self.MainColor)
     MainColor_Lighter.setAlpha(128)
     ButtonG1 = self.ButtonsColor.lighter(120)
     ButtonG3 = self.ButtonsColor.darker(110)
     InputFieldHover = self.InputFieldColor.lighter(200)
     with open(STYLE_PATH, 'r') as f:
         styleString = f.read()
         return styleString % (
             "rgba%s" % str(self.TextColor.getRgb()),
             "rgba%s" % str(self.BgColor.getRgb()),
             "rgba%s" % str(self.BgColorDarker.getRgb()),
             "rgba%s" % str(self.BgColorBright.getRgb()),
             "rgba%s" % str(self.MainColor.getRgb()),
             "rgba%s" % str(MainColor_Lighter.getRgb()),
             "rgba%s" % str(MainColor_Lighter.getRgb()),
             "rgba%s" % str(self.BorderColor.getRgb()),
             "rgba%s" % str(self.InputFieldColor.getRgb()),
             "rgba%s" % str(InputFieldHover.getRgb()),
             "rgba%s" % str(MainColor_Lighter.getRgb()),
             "rgba%s" % str(self.TextSelectedColor.getRgb()),
             "rgba%s" % str(ButtonG1.getRgb()),
             "rgba%s" % str(self.ButtonsColor.getRgb()),
             "rgba%s" % str(ButtonG3.getRgb()),
             "rgba%s" % str(QtGui.QColor(0, 0, 0, 100).getRgb()))
コード例 #17
0
    def populate_render_trees(self, tree_widget, render_nodes, inherited,
                              others, excluded_types):
        tree_widget.clear()

        for node_type, nodes in render_nodes.items():
            parent_item = QtWidgets.QTreeWidgetItem([node_type])
            tree_widget.addTopLevelItem(parent_item)
            for node in nodes:
                child_item = QtWidgets.QTreeWidgetItem([node])
                for c in range(0, child_item.columnCount()):
                    child_item.setForeground(
                        c, QtGui.QBrush(QtGui.QColor(250, 180, 120)))
                parent_item.addChild(child_item)
                node_attributes = self.Converter.get_type_attributes(
                    node, inherited, others, excluded_types)
                for node_attribute, node_info in node_attributes.items():
                    item = QtWidgets.QTreeWidgetItem(
                        [node_attribute, node_info])
                    child_item.addChild(item)
                    if node_info == 'float3':
                        item.setForeground(
                            0, QtGui.QBrush(QtGui.QColor(250, 120, 120)))
                        attibute_children = self.Converter.get_attribute_children(
                            node_attribute, node)
                        if attibute_children:
                            for child_attribute in attibute_children:
                                child_attribute_item = QtWidgets.QTreeWidgetItem(
                                    [child_attribute, 'float'])
                                item.addChild(child_attribute_item)
                                child_attribute_item.setHidden(True)

        self.resize_trees(tree_widget)
コード例 #18
0
ファイル: OverLayWidget.py プロジェクト: FXTD-ODYSSEY/QtLib
    def paintEvent(self, event):

        # NOTE https://stackoverflow.com/questions/51687692/how-to-paint-roundedrect-border-outline-the-same-width-all-around-in-pyqt-pysi
        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        rectPath = QtGui.QPainterPath()
        height = self.height() - 4
        rectF = QtCore.QRectF(2, 2, self.width() - 4, height)

        # NOTE 绘制边界颜色
        if self.config.get("border", True):
            border_color = self.config.get("border_color",
                                           QtGui.QColor(255, 0, 0, 255))
            border_line = self.config.get("border_line", QtCore.Qt.SolidLine)
            border_cap = self.config.get("border_cap", QtCore.Qt.RoundCap)
            border_round = self.config.get("border_round", QtCore.Qt.RoundJoin)
            border_bevel = self.config.get("border_bevel", 15)
            border_pen = self.config.get("border_pen")

            rectPath.addRoundedRect(rectF, border_bevel, border_bevel)
            painter.setPen(border_pen if border_pen else QtGui.QPen(
                border_color, 2, border_line, border_cap, border_round))
            painter.drawPath(rectPath)

        rect = self.config.get("rect")
        if rect:
            rect_color = self.config.get("rect_color",
                                         QtGui.QColor(0, 255, 0, 125))
            rect_bevel = self.config.get("rect_bevel", 15)
            # NOTE 绘制背景颜色
            painter.setBrush(rect_color)
            painter.drawRoundedRect(rectF, rect_bevel, rect_bevel)
コード例 #19
0
ファイル: ColorSwatch.py プロジェクト: timlehr/gaffer
	def __updateCheckerColors( self ) :

		displayTransform = GafferUI.DisplayTransform.get()
		effectiveDisplayTransform = displayTransform if self.__useDisplayTransform else lambda x : x

		opaqueDisplayColor = self._qtColor( effectiveDisplayTransform( self.__color ) )
		self.__opaqueChecker.color0 = self.__opaqueChecker.color1 = opaqueDisplayColor
		if self.__color.dimensions()==3 :
			self.__transparentChecker.color0 = self.__transparentChecker.color1 = opaqueDisplayColor
		else :
			c = self.__color
			# We want the background colour to be the same whether or not we're using the display transform for
			# the main colour, so if we're not using the display transform later after compositing, we pre-apply
			# it to the background colours before compositing.
			bg0 = self.__linearBackgroundColor0 if self.__useDisplayTransform else displayTransform( self.__linearBackgroundColor0 )
			bg1 = self.__linearBackgroundColor1 if self.__useDisplayTransform else displayTransform( self.__linearBackgroundColor1 )
			# Now composite the main colour with the background colour. This is happening in linear space
			# if __useDisplayTransform is True, and in display space otherwise.
			color0 = bg0 * ( 1.0 - c.a ) + imath.Color3f( c.r, c.g, c.b ) * c.a
			color1 = bg1 * ( 1.0 - c.a ) + imath.Color3f( c.r, c.g, c.b ) * c.a

			self.__transparentChecker.color0 = self._qtColor( effectiveDisplayTransform( color0 ) )
			self.__transparentChecker.color1 = self._qtColor( effectiveDisplayTransform( color1 ) )

		## \todo Colour should come from the style when we have styles applying to Widgets as well as Gadgets
		self.__opaqueChecker.borderColor = QtGui.QColor( 119, 156, 255 ) if self.getHighlighted() else None
		self.__transparentChecker.borderColor = QtGui.QColor( 119, 156, 255 ) if self.getHighlighted() else None

		self._qtWidget().update()
コード例 #20
0
    def paint(self, painter, option, widget):
        """Override of QtWidgets.QGraphicsItem paint."""
        painter.setRenderHints(QtGui.QPainter.Antialiasing
                               | QtGui.QPainter.TextAntialiasing
                               | QtGui.QPainter.SmoothPixmapTransform)
        if self.filled:
            brush = QtGui.QBrush(self.color)
            painter.setBrush(brush)
            if self.color.lightness() < 100:
                pen_color = QtGui.QColor(self.color.lighter(300))
            else:
                pen_color = QtGui.QColor(self.color.darker(300))
            pen = QtGui.QPen(pen_color)
            pen.setJoinStyle(QtCore.Qt.RoundJoin)
            painter.setPen(QtCore.Qt.NoPen)
        else:
            brush = QtGui.QBrush(QtCore.Qt.white, QtCore.Qt.Dense6Pattern)
            painter.setBrush(brush)
            pen = QtGui.QPen(QtCore.Qt.white)
            pen.setStyle(QtCore.Qt.DotLine)
            painter.setPen(pen)

        # draw triangle
        points = [
            QtCore.QPointF(0 - (self.width * .5), 0),
            QtCore.QPointF(self.width * .5, 0),
            QtCore.QPointF(0, self.height)
        ]
        painter.drawPolygon(points)
        # Draw outline
        if self.filled:
            painter.setBrush(QtCore.Qt.NoBrush)
            painter.setPen(pen)
            painter.drawLine(0 - (self.width * .5), 0, 0, self.height)
            painter.drawLine(0, self.height, self.width * .5, 0)
コード例 #21
0
    def __init__(self,
                 pos=QtCore.QPointF(),
                 radius=3,
                 hover_width=0.5,
                 color=QtGui.QColor(255, 255, 255, 255),
                 attr_name_represented='',
                 is_exec=False,
                 is_input=False,
                 is_break=False,
                 is_start=False,
                 start_idx=-1):
        super(NodeGraphicsPlug, self).__init__()
        self.setAcceptHoverEvents(True)
        self.setPos(pos)
        # TODO benchmark this cache setting to see if it helps or hurts performance
        self.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)

        self.radius = radius
        self.hover_width = hover_width
        self.color = QtGui.QColor(color)
        self.attr_name_represented = attr_name_represented
        self.is_exec = is_exec
        if is_exec:
            self.attr_name_represented = nxt_node.INTERNAL_ATTRS.EXECUTE_IN
        self.is_input = is_input
        self.is_break = is_break
        self.is_start = is_start

        self.is_hovered = False
コード例 #22
0
 def setDefault(self, defcolor):
     if defcolor != self.prevColor:
         self.prevColor = defcolor
         self._pinColor = QtGui.QColor(*defcolor)
         for e in self.connections:
             e.setColor(QtGui.QColor(*defcolor))
         self.OnPinChanged.emit(self)
         self.update()
コード例 #23
0
ファイル: TaskPanel.py プロジェクト: 3dzayn/gazu-publisher
 def update_header_task_type(self):
     self.header_task_type.setText(self.task["task_type_name"])
     task_type_color = QtGui.QColor(self.task["task_type_color"])
     background_color = QtGui.QColor(main_color)
     mix_color = combine_colors(task_type_color, background_color)
     self.header_task_type.setStyleSheet(
         """QFrame{{ background: {0};border-radius: 4px;padding: 2px; }}""".
         format(mix_color.name()))
コード例 #24
0
    def paint(self, painter, option, widget=None):
        """Re-implement paint method

        """
        # Update level of detail
        self._lod = option.levelOfDetailFromTransform(painter.worldTransform())

        # Update brush
        palette = (self.scene().palette() if self.scene() else option.palette)
        brush = palette.text()
        if option.state & QtWidgets.QStyle.State_Selected:
            brush = palette.highlight()
        elif option.state & QtWidgets.QStyle.State_MouseOver:
            color = brush.color().darker(250)
            brush.setColor(color)

        # Update unit width
        width = (1 /
                 self._lod if self._outline * self._lod < 1 else self._outline)

        # Draw line
        painter.setPen(QtGui.QPen(brush, width))
        painter.drawLine(self._line)

        # Draw arrow if needed
        if self._arrow and self._lod > 0.15:
            # Construct arrow
            matrix = QtGui.QTransform()
            matrix.rotate(-self._line.angle())
            matrix.scale(width, width)

            if self._arrow & self.ARROW_STANDARD:
                poly = matrix.map(ARROW_STANDARD)
            elif self._arrow & self.ARROW_SLIM:
                poly = matrix.map(ARROW_SLIM)

            v = self._line.unitVector()
            v = (self._line.length() / 2) * QtCore.QPointF(
                v.x2() - v.x1(),
                v.y2() - v.y1())
            poly.translate(self._line.x1(), self._line.y1())
            poly.translate(v.x(), v.y())

            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(brush)
            painter.drawPolygon(poly)

        # Draw debug
        if DEBUG:
            painter.setBrush(QtGui.QBrush())
            painter.setPen(QtGui.QColor(255, 0, 0))
            painter.drawPath(self.shape())

            painter.setPen(QtGui.QColor(0, 255, 0))
            painter.drawRect(self.boundingRect())

        return
コード例 #25
0
    def paint(self, painter, option, widget):
        """
        Draws the node base not the ports.

        Args:
            painter (QtGui.QPainter): painter used for drawing the item.
            option (QtGui.QStyleOptionGraphicsItem):
                used to describe the parameters needed to draw.
            widget (QtWidgets.QWidget): not used.
        """
        self.auto_switch_mode()

        painter.save()
        bg_border = 1.0
        rect = QtCore.QRectF(0.5 - (bg_border / 2), 0.5 - (bg_border / 2),
                             self._width + bg_border, self._height + bg_border)
        radius = 2
        border_color = QtGui.QColor(*self.border_color)

        path = QtGui.QPainterPath()
        path.addRoundedRect(rect, radius, radius)

        rect = self.boundingRect()

        bg_color = QtGui.QColor(*self.color)
        painter.setBrush(bg_color)
        painter.setPen(QtCore.Qt.NoPen)
        painter.drawRoundedRect(rect, radius, radius)

        if self.selected and NODE_SEL_COLOR:
            painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
            painter.drawRoundedRect(rect, radius, radius)

        label_rect = QtCore.QRectF(rect.left(), rect.top(), self._width, 28)
        path = QtGui.QPainterPath()
        path.addRoundedRect(label_rect, radius, radius)
        painter.setBrush(QtGui.QColor(30, 30, 30, 200))
        painter.fillPath(path, painter.brush())

        border_width = 0.8
        if self.selected and NODE_SEL_BORDER_COLOR:
            border_width = 1.2
            border_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
        border_rect = QtCore.QRectF(rect.left() - (border_width / 2),
                                    rect.top() - (border_width / 2),
                                    rect.width() + border_width,
                                    rect.height() + border_width)

        pen = QtGui.QPen(border_color, border_width)
        pen.setCosmetic(self.viewer().get_zoom() < 0.0)
        path = QtGui.QPainterPath()
        path.addRoundedRect(border_rect, radius, radius)
        painter.setBrush(QtCore.Qt.NoBrush)
        painter.setPen(pen)
        painter.drawPath(path)

        painter.restore()
コード例 #26
0
ファイル: slicer.py プロジェクト: zhollosy/NodeGraphQt
    def paint(self, painter, option, widget):
        """
        Draws the slicer pipe.

        Args:
            painter (QtGui.QPainter): painter used for drawing the item.
            option (QtGui.QStyleOptionGraphicsItem):
                used to describe the parameters needed to draw.
            widget (QtWidgets.QWidget): not used.
        """
        color = QtGui.QColor(*PIPE_SLICER_COLOR)
        p1 = self.path().pointAtPercent(0)
        p2 = self.path().pointAtPercent(1)
        size = 6.0
        offset = size / 2
        arrow_size = 4.0

        painter.save()
        painter.setRenderHint(painter.Antialiasing, True)

        font = painter.font()
        font.setPointSize(12)
        painter.setFont(font)
        text = 'slice'
        text_x = painter.fontMetrics().width(text) / 2
        text_y = painter.fontMetrics().height() / 1.5
        text_pos = QtCore.QPointF(p1.x() - text_x, p1.y() - text_y)
        text_color = QtGui.QColor(*PIPE_SLICER_COLOR)
        text_color.setAlpha(80)
        painter.setPen(QtGui.QPen(text_color, 1.5, QtCore.Qt.SolidLine))
        painter.drawText(text_pos, text)

        painter.setPen(QtGui.QPen(color, 1.5, QtCore.Qt.DashDotLine))
        painter.drawPath(self.path())

        pen = QtGui.QPen(color, 1.5, QtCore.Qt.SolidLine)
        pen.setCapStyle(QtCore.Qt.RoundCap)
        pen.setJoinStyle(QtCore.Qt.MiterJoin)
        painter.setPen(pen)
        painter.setBrush(color)

        rect = QtCore.QRectF(p1.x() - offset, p1.y() - offset, size, size)
        painter.drawEllipse(rect)

        arrow = QtGui.QPolygonF()
        arrow.append(QtCore.QPointF(-arrow_size, arrow_size))
        arrow.append(QtCore.QPointF(0.0, -arrow_size * 0.9))
        arrow.append(QtCore.QPointF(arrow_size, arrow_size))

        transform = QtGui.QTransform()
        transform.translate(p2.x(), p2.y())
        radians = math.atan2(p2.y() - p1.y(), p2.x() - p1.x())
        degrees = math.degrees(radians) - 90
        transform.rotate(degrees)

        painter.drawPolygon(transform.map(arrow))
        painter.restore()
コード例 #27
0
ファイル: login.py プロジェクト: cgwire/qtazu
 def create_animation(self):
     """
     Create the animation of the color background.
     """
     color_begin = QtGui.QColor("#943434")
     color_end = QtGui.QColor("#CC4444")
     self.color_anim = QtCore.QPropertyAnimation(self, b"background_color")
     self.color_anim.setStartValue(color_begin)
     self.color_anim.setEndValue(color_end)
     self.color_anim.setDuration(400)
コード例 #28
0
ファイル: QtSliders.py プロジェクト: jdrese/PyFlow
 def __init__(self, parent, *args):
     super(pyf_GradientSlider, self).__init__(parent=parent, *args)
     self.parent = parent
     self.color1 = QtGui.QColor()
     self.color1.setHslF(0, 0, 0, 1)
     self.color2 = QtGui.QColor()
     self.color2.setHslF(0, 1, 1, 1)
     self.setMinimum(0.0)
     self.setMaximum(1.0)
     self.setStyleSheet(sliderStyleSheetC)
コード例 #29
0
	def __paintEvent( self, event ) :

		painter = QtGui.QPainter( self._qtWidget() )
		painter.setRenderHint( QtGui.QPainter.Antialiasing )

		painter.setBrush( QtGui.QColor( 35, 35, 35 ) )
		painter.setPen( QtGui.QColor( 0, 0, 0, 0 ) )

		radius = self._qtWidget().layout().contentsMargins().left()
		size = self.size()
		painter.drawRoundedRect( QtCore.QRectF( 0, 0, size.x, size.y ), radius, radius )
コード例 #30
0
def compile_color(color1, color2):
    """
    There is some bias when calculate with float. Set margin of error to 0.01
    """
    delta = 0.01
    q_color_1 = QtGui.QColor(color1)
    q_color_2 = QtGui.QColor(color2)

    return ((abs(q_color_1.redF() - q_color_2.redF()) < delta)
            and (abs(q_color_1.greenF() - q_color_2.greenF()) < delta)
            and (abs(q_color_1.blueF() - q_color_2.blueF()) < delta))