Python PyQt5.QtGui.QPainterPath() Examples

The following are code examples for showing how to use PyQt5.QtGui.QPainterPath(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: eddy   Author: obdasystems   File: qt.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width, height, color, border=None):
        """
        Initialize the icon.
        :type width: T <= int | float
        :type height: T <= int | float
        :type color: str
        :type border: str
        """
        pixmap = QtGui.QPixmap(width, height)
        painter = QtGui.QPainter(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
        painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
        if border:
            painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
            painter.drawPath(path)
        painter.end()
        super().__init__(pixmap) 
Example 2
Project: eddy   Author: obdasystems   File: membership.py    GNU General Public License v3.0 6 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())

        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())

        return path 
Example 3
Project: eddy   Author: obdasystems   File: attribute.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=20, height=20, brush=None, remaining_characters='attribute', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        brush = brush or AttributeNode.DefaultBrush
        pen = AttributeNode.DefaultPen
        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.selection = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.polygon = Polygon(QtCore.QRectF(-10, -10, 20, 20), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='attribute', pos=lambda: self.center() - QtCore.QPointF(0, 22), parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)



    #############################################
    #   INTERFACE
    ################################# 
Example 4
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 5
Project: labelOCT   Author: HaozheLiu-ST   File: QtImageViewer.py    GNU General Public License v3.0 6 votes vote down vote up
def mouseReleaseEvent(self, event):
        """ Stop mouse pan or zoom mode (apply zoom if valid).
        """
        QGraphicsView.mouseReleaseEvent(self, event)
        scenePos = self.mapToScene(event.pos())
        if event.button() == Qt.LeftButton:
            self.setDragMode(QGraphicsView.NoDrag)
            self.leftMouseButtonReleased.emit(scenePos.x(), scenePos.y())
        elif event.button() == Qt.RightButton:
            if self.canZoom:
                viewBBox = self.zoomStack[-1] if len(self.zoomStack) else self.sceneRect()
                selectionBBox = self.scene.selectionArea().boundingRect().intersected(viewBBox)
                self.scene.setSelectionArea(QPainterPath())  # Clear current selection area.
                if selectionBBox.isValid() and (selectionBBox != viewBBox):
                    self.zoomStack.append(selectionBBox)
                    self.updateViewer()
            self.setDragMode(QGraphicsView.NoDrag)
            self.rightMouseButtonReleased.emit(scenePos.x(), scenePos.y()) 
Example 6
Project: BUAAAIHomeWork   Author: potato-cat   File: small_arrow.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        path = QPainterPath()
        l_arrow = self.end - self.start
        path.moveTo(self.start)
        path.lineTo(self.end)

        length = math.sqrt(l_arrow.x() ** 2 + l_arrow.y() ** 2)
        sita = math.atan2(l_arrow.y(), l_arrow.x())
        p1 = self.end - QPointF(SMALL_ARROW_WIDTH * math.cos(sita),
                                SMALL_ARROW_WIDTH * math.sin(sita))
        p2 = p1 - QPointF(-(SMALL_ARROW_WIDTH / 2) * math.sin(sita),
                          (SMALL_ARROW_WIDTH / 2) * math.cos(sita))
        p3 = p1 + QPointF(-SMALL_ARROW_WIDTH / 2 * math.sin(sita),
                          SMALL_ARROW_WIDTH / 2 * math.cos(sita))
        path.addPolygon(QPolygonF([p2, p3, self.end, p2]))
        # path = path.simplified()
        painter.setPen(QPen(self.color, 2))
        painter.setBrush(self.color)
        painter.drawPath(path)
        painter.setPen(Qt.red)
        painter.drawPoint(p1) 
Example 7
Project: BUAAAIHomeWork   Author: potato-cat   File: big_arrow.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        path = QPainterPath()
        l_arrow = self.end - self.start
        length = math.sqrt(l_arrow.x() ** 2 + l_arrow.y() ** 2)
        sita = math.atan2(l_arrow.y(), l_arrow.x())
        p1 = self.start + QPointF(-(BIG_ARROW_WIDTH / 2) * math.sin(sita),
                                  (BIG_ARROW_WIDTH / 2) * math.cos(sita))
        p2 = self.start - QPointF(-(BIG_ARROW_WIDTH / 2) * math.sin(sita),
                                  (BIG_ARROW_WIDTH / 2) * math.cos(sita))
        p3 = p2 + QPointF((length - BIG_ARROW_WIDTH) * math.cos(sita),
                          (length - BIG_ARROW_WIDTH) * math.sin(sita))
        p4 = p3 - QPointF(-BIG_ARROW_WIDTH / 2 * math.sin(sita),
                          BIG_ARROW_WIDTH / 2 * math.cos(sita))
        p5 = self.end
        p7 = p1 + QPointF((length - BIG_ARROW_WIDTH) * math.cos(sita),
                          (length - BIG_ARROW_WIDTH) * math.sin(sita))
        p6 = p7 + QPointF(-BIG_ARROW_WIDTH / 2 * math.sin(sita),
                          BIG_ARROW_WIDTH / 2 * math.cos(sita))
        path.addPolygon(QPolygonF([p1, p2, p3, p4, p5, p6, p7, p1]))
        # path = path.simplified()
        painter.setPen(Qt.black)
        painter.setBrush(Qt.yellow)
        painter.drawPath(path) 
Example 8
Project: NetDebug   Author: BeiChenYx   File: mytitlebar.py    MIT License 6 votes vote down vote up
def paintEvent(self, event):
        """
        绘制标题栏背景色
        """
        painter = QtGui.QPainter(self)
        pathBack = QtGui.QPainterPath()
        pathBack.setFillRule(QtCore.Qt.WindingFill)
        pathBack.addRoundedRect(
            QtCore.QRectF(0, 0, self.width(), self.height()),
            3, 3
        )
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform, True)
        painter.fillPath(
            pathBack,
            QtGui.QBrush(QtGui.QColor(
                self.m_colorR, self.m_colorG, self.m_colorB
            ))
        )
        # print(self.width())
        # print(self.parentWidget().width()) 
        # 当窗口最大化或者还原后,窗口长度变了,标题的长度应该一起改变
        if self.width() != self.parentWidget().width():
            self.setFixedWidth(self.parentWidget().width())

        # return QtWidgets.QWidget.paintEvent(event) 
Example 9
Project: NetDebug   Author: BeiChenYx   File: basewindow.py    MIT License 6 votes vote down vote up
def paintEvent(self, event):
        """
        设置背景色
        """
        painter = QtGui.QPainter(self)
        pathBack = QtGui.QPainterPath()
        pathBack.setFillRule(QtCore.Qt.WindingFill)
        pathBack.addRoundedRect(
            QtCore.QRectF(0, 0, self.width(), self.height()),
            3, 3
        )
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform, True)
        painter.fillPath(
            pathBack,
            QtGui.QBrush(QtGui.QColor( 238, 223, 204))
        )

        # return QtWidgets.QWidget.paintEvent(event) 
Example 10
Project: eddy   Author: danielepantaleone   File: qt.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width, height, color, border=None):
        """
        Initialize the icon.
        :type width: T <= int | float
        :type height: T <= int | float
        :type color: str
        :type border: str
        """
        pixmap = QtGui.QPixmap(width, height)
        painter = QtGui.QPainter(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
        painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
        if border:
            painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
            painter.drawPath(path)
        painter.end()
        super().__init__(pixmap) 
Example 11
Project: eddy   Author: danielepantaleone   File: membership.py    GNU General Public License v3.0 6 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())

        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())

        return path 
Example 12
Project: eddy   Author: danielepantaleone   File: attribute.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=20, height=20, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        brush = brush or AttributeNode.DefaultBrush
        pen = AttributeNode.DefaultPen
        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.selection = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.polygon = Polygon(QtCore.QRectF(-10, -10, 20, 20), brush, pen)
        self.label = NodeLabel(template='attribute', pos=lambda: self.center() - QtCore.QPointF(0, 22), parent=self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)

    #############################################
    #   INTERFACE
    ################################# 
Example 13
Project: Lector   Author: BasioMeusPuga   File: definitionsdialog.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(DefinitionsUI, self).__init__()
        self.setupUi(self)
        self._translate = QtCore.QCoreApplication.translate

        self.parent = parent
        self.previous_position = None

        self.setWindowFlags(
            QtCore.Qt.Popup |
            QtCore.Qt.FramelessWindowHint)

        radius = 15
        path = QtGui.QPainterPath()
        path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)

        try:
            mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
            self.setMask(mask)
        except TypeError:  # Required for older versions of Qt
            pass

        self.definitionView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        self.app_id = 'bb7a91f9'
        self.app_key = 'fefacdf6775c347b52e9efa2efe642ef'

        self.root_url = 'https://od-api.oxforddictionaries.com:443/api/v1/inflections/'
        self.define_url = 'https://od-api.oxforddictionaries.com:443/api/v1/entries/'

        self.pronunciation_mp3 = None

        self.okButton.clicked.connect(self.hide)
        self.dialogBackground.clicked.connect(self.color_background)
        if multimedia_available:
            self.pronounceButton.clicked.connect(self.play_pronunciation)
        else:
            self.pronounceButton.setEnabled(False) 
Example 14
Project: Lector   Author: BasioMeusPuga   File: metadatadialog.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(MetadataUI, self).__init__()
        self.setupUi(self)
        self._translate = QtCore.QCoreApplication.translate

        self.setWindowFlags(
            QtCore.Qt.Popup |
            QtCore.Qt.FramelessWindowHint)

        self.parent = parent

        radius = 15
        path = QtGui.QPainterPath()
        path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)

        try:
            mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
            self.setMask(mask)
        except TypeError:  # Required for older versions of Qt
            pass

        self.parent = parent
        self.database_path = self.parent.database_path

        self.book_index = None
        self.book_year = None
        self.previous_position = None
        self.cover_for_database = None

        self.coverView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.coverView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        self.okButton.clicked.connect(self.ok_pressed)
        self.cancelButton.clicked.connect(self.cancel_pressed)
        self.dialogBackground.clicked.connect(self.color_background)

        self.titleLine.returnPressed.connect(self.ok_pressed)
        self.authorLine.returnPressed.connect(self.ok_pressed)
        self.yearLine.returnPressed.connect(self.ok_pressed)
        self.tagsLine.returnPressed.connect(self.ok_pressed) 
Example 15
Project: Lector   Author: BasioMeusPuga   File: dockwidgets.py    GNU General Public License v3.0 5 votes vote down vote up
def showEvent(self, event=None):
        # TODO
        # See what happens when the size of the viewport is smaller
        # than the size of the dock

        viewport_bottomRight = self.contentView.mapToGlobal(
            self.contentView.viewport().rect().bottomRight())

        # Dock dimensions
        desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
        dock_width = desktop_size.width() // 4.5
        dock_height = 30

        dock_x = viewport_bottomRight.x() - dock_width - 30
        dock_y = viewport_bottomRight.y() - 70

        self.main_window.active_docks.append(self)
        self.setGeometry(dock_x, dock_y, dock_width, dock_height)

        # Rounded
        radius = 20
        path = QtGui.QPainterPath()
        path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)
        try:
            mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
            self.setMask(mask)
        except TypeError:  # Required for older versions of Qt
            pass

        self.animation.start() 
Example 16
Project: eddy   Author: obdasystems   File: session.py    GNU General Public License v3.0 5 votes vote down vote up
def doSelectAll(self):
        """
        Select all the items in the active diagrsm.
        """
        diagram = self.mdi.activeDiagram()
        if diagram:
            path = QtGui.QPainterPath()
            path.addRect(diagram.sceneRect())
            diagram.setSelectionArea(path)
            diagram.setMode(DiagramMode.Idle) 
Example 17
Project: eddy   Author: obdasystems   File: different.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 18
Project: eddy   Author: obdasystems   File: different.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        return path 
Example 19
Project: eddy   Author: obdasystems   File: different.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())

        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())

        return path 
Example 20
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        path.addPolygon(self.tail.geometry())
        return path 
Example 21
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        path.addPolygon(self.tail.geometry())
        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())
        return path 
Example 22
Project: eddy   Author: obdasystems   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 23
Project: eddy   Author: obdasystems   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        return path 
Example 24
Project: eddy   Author: obdasystems   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())
        return path 
Example 25
Project: eddy   Author: obdasystems   File: same.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        return path 
Example 26
Project: eddy   Author: obdasystems   File: same.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())

        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())

        return path 
Example 27
Project: eddy   Author: obdasystems   File: inclusion.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 28
Project: eddy   Author: obdasystems   File: inclusion.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        return path 
Example 29
Project: eddy   Author: obdasystems   File: inclusion.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())
        return path 
Example 30
Project: eddy   Author: obdasystems   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 31
Project: eddy   Author: obdasystems   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        return path 
Example 32
Project: eddy   Author: obdasystems   File: attribute.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addEllipse(self.polygon.geometry())
        return path 
Example 33
Project: eddy   Author: obdasystems   File: attribute.py    GNU General Public License v3.0 5 votes vote down vote up
def updateNode(self, functional=None, **kwargs):
        """
        Update the current node.
        :type functional: bool
        """
        if functional is None:
            functional = self.isFunctional()

        # FUNCTIONAL POLYGON (SHAPE)
        path1 = QtGui.QPainterPath()
        path1.addEllipse(self.polygon.geometry())
        path2 = QtGui.QPainterPath()
        path2.addEllipse(QtCore.QRectF(-7, -7, 14, 14))
        self.fpolygon.setGeometry(path1.subtracted(path2))

        # FUNCTIONAL POLYGON (PEN & BRUSH)
        pen = QtGui.QPen(QtCore.Qt.NoPen)
        brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        if functional:
            pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
            brush = QtGui.QBrush(QtGui.QColor(252, 252, 252, 255))
        self.fpolygon.setPen(pen)
        self.fpolygon.setBrush(brush)

        # SELECTION + BACKGROUND + CACHE REFRESH
        super().updateNode(**kwargs) 
Example 34
Project: eddy   Author: obdasystems   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rectangle.
        :rtype: QtCore.QRectF
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.selection.geometry())
        return path.boundingRect() 
Example 35
Project: eddy   Author: obdasystems   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path 
Example 36
Project: eddy   Author: obdasystems   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        return path 
Example 37
Project: eddy   Author: obdasystems   File: property_assertion.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRoundedRect(self.polygon.geometry(), 16, 16)
        return path 
Example 38
Project: eddy   Author: obdasystems   File: value_domain.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRoundedRect(self.polygon.geometry(), 8, 8)
        return path 
Example 39
Project: eddy   Author: obdasystems   File: value_domain.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRoundedRect(self.polygon.geometry(), 8, 8)
        return path 
Example 40
Project: eddy   Author: obdasystems   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=70, height=50, brush=None, remaining_characters='role', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        
        w = max(width, 70)
        h = max(height, 50)
        brush = brush or RoleNode.DefaultBrush
        pen = RoleNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(0, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(0, -y / 2),
            QtCore.QPointF(-x / 2, 0)
        ])

        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.ipolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='role', pos=self.center, parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   INTERFACE
    ################################# 
Example 41
Project: eddy   Author: obdasystems   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rectangle.
        :rtype: QtCore.QRectF
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.selection.geometry())
        return path.boundingRect() 
Example 42
Project: eddy   Author: obdasystems   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path 
Example 43
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rectangle.
        :rtype: QtCore.QRectF
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.selection.geometry())
        return path.boundingRect() 
Example 44
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path 
Example 45
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path 
Example 46
Project: eddy   Author: obdasystems   File: operator.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rectangle.
        :rtype: QtCore.QRectF
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.selection.geometry())
        return path.boundingRect() 
Example 47
Project: eddy   Author: obdasystems   File: operator.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPolygon(self.polygon.geometry())
        return path 
Example 48
Project: eddy   Author: obdasystems   File: restriction.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        return path 
Example 49
Project: eddy   Author: obdasystems   File: restriction.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self, *args, **kwargs):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        return path 
Example 50
Project: eddy   Author: obdasystems   File: concept.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        return path 
Example 51
Project: eddy   Author: obdasystems   File: concept.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addRect(self.polygon.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        return path 
Example 52
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        pass 
Example 53
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the polygon geometry.
        :rtype: T <= QRectF | QPolygonF | QPainterPath
        """
        return self._geometry 
Example 54
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def setGeometry(self, geometry):
        """
        Set the shape polygon.
        :type geometry: T <= QRectF | QPolygonF | QPainterPath
        """
        self._geometry = geometry 
Example 55
Project: interSubs   Author: oltodosel   File: interSubs.py    MIT License 5 votes vote down vote up
def draw_text_n_outline(self, painter: QPainter, x, y, outline_width, outline_blur, text):
		outline_color = QColor(config.outline_color)

		font = self.font()
		text_path = QPainterPath()
		if config.R2L_from_B:
			text_path.addText(x, y, font, ' ' + r2l(text.strip()) + ' ')
		else:
			text_path.addText(x, y, font, text)

		# draw blur
		range_width = range(outline_width, outline_width + outline_blur)
		# ~range_width = range(outline_width + outline_blur, outline_width, -1)

		for width in range_width:
			if width == min(range_width):
				alpha = 200
			else:
				alpha = (max(range_width) - width) / max(range_width) * 200

			blur_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), alpha)
			blur_brush = QBrush(blur_color, Qt.SolidPattern)
			blur_pen = QPen(blur_brush, width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

			painter.setPen(blur_pen)
			painter.drawPath(text_path)

		# draw outline
		outline_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), 255)
		outline_brush = QBrush(outline_color, Qt.SolidPattern)
		outline_pen = QPen(outline_brush, outline_width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

		painter.setPen(outline_pen)
		painter.drawPath(text_path)

		# draw text
		color = self.palette().color(QPalette.Text)
		painter.setPen(color)
		painter.drawText(x, y, text) 
Example 56
Project: otRebuilder   Author: Pal3love   File: qtPen.py    MIT License 5 votes vote down vote up
def __init__(self, glyphSet, path=None):
		BasePen.__init__(self, glyphSet)
		if path is None:
			from PyQt5.QtGui import QPainterPath
			path = QPainterPath()
		self.path = path 
Example 57
Project: EGTR-FutureRestore   Author: M4cs   File: PySimpleGUIQt.py    GNU General Public License v3.0 5 votes vote down vote up
def DrawText(self, text, location, color='black', font=None, angle=0):
        converted_point = self._convert_xy_to_canvas_xy(location[0], location[1])

        qcolor = QColor(color)
        qpath = QPainterPath()
        _font = font or ('courier', 12)
        qfont = QFont(_font[0], _font[1])
        # qfont.setWeight(.5)

        qpath.addText(self.x+converted_point[0], self.y+converted_point[1], qfont, str(text))
        self.QT_QGraphicsScene.addPath(qpath, qcolor) 
Example 58
Project: PointlessMaker   Author: aboood40091   File: main.py    GNU General Public License v3.0 5 votes vote down vote up
def SelectAll(self):
        paintRect = QtGui.QPainterPath()
        paintRect.addRect(0, -(26.5 * globals.TileWidth), 241 * globals.TileWidth, 27.5 * globals.TileWidth)
        self.scene.setSelectionArea(paintRect) 
Example 59
Project: qfapp   Author: tyao1   File: qtPen.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, glyphSet, path=None):
		BasePen.__init__(self, glyphSet)
		if path is None:
			from PyQt5.QtGui import QPainterPath
			path = QPainterPath()
		self.path = path 
Example 60
Project: Sushi   Author: M4cs   File: PySimpleGUIQt.py    GNU General Public License v3.0 5 votes vote down vote up
def DrawText(self, text, location, color='black', font=None, angle=0):
        converted_point = self._convert_xy_to_canvas_xy(location[0], location[1])

        qcolor = QColor(color)
        qpath = QPainterPath()
        _font = font or ('courier', 12)
        qfont = QFont(_font[0], _font[1])
        # qfont.setWeight(.5)

        qpath.addText(self.x+converted_point[0], self.y+converted_point[1], qfont, str(text))
        self.QT_QGraphicsScene.addPath(qpath, qcolor) 
Example 61
Project: GeoMop   Author: GeoMop   File: polygon_operation.py    GNU General Public License v3.0 5 votes vote down vote up
def _get_polygon_draw_path(self, polygon):
        """Get the path to draw the polygon in, i.e. the outer boundary and inner boundaries.
        The path approach allows holes in polygons and therefore flat depth for polygons (Odd-even paint rule)"""
        complex_path = QtGui.QPainterPath()
        self._add_to_painter_path(complex_path, polygon.outer_wire)
        # Subtract all inner parts
        for inner_wire in polygon.outer_wire.childs:
            self._add_to_painter_path(complex_path, inner_wire)
        return complex_path 
Example 62
Project: GeoMop   Author: GeoMop   File: connection.py    GNU General Public License v3.0 5 votes vote down vote up
def set_path(self):
        """Set path as bezzier curve"""
        path = QtGui.QPainterPath()        
        p1 = self._conn.get_in_pos()
        p2 = self._conn.get_out_pos()
        c1 = QtCore.QPointF(p1.x(), (p2.y()+p1.y())/2)
        c2 = QtCore.QPointF(p2.x(), (p2.y()+p1.y())/2)
        path.moveTo(p1)
        path.cubicTo(c1, c2, p2)
        self.setPath(path); 
Example 63
Project: pi-dashboard   Author: mybesttools   File: pi_charts.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paintEvent(self, event):
        if not self.data: return
        QtWidgets.QFrame.paintEvent(self, event)
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        # Draw background
        painter.setBrush(QtGui.QBrush(self.bgcolor))
        painter.setPen(Qt.NoPen)
        painter.drawRoundedRect(self.contentsRect(), 2, 2)
        # Draw the Lines
        for i in range(len(self.data[0])):
            path = None
            pen = QtGui.QPen(self.colors[i % len(self.colors)])
            for j in range(len(self.data)):
                value = self.data[j][i]
                prevvalue = self.data[j-1][i]
                if value == -1 or prevvalue == -1:
                    continue
                if not self.showzero and value <= 0 and prevvalue <= 0:
                    continue
                x1 = (self.pxperpt * (j - 0.5) + self.pxperpt / 4) - self.offset
                x2 = (self.pxperpt * j + self.pxperpt / 4) - self.offset
                y1 = self.height() - int((self.height() - 1) * (prevvalue / self.maxvalue))
                y2 = self.height() - int((self.height() - 1) * (value / self.maxvalue))
                path = path or QtGui.QPainterPath(QtCore.QPointF(x1,y1))
                path.cubicTo(x1, y1, x1, y2, x2, y2)
            if path:
                painter.strokePath(path, pen)
        painter.end() 
Example 64
Project: reversi_ai   Author: andysalerno   File: reversi_window.py    MIT License 5 votes vote down vote up
def paintEvent(self, q_paint_event):
        # board background color
        painter = QtGui.QPainter(self)
        bg_path = QtGui.QPainterPath()
        bg_path.addRect(0, 0, self.width(), self.height())
        painter.fillPath(bg_path, GREEN)

        # draw the board lines
        for i in range(8):
            x_pos = self.width() / 8 * i
            painter.drawLine(x_pos, 0, x_pos, self.height())

            y_pos = self.height() / 8 * i
            painter.drawLine(0, y_pos, self.width(), y_pos)

        if self.board is not None and len(self.board) >= 8 * 8:
            for h in range(8):
                for w in range(8):
                    pieces_path = QtGui.QPainterPath()
                    w_dist = self.width() / 8
                    h_dist = self.height() / 8

                    x_pos = w_dist * w
                    y_pos = h_dist * h

                    bounding_rect = QtCore.QRectF(x_pos, y_pos, w_dist, h_dist)

                    index = (h * 8) + w
                    piece = self.board[index]
                    if piece == 'O':
                        pieces_path.addEllipse(bounding_rect)
                        painter.fillPath(pieces_path, WHITE)
                    elif piece == 'X':
                        pieces_path.addEllipse(bounding_rect)
                        painter.fillPath(pieces_path, BLACK) 
Example 65
Project: linux-show-player   Author: FrancescoCeruti   File: jack_sink.py    GNU General Public License v3.0 5 votes vote down vote up
def draw_connection_line(painter, x1, y1, x2, y2, h1, h2):
        # Account for list view headers.
        y1 += h1
        y2 += h2

        # Invisible output ports don't get a connecting dot.
        if y1 > h1:
            painter.drawLine(x1, y1, x1 + 4, y1)

        # Setup control points
        spline = QPolygon(4)
        cp = int((x2 - x1 - 8) * 0.4)
        spline.setPoints(x1 + 4, y1,
                         x1 + 4 + cp, y1,
                         x2 - 4 - cp, y2,
                         x2 - 4, y2)
        # The connection line
        path = QPainterPath()
        path.moveTo(spline.at(0))
        path.cubicTo(spline.at(1), spline.at(2), spline.at(3))
        painter.strokePath(path, painter.pen())

        # painter.drawLine(x1 + 4, y1, x2 - 4, y2)

        # Invisible input ports don't get a connecting dot.
        if y2 > h2:
            painter.drawLine(x2 - 4, y2, x2, y2) 
Example 66
Project: AutoSplit64   Author: Kainev   File: rectangle_selector.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        """
        path = QPainterPath()
        path.addRect(self.rect())
        if self.isSelected():
            for shape in self.handles.values():
                path.addEllipse(shape)
        return path 
Example 67
Project: eddy   Author: danielepantaleone   File: session.py    GNU General Public License v3.0 5 votes vote down vote up
def doSelectAll(self):
        """
        Select all the items in the active diagrsm.
        """
        diagram = self.mdi.activeDiagram()
        if diagram:
            path = QtGui.QPainterPath()
            path.addRect(diagram.sceneRect())
            diagram.setSelectionArea(path)
            diagram.setMode(DiagramMode.Idle) 
Example 68
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        path.addPolygon(self.tail.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 69
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        path.addPolygon(self.tail.geometry())
        return path 
Example 70
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        path.addPolygon(self.tail.geometry())
        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())
        return path 
Example 71
Project: eddy   Author: danielepantaleone   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        return path 
Example 72
Project: eddy   Author: danielepantaleone   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())
        return path 
Example 73
Project: eddy   Author: danielepantaleone   File: inclusion.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 74
Project: eddy   Author: danielepantaleone   File: inclusion.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        return path 
Example 75
Project: eddy   Author: danielepantaleone   File: inclusion.py    GNU General Public License v3.0 5 votes vote down vote up
def shape(self):
        """
        Returns the shape of this item as a QPainterPath in local coordinates.
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        if self.isSelected():
            for polygon in self.handles:
                path.addEllipse(polygon.geometry())
            for polygon in self.anchors.values():
                path.addEllipse(polygon.geometry())
        return path 
Example 76
Project: eddy   Author: danielepantaleone   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def boundingRect(self):
        """
        Returns the shape bounding rect.
        :rtype: QRectF
        """
        path = QtGui.QPainterPath()
        path.addPath(self.selection.geometry())
        path.addPolygon(self.head.geometry())
        for polygon in self.handles:
            path.addEllipse(polygon.geometry())
        for polygon in self.anchors.values():
            path.addEllipse(polygon.geometry())
        return path.controlPointRect() 
Example 77
Project: eddy   Author: danielepantaleone   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QtGui.QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addPath(self.path.geometry())
        path.addPolygon(self.head.geometry())
        return path 
Example 78
Project: eddy   Author: danielepantaleone   File: attribute.py    GNU General Public License v3.0 5 votes vote down vote up
def painterPath(self):
        """
        Returns the current shape as QPainterPath (used for collision detection).
        :rtype: QPainterPath
        """
        path = QtGui.QPainterPath()
        path.addEllipse(self.polygon.geometry())
        return path 
Example 79
Project: eddy   Author: danielepantaleone   File: attribute.py    GNU General Public License v3.0 5 votes vote down vote up
def updateNode(self, functional=None, **kwargs):
        """
        Update the current node.
        :type functional: bool
        """
        if functional is None:
            functional = self.isFunctional()

        # FUNCTIONAL POLYGON (SHAPE)
        path1 = QtGui.QPainterPath()
        path1.addEllipse(self.polygon.geometry())
        path2 = QtGui.QPainterPath()
        path2.addEllipse(QtCore.QRectF(-7, -7, 14, 14))
        self.fpolygon.setGeometry(path1.subtracted(path2))

        # FUNCTIONAL POLYGON (PEN & BRUSH)
        pen = QtGui.QPen(QtCore.Qt.NoPen)
        brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        if functional:
            pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
            brush = QtGui.QBrush(QtGui.QColor(252, 252, 252, 255))
        self.fpolygon.setPen(pen)
        self.fpolygon.setBrush(brush)

        # SELECTION + BACKGROUND + CACHE REFRESH
        super().updateNode(**kwargs) 
Example 80
Project: Python-Googlefit   Author: pinae   File: timed_diagram.py    GNU General Public License v3.0 4 votes vote down vote up
def draw_data(self, qp, size):
        point_pen = QPen(self.data_color, 1, Qt.SolidLine)
        qp.setPen(point_pen)
        qp.setBrush(QBrush(self.data_color))
        unit_text_width = self.fm.size(Qt.TextSingleLine, self.y_unit).width()
        time_text_height = self.fm.size(Qt.TextSingleLine, "12:00").height()
        available_x_distance = size.width() - self.padding - 6 - (
                self.padding + unit_text_width + 1)
        available_y_distance = size.height() - time_text_height - 2 * self.padding
        last_point = None
        for time, value in self.data:
            x_pos = self.padding + unit_text_width + 1 + (
                (time - self.x_range[0]) / (self.x_range[1] - self.x_range[0]) * available_x_distance)
            y_pos = size.height() - time_text_height - self.padding - (
                value - self.y_range[0]) / (self.y_range[1] - self.y_range[0]) * available_y_distance
            qp.drawEllipse(x_pos-2, y_pos-2, 4, 4)
            if last_point is not None:
                qp.drawLine(last_point[0], last_point[1], x_pos, y_pos)
            last_point = x_pos, y_pos
        if len(self.data) > 2:
            smooth_value = self.data[0][1]
            current_point_index = 1
            path = QPainterPath()
            path.moveTo(self.padding + unit_text_width + 1,
                        size.height() - time_text_height - self.padding - (
                            smooth_value - self.y_range[0]) / (self.y_range[1] - self.y_range[0]) *
                        available_y_distance)
            for i in range(available_x_distance):
                x = self.x_range[0] + i / available_x_distance * (self.x_range[1] - self.x_range[0])
                while self.data[current_point_index][0] < x:
                    current_point_index += 1
                point_factor = (x - self.data[current_point_index - 1][0]) / (
                    self.data[current_point_index][0] - self.data[current_point_index - 1][0])
                time_slice = (self.x_range[1] - self.x_range[0]) / available_x_distance
                smooth_value = (smooth_value * (1 - self.smooth_factor * time_slice / timedelta(days=1)) +
                                self.smooth_factor * time_slice / timedelta(days=1) * (
                                    self.data[current_point_index][1] * point_factor +
                                    self.data[current_point_index - 1][1] * (1 - point_factor)))
                path.lineTo(
                    self.padding + unit_text_width + 1 + (
                        (x - self.x_range[0]) / (self.x_range[1] - self.x_range[0]) * available_x_distance),
                    size.height() - time_text_height - self.padding - (
                        smooth_value - self.y_range[0]) / (self.y_range[1] - self.y_range[0]) * available_y_distance
                )
            qp.setPen(QPen(self.smooth_curve_color, 2, Qt.SolidLine))
            qp.setBrush(Qt.NoBrush)
            qp.drawPath(path)