Ejemplo n.º 1
0
    def __updateCurve(self):
        self.prepareGeometryChange()
        if self.sourceAnchor and self.sinkAnchor:
            source_pos = self.sourceAnchor.anchorScenePos()
            sink_pos = self.sinkAnchor.anchorScenePos()
            source_pos = self.curveItem.mapFromScene(source_pos)
            sink_pos = self.curveItem.mapFromScene(sink_pos)

            # Adaptive offset for the curve control points to avoid a
            # cusp when the two points have the same y coordinate
            # and are close together
            delta = source_pos - sink_pos
            dist = math.sqrt(delta.x() ** 2 + delta.y() ** 2)
            cp_offset = min(dist / 2.0, 60.0)

            # TODO: make the curve tangent orthogonal to the anchors path.
            path = QPainterPath()
            path.moveTo(source_pos)
            path.cubicTo(source_pos + QPointF(cp_offset, 0),
                         sink_pos - QPointF(cp_offset, 0),
                         sink_pos)

            self.curveItem.setPath(path)
            self.sourceIndicator.setPos(source_pos)
            self.sinkIndicator.setPos(sink_pos)
            self.__updateText()
        else:
            self.setHoverState(False)
            self.curveItem.setPath(QPainterPath())
Ejemplo n.º 2
0
    def rebuild(self, gridRect):
        """
        Rebuilds the tracker item.
        """
        scene = self.scene()
        if (not scene):
            return

        self.setVisible(gridRect.contains(self.pos()))
        self.setZValue(100)

        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(0, gridRect.height())

        tip = ''
        tip_point = None
        self._ellipses = []
        items = scene.collidingItems(self)
        self._basePath = QPainterPath(path)

        for item in items:
            item_path = item.path()
            found = None
            for y in range(int(gridRect.top()), int(gridRect.bottom())):
                point = QPointF(self.pos().x(), y)
                if (item_path.contains(point)):
                    found = QPointF(0, y - self.pos().y())
                    break

            if (found):
                path.addEllipse(found, 6, 6)
                self._ellipses.append(found)

                # update the value information
                value = scene.valueAt(self.mapToScene(found))
                tip_point = self.mapToScene(found)
                hruler = scene.horizontalRuler()
                vruler = scene.verticalRuler()

                x_value = hruler.formatValue(value[0])
                y_value = vruler.formatValue(value[1])

                tip = '<b>x:</b> %s<br/><b>y:</b> %s' % (x_value, y_value)

        self.setPath(path)
        self.setVisible(True)

        # show the popup widget
        if (tip):
            anchor = XPopupWidget.Anchor.RightCenter
            widget = self.scene().chartWidget()
            tip_point = widget.mapToGlobal(widget.mapFromScene(tip_point))

            XPopupWidget.showToolTip(tip,
                                     anchor=anchor,
                                     parent=widget,
                                     point=tip_point,
                                     foreground=QColor('blue'),
                                     background=QColor(148, 148, 255))
Ejemplo n.º 3
0
Archivo: Track.py Proyecto: Pesa/forse
 def __init__(self, parent, pos, angle, pit=False):
     QGraphicsItemGroup.__init__(self, parent)
     AbstractSector.__init__(self, pos, angle)
     self.setZValue(3)
     self.black = QGraphicsPathItem(self)
     self.white = QGraphicsPathItem(self)
     start = 3 * (_trackWidth / 2)
     end = -start - abs(_pitDistance if pit else 0)
     rowdelta = _trackWidth / 4
     for item, y in [(self.black, -rowdelta),
                     (self.white, rowdelta)]:
         item.setCacheMode(QGraphicsPathItem.DeviceCoordinateCache)
         self.addToGroup(item)
         path = QPainterPath()
         path.moveTo(start, y)
         path.lineTo(end, y)
         path.moveTo(end, -y)
         path.lineTo(start, -y)
         item.setPath(path)
     pen = QPen(Qt.black, _trackWidth / 2)
     pen.setCapStyle(Qt.FlatCap)
     pen.setDashPattern([1, 1])
     self.black.setPen(QPen(pen))
     pen.setColor(Qt.white)
     self.white.setPen(pen)
Ejemplo n.º 4
0
    def drawArrow(self, paint, x1, y1, x2, y2):
        m = paint.worldMatrix()
        paint.translate(x1, y1)
        pi = 3.1415926
        if abs(x2 - x1) > 0:
            alpha = math.atan(abs(y2 - y1) / abs(x2 - x1)) * 180 / pi
        else:
            alpha = 90
        if y2 > y1:
            if x2 > x1:
                paint.rotate(alpha)
            else:
                paint.rotate(180 - alpha)
        else:
            if x2 > x1:
                paint.rotate(-alpha)
            else:
                paint.rotate(alpha - 180)
        endcoord = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) - self.size / 2
        p1 = QPointF(endcoord, 0)
        paint.drawLine(0, 0, p1.x(), 0)

        coord = math.sqrt(9**2 - 6**2)
        p2 = QPointF(endcoord - coord, 6)
        p3 = QPointF(endcoord - coord, -6)
        path = QPainterPath()
        path.moveTo(p1)
        path.lineTo(p2)
        path.lineTo(p3)
        path.lineTo(p1)
        paint.fillPath(path, paint.pen().color())
        paint.setWorldMatrix(m)
Ejemplo n.º 5
0
 def tick_DC(self, u, i):
     self.datau.pop(0)
     self.datai.pop(0)
     self.datau.append(u)
     self.datai.append(i)
     self.scene1 = QGraphicsScene()
     self.scene2 = QGraphicsScene()
     self.setup_scene(self.scene1)
     self.setup_scene(self.scene2)
     self.scene1.addSimpleText('[U/V]').moveBy(-39, 220 - 10)
     self.scene2.addSimpleText('[I/mA]').moveBy(-39, 220 - 10)
     self.scene1.addSimpleText('+4.0').moveBy(-40, 0 - 10)
     self.scene1.addSimpleText('+2.0').moveBy(-40, 50 - 10)
     self.scene1.addSimpleText('  0.0').moveBy(-40, 100 - 10)
     self.scene1.addSimpleText('-2.0').moveBy(-40, 150 - 10)
     self.scene1.addSimpleText('-4.0').moveBy(-40, 200 - 10)
     self.scene2.addSimpleText('+0.4').moveBy(-40, 0 - 10)
     self.scene2.addSimpleText('+0.2').moveBy(-40, 50 - 10)
     self.scene2.addSimpleText('  0.0').moveBy(-40, 100 - 10)
     self.scene2.addSimpleText('-0.2').moveBy(-40, 150 - 10)
     self.scene2.addSimpleText('-0.4').moveBy(-40, 200 - 10)
     path = QPainterPath()
     path.moveTo(0, 100 - self.datau[0] * 25)
     for i in xrange(1, 200):
         path.lineTo(3 * (i + 1), 100 - self.datau[i] * 25)
     self.scene1.addPath(path, QPen(QColor(0, 0, 255), 3))
     path = QPainterPath()
     path.moveTo(0, 100 - self.datai[0] * 25)
     for i in xrange(1, 200):
         path.lineTo(3 * (i + 1), 100 - self.datai[i] * 25)
     self.scene2.addPath(path, QPen(QColor(0, 0, 255), 3))
     self.ui.graph1.setScene(self.scene1)
     self.ui.graph2.setScene(self.scene2)
Ejemplo n.º 6
0
    def draw_into(self, scene, incremental=False):
        for subbranch in self.branches:
            subbranch.draw_into(scene, incremental)
        start = self.already_drawn if incremental else None
        points = [QPointF(np.real(x), -np.imag(x)) for x in self.history[start:]]

        gens = float(self.params["painter_generations"])
        scale_factor = (self.params["scale"] - 1) * 3 + 1
        pen_width = max(0, gens-self.generation) / gens * self.params["painter_thickness"] * scale_factor
        if self.generation == 0 and len(self.history) < 30:
            intensity = 126/30.0 * len(self.history)
        else:
            intensity = 17 + 99 * max(0, gens-self.generation) / gens
        color = self.params["color"].darker(85 + (127 - intensity) * 4)
        outline = color.darker(500)
        pen = QPen(color)
        pen.setWidthF(pen_width)
        darkPen = QPen(outline)
        darkPen.setWidthF(pen_width)
        depth = self.params["depth"]
        path = QPainterPath()
        path.moveTo(points[0])
        for index in range(1, len(points) - 1):
            path.lineTo(points[index])
        scene.addPath(path, pen)

        if incremental:
            self.already_drawn = max(0, len(self.history) - 1)
Ejemplo n.º 7
0
    def __updateCurve(self):
        self.prepareGeometryChange()
        if self.sourceAnchor and self.sinkAnchor:
            source_pos = self.sourceAnchor.anchorScenePos()
            sink_pos = self.sinkAnchor.anchorScenePos()
            source_pos = self.curveItem.mapFromScene(source_pos)
            sink_pos = self.curveItem.mapFromScene(sink_pos)

            # Adaptive offset for the curve control points to avoid a
            # cusp when the two points have the same y coordinate
            # and are close together
            delta = source_pos - sink_pos
            dist = math.sqrt(delta.x()**2 + delta.y()**2)
            cp_offset = min(dist / 2.0, 60.0)

            # TODO: make the curve tangent orthogonal to the anchors path.
            path = QPainterPath()
            path.moveTo(source_pos)
            path.cubicTo(source_pos + QPointF(cp_offset, 0),
                         sink_pos - QPointF(cp_offset, 0), sink_pos)

            self.curveItem.setPath(path)
            self.sourceIndicator.setPos(source_pos)
            self.sinkIndicator.setPos(sink_pos)
            self.__updateText()
        else:
            self.setHoverState(False)
            self.curveItem.setPath(QPainterPath())
Ejemplo n.º 8
0
 def __init_corner(self):
     path = QPainterPath()
     path.moveTo(-Block.padding, -15 - Block.padding)
     path.lineTo(-15 - Block.padding, -Block.padding)
     path.lineTo(-Block.padding, -Block.padding)
     path.closeSubpath()
     self.__corner_path = path
Ejemplo n.º 9
0
 def rebuild( self, gridRect ):
     """
     Rebuilds the tracker item.
     """
     scene = self.scene()
     if ( not scene ):
         return
     
     self.setVisible(gridRect.contains(self.pos()))
     self.setZValue(100)
     
     path = QPainterPath()
     path.moveTo(0, 0)
     path.lineTo(0, gridRect.height())
     
     tip             = ''
     tip_point       = None
     self._ellipses  = []
     items           = scene.collidingItems(self)
     self._basePath  = QPainterPath(path)
     
     for item in items:
         item_path = item.path()
         found = None
         for y in range(int(gridRect.top()), int(gridRect.bottom())):
             point = QPointF(self.pos().x(), y)
             if ( item_path.contains(point) ):
                 found = QPointF(0, y - self.pos().y())
                 break
         
         if ( found ):
             path.addEllipse(found, 6, 6)
             self._ellipses.append(found)
             
             # update the value information
             value     = scene.valueAt(self.mapToScene(found))
             tip_point = self.mapToScene(found)
             hruler    = scene.horizontalRuler()
             vruler    = scene.verticalRuler()
             
             x_value = hruler.formatValue(value[0])
             y_value = vruler.formatValue(value[1])
             
             tip = '<b>x:</b> %s<br/><b>y:</b> %s' % (x_value, y_value)
     
     self.setPath(path)
     self.setVisible(True)
     
     # show the popup widget
     if ( tip ):
         anchor    = XPopupWidget.Anchor.RightCenter
         widget    = self.scene().chartWidget()
         tip_point = widget.mapToGlobal(widget.mapFromScene(tip_point))
         
         XPopupWidget.showToolTip(tip, 
                                  anchor = anchor,
                                  parent = widget,
                                  point  = tip_point,
                                  foreground = QColor('blue'),
                                  background = QColor(148, 148, 255))
Ejemplo n.º 10
0
 def toQPainterPath(self):
     """Return a QPainterPath containing all segments of this path.
     """
     if not self.isValid():
         raise Path2dException('invalid path')
     p = QPainterPath()
     sx, sy = self._elements[0]
     if len(self._elements[1]) == 2:
         # Only add a start point if the QPainterPath will start with a
         # line, not an arc.
         p.moveTo(sx, sy)
     for e in self._elements[1:]:
         if len(e) == 2:
             p.lineTo(*e)
             sx, sy = e
         else:
             (ex, ey), (cx, cy), arcDir = e
             r = hypot(ex - cx, ey - cy)
             d = r * 2
             sa = degrees(atan2(sy - cy, sx - cx)) % 360.0
             ea = degrees(atan2(ey - cy, ex - cx)) % 360.0
             # NOTE: machtool uses a right-handed cartesian coordinate
             #       system with the Y+ up. Because of this, the QRectF
             #       used to define the arc has a negative height. This
             #       makes a positive arc angle sweep cclw as it should.
             rect = QRectF(cx - r, cy + r, d, -d)
             if arcDir == 'cclw':
                 span = (ea + 360.0 if ea < sa else ea) - sa
             else:
                 span = -((sa + 360.0 if sa < ea else sa) - ea)
             p.arcMoveTo(rect, sa)
             p.arcTo(rect, sa, span)
             sx, sy = ex, ey
     return p
Ejemplo n.º 11
0
    def itemRegion(self, index):

        if not index.isValid() or not self.model():
            return QRegion()
        return QRegion()

        # TODO: what to do with this code?

        if index.column != 1:
            return self.itemRect(index)

        if self.model().data(index).toDouble()[0] <= 0.0:
            return QRegion()

        startAngle = 0.0
        for row in xrange(self.model().rowCount(self.rootIndex())):
            sliceIndex = self.model().index(row, 1, self.rootIndex())
            value = self.model().data(sliceIndex).toDouble()[0]

            if value > 0.0:
                angle = 360*value/self.totalValue

                if sliceIndex == index:
                    slicePath = QPainterPath()
                    slicePath.moveTo(self.totalSize/2, self.totalSize/2)
                    slicePath.arcTo(self.margin, self.margin,
                                    self.margin+self.histogramSize,
                                    self.margin+self.histogramSize,
                                    startAngle, angle)
                    slicePath.closeSubpath()
                    return QRegion(slicePath.toFillPolygon().toPolygon())

                startAngle += angle

        return QRegion()
Ejemplo n.º 12
0
	def __drawLine(self, painter, graph, width, height):
		path = QPainterPath()
		try:
			day   = graph[0][0].day
			value = graph[0][0].data(self.__index)
			(x, y) = self.__getCoordinates(width, height, day, value)
			path.moveTo(x, y)
		except IndexError:
			pass

		for pos in range(1, len(graph[0])):
			point = graph[0][pos]
			day   = point.day
			value = point.data(self.__index)
			(x, y) = self.__getCoordinates(width, height, day, value)
			path.lineTo(x, y)

		pen = QPen()
		pen.setColor(QColor(graph[2]))
		pen.setWidth(3)
		pen.setCapStyle(Qt.RoundCap);
 		pen.setJoinStyle(Qt.RoundJoin);
		painter.setPen(pen)
		painter.setBrush(Qt.NoBrush)
		painter.drawPath(path)
Ejemplo n.º 13
0
 def tick_DC(self, u, i):
     self.datau.pop(0)
     self.datai.pop(0)
     self.datau.append(u)
     self.datai.append(i)
     self.scene1 = QGraphicsScene()
     self.scene2 = QGraphicsScene()
     self.setup_scene(self.scene1)
     self.setup_scene(self.scene2)
     self.scene1.addSimpleText('[U/V]').moveBy(-39, 220-10)
     self.scene2.addSimpleText('[I/mA]').moveBy(-39, 220-10)
     self.scene1.addSimpleText('+4.0').moveBy(-40,   0-10)
     self.scene1.addSimpleText('+2.0').moveBy(-40,  50-10)
     self.scene1.addSimpleText('  0.0').moveBy(-40, 100-10)
     self.scene1.addSimpleText('-2.0').moveBy(-40, 150-10)
     self.scene1.addSimpleText('-4.0').moveBy(-40, 200-10)
     self.scene2.addSimpleText('+0.4').moveBy(-40,   0-10)
     self.scene2.addSimpleText('+0.2').moveBy(-40,  50-10)
     self.scene2.addSimpleText('  0.0').moveBy(-40, 100-10)
     self.scene2.addSimpleText('-0.2').moveBy(-40, 150-10)
     self.scene2.addSimpleText('-0.4').moveBy(-40, 200-10)
     path = QPainterPath()
     path.moveTo(0,100-self.datau[0]*25)
     for i in xrange(1,200):
         path.lineTo(3*(i+1), 100-self.datau[i]*25)
     self.scene1.addPath(path, QPen(QColor(0,0,255), 3))
     path = QPainterPath()
     path.moveTo(0,100-self.datai[0]*25)
     for i in xrange(1,200):
         path.lineTo(3*(i+1), 100-self.datai[i]*25)
     self.scene2.addPath(path, QPen(QColor(0,0,255), 3))
     self.ui.graph1.setScene(self.scene1)
     self.ui.graph2.setScene(self.scene2)
Ejemplo n.º 14
0
 def toQPainterPath(self):
     """Return a QPainterPath containing all segments of this path.
     """
     if not self.isValid():
         raise Path2dException('invalid path')
     p = QPainterPath()
     sx, sy = self._elements[0]
     if len(self._elements[1]) == 2:
         # Only add a start point if the QPainterPath will start with a
         # line, not an arc.
         p.moveTo(sx, sy)
     for e in self._elements[1:]:
         if len(e) == 2:
             p.lineTo(*e)
             sx, sy = e
         else:
             (ex, ey), (cx, cy), arcDir = e
             r = hypot(ex-cx, ey-cy)
             d = r*2
             sa = degrees(atan2(sy-cy, sx-cx)) % 360.0
             ea = degrees(atan2(ey-cy, ex-cx)) % 360.0
             # NOTE: machtool uses a right-handed cartesian coordinate
             #       system with the Y+ up. Because of this, the QRectF
             #       used to define the arc has a negative height. This
             #       makes a positive arc angle sweep cclw as it should.
             rect = QRectF(cx - r, cy + r, d, -d)
             if arcDir == 'cclw':
                 span = (ea + 360.0 if ea < sa else ea) - sa
             else:
                 span = -((sa + 360.0 if sa < ea else sa) - ea)
             p.arcMoveTo(rect, sa)
             p.arcTo(rect, sa, span)
             sx, sy = ex, ey
     return p
Ejemplo n.º 15
0
 def __init_corner(self):
     path = QPainterPath()
     dpi = Info.dpi
     path.moveTo(-OIBlock.padding * 1.2 * dpi, (-.15 - OIBlock.padding * 1.2) * dpi)
     path.lineTo((-.15 - OIBlock.padding * 1.2) * dpi, -OIBlock.padding * 1.2 * dpi)
     path.lineTo(-OIBlock.padding * 1.2 * dpi, -OIBlock.padding * 1.2 * dpi)
     path.closeSubpath()
     self.__corner_path = path
Ejemplo n.º 16
0
 def compute_path(self):
     p1 = self.p1 if self.p1.x() < self.p2.x() else self.p2
     p2 = self.p2 if self.p1.x() < self.p2.x() else self.p1
     path = QPainterPath()
     path.moveTo(p1)
     dx = p2.x() - p1.x()
     path.cubicTo(QPoint(p1.x() + dx / 3, p1.y()), QPoint(p2.x() - dx / 3, p2.y()), p2)
     self.__path = path
Ejemplo n.º 17
0
class RobotView(QGraphicsItem):
    def __init__(self, robot):
        super(RobotView, self).__init__()
        self.robot = robot
        self.outline = QPainterPath()
        self.cut_angle = 0.0
        self.setFlags(QGraphicsItem.ItemIsSelectable)

    @property
    def uuid(self):
        return self.robot.uuid

    @property
    def color(self):
        if self.isSelected():
            return GREEN
        elif self.robot.is_blue:
            return BLUE
        elif self.robot.is_yellow:
            return YELLOW
        else:
            return BLACK

    def position(self):
        x, y, width, height = s(self.robot.x, self.robot.y, self.robot.world.length, self.robot.world.width)
        radius = s(self.robot.radius)

        self.cut_angle = acos(self.robot.front_cut / self.robot.radius)

        self.outline = QPainterPath()
        self.outline.moveTo(radius, 0)
        self.outline.arcTo(-radius, -radius, 2 * radius, 2 * radius, 0, 360 - 2 * self.cut_angle)
        self.outline.closeSubpath()

        self.setPos(x, -y)

    def boundingRect(self):
        radius = s(self.robot.radius)
        return QRectF(-radius, -radius, 2 * radius, 2 * radius)

    def paint(self, painter, option, widget=None):
        # Save transformation:
        painter.save()

        color = self.color

        # Change position
        painter.setBrush(color)
        painter.setPen(color)

        robot_rotation = self.robot.angle or 0.0
        # Draw robot shape
        painter.rotate(-self.cut_angle - robot_rotation)
        painter.drawPath(self.outline)
        painter.rotate(self.cut_angle + robot_rotation)

        # Reset transformation
        painter.restore()
Ejemplo n.º 18
0
 def tile_path(self, cx, cy):
     path = QPainterPath()
     path.moveTo((cx - self.r_hex), cy)
     for i in range(1, 6):
         x = cx + (self.r_hex * cos(((3 - i) * pi) / 3))
         y = cy + (self.r_hex * sin(((3 - i) * pi) / 3))
         path.lineTo(x, y)
     path.closeSubpath()
     return path
Ejemplo n.º 19
0
def draw_arc(x, y, radius_in, radius_out, angle_init, angle_end, painter):
    path = QPainterPath()

    path.moveTo(x + radius_in * cos(angle_init), y + radius_in * sin(angle_init))
    path.arcTo(x - radius_out, y - radius_out, 2 * radius_out, 2 * radius_out, angle_init, angle_end - angle_init)
    path.arcTo(x - radius_in, y - radius_in, 2 * radius_in, 2 * radius_in, angle_end, angle_init - angle_end)
    path.closeSubpath()

    painter.drawPath(path)
Ejemplo n.º 20
0
 def __init_corner(self):
     path = QPainterPath()
     dpi = Info.dpi
     path.moveTo(-OIBlock.padding * 1.2 * dpi,
                 (-.15 - OIBlock.padding * 1.2) * dpi)
     path.lineTo((-.15 - OIBlock.padding * 1.2) * dpi,
                 -OIBlock.padding * 1.2 * dpi)
     path.lineTo(-OIBlock.padding * 1.2 * dpi, -OIBlock.padding * 1.2 * dpi)
     path.closeSubpath()
     self.__corner_path = path
Ejemplo n.º 21
0
 def shape(self):
     params = parameters.instance
     path = QPainterPath()
     scale = self.scale
     half_size = params.old_point_size/2.
     path.moveTo(0, -half_size*scale[1])
     path.lineTo(0,  half_size*scale[1])
     path.moveTo(-half_size*scale[0], 0)
     path.lineTo(half_size*scale[0], 0)
     return path
Ejemplo n.º 22
0
 def shape(self):
     params = parameters.instance
     path = QPainterPath()
     scale = self.scale
     half_size = params.old_point_size / 2.
     path.moveTo(0, -half_size * scale[1])
     path.lineTo(0, half_size * scale[1])
     path.moveTo(-half_size * scale[0], 0)
     path.lineTo(half_size * scale[0], 0)
     return path
Ejemplo n.º 23
0
 def paint(self, painter, option, widget):
     params = parameters.instance
     pen = QPen(QColor(Qt.black))
     scale = self.scale
     ms = min(scale)
     pen.setWidth(params.cell_thickness)
     sel_thick = 2*params.cell_thickness
     if sel_thick == 0:
         sel_thick = 2*ms
     col = None
     if self.current:
         col = QColor(params.selected_cell_color)
     elif self.hover:
         col = QColor(params.cell_hover_color)
     else:
         col = QColor(params.cell_color)
     painter.setBrush(col)
     if self.hover_contour:
         pen1 = QPen(QColor(Qt.white))
         pen1.setWidth(sel_thick)
         painter.setPen(pen1)
     else:
         painter.setPen(pen)
     if isinstance(self.polygon, QPolygonF):
         painter.drawPolygon(self.polygon_shape)
     elif isinstance(self.polygon, QLineF):
         painter.drawLine(self.polygon)
     pen.setWidth(0)
     painter.setPen(pen)
     painter.drawPolygon(self.hexagon)
     if self.hover_side is not None:
         pen = QPen(QColor(Qt.red))
         pen.setWidth(sel_thick)
         side = self.sides[self.hover_side]
         painter.setPen(pen)
         pp = QPainterPath()
         pp.moveTo(side[0])
         for p in side[1:]:
             pp.lineTo(p)
         painter.drawPath(pp)
     elif self.division_line is not None:
         pen = QPen(params.division_wall_color)
         pen.setWidth(sel_thick)
         painter.setPen(pen)
         painter.drawLine(self.division_line)
     elif self.dragging_line:
         pen = QPen(QColor(Qt.red))
         pen.setWidth(sel_thick)
         painter.setPen(pen)
         polygon = self.polygon
         dg = self.drag_side
         p1 = polygon[dg]
         p2 = polygon[dg+1]
         painter.drawLine(p1, self.moving_point)
         painter.drawLine(self.moving_point, p2)
Ejemplo n.º 24
0
 def paint(self, painter, option, widget):
     params = parameters.instance
     pen = QPen(QColor(Qt.black))
     scale = self.scale
     ms = min(scale)
     pen.setWidth(params.cell_thickness)
     sel_thick = 2 * params.cell_thickness
     if sel_thick == 0:
         sel_thick = 2 * ms
     col = None
     if self.current:
         col = QColor(params.selected_cell_color)
     elif self.hover:
         col = QColor(params.cell_hover_color)
     else:
         col = QColor(params.cell_color)
     painter.setBrush(col)
     if self.hover_contour:
         pen1 = QPen(QColor(Qt.white))
         pen1.setWidth(sel_thick)
         painter.setPen(pen1)
     else:
         painter.setPen(pen)
     if isinstance(self.polygon, QPolygonF):
         painter.drawPolygon(self.polygon_shape)
     elif isinstance(self.polygon, QLineF):
         painter.drawLine(self.polygon)
     pen.setWidth(0)
     painter.setPen(pen)
     painter.drawPolygon(self.hexagon)
     if self.hover_side is not None:
         pen = QPen(QColor(Qt.red))
         pen.setWidth(sel_thick)
         side = self.sides[self.hover_side]
         painter.setPen(pen)
         pp = QPainterPath()
         pp.moveTo(side[0])
         for p in side[1:]:
             pp.lineTo(p)
         painter.drawPath(pp)
     elif self.division_line is not None:
         pen = QPen(params.division_wall_color)
         pen.setWidth(sel_thick)
         painter.setPen(pen)
         painter.drawLine(self.division_line)
     elif self.dragging_line:
         pen = QPen(QColor(Qt.red))
         pen.setWidth(sel_thick)
         painter.setPen(pen)
         polygon = self.polygon
         dg = self.drag_side
         p1 = polygon[dg]
         p2 = polygon[dg + 1]
         painter.drawLine(p1, self.moving_point)
         painter.drawLine(self.moving_point, p2)
Ejemplo n.º 25
0
    def calculateDatasets(self, scene, axes, datasets):
        """
        Builds the datasets for this renderer.  Each renderer will need to
        subclass and implemenent this method, otherwise, no data will be
        shown in the chart.
        
        :param      scene | <XChartScene>
                    axes | [<
                    datasets | [<XChartDataset>, ..]
        """
        items = self.calculateDatasetItems(scene, datasets)
        if not items:
            scene.clear()
            return

        rect = self.buildData('axis_rect')
        half_size = self.maximumBarSize() / 2.0

        for dataset, item in items.items():
            path = QPainterPath()
            subpaths = []

            for value in dataset.values():
                pos = self.pointAt(axes, value)

                radius = min(rect.bottom() - pos.y(), 8)

                subpath = QPainterPath()

                # create a vertical bar graph
                if self.orientation() == Qt.Vertical:
                    subpath.moveTo(pos.x() - half_size, rect.bottom())
                    subpath.lineTo(pos.x() - half_size, pos.y() + radius)
                    subpath.quadTo(pos.x() - half_size, pos.y(),
                                   pos.x() - half_size + radius, pos.y())
                    subpath.lineTo(pos.x() + half_size - radius, pos.y())
                    subpath.quadTo(pos.x() + half_size, pos.y(),
                                   pos.x() + half_size,
                                   pos.y() + radius)
                    subpath.lineTo(pos.x() + half_size, rect.bottom())
                    subpath.lineTo(pos.x() - half_size, rect.bottom())

                # create a horizontal bar graph
                else:
                    subpath.moveTo(rect.left(), pos.y() - half_size)
                    subpath.lineTo(pos.x(), pos.y() - half_size)
                    subpath.lineTo(pos.x(), pos.y() + half_size)
                    subpath.lineTo(rect.left(), pos.y() + half_size)
                    subpath.lineTo(rect.left(), pos.y() - half_size)

                path.addPath(subpath)
                subpaths.append(subpath)

            item.setPath(path)
            item.setBuildData('subpaths', subpaths)
Ejemplo n.º 26
0
    def _updatePath(self):
        p0 = self._p0
        p1 = self._p1

        path = QPainterPath()
        path.moveTo(p0)
        dx = p1.x() - p0.x()
        x0 = p0.x() + 0.7 * dx
        x1 = p1.x() - 0.7 * dx
        path.cubicTo(QPointF(x0, p0.y()), QPointF(x1, p1.y()), p1)
        self.setPath(path)
Ejemplo n.º 27
0
 def calculateDatasets(self, scene, axes, datasets):
     """
     Builds the datasets for this renderer.  Each renderer will need to
     subclass and implemenent this method, otherwise, no data will be
     shown in the chart.
     
     :param      scene | <XChartScene>
                 axes | [<
                 datasets | [<XChartDataset>, ..]
     """
     items = self.calculateDatasetItems(scene, datasets)
     if not items:
         scene.clear()
         return
     
     rect = self.buildData('axis_rect')
     half_size = self.maximumBarSize() / 2.0
     
     for dataset, item in items.items():
         path = QPainterPath()
         subpaths = []
         
         for value in dataset.values():
             pos = self.pointAt(axes, value)
             
             radius = min(rect.bottom() - pos.y(), 8)
             
             subpath = QPainterPath()
             
             # create a vertical bar graph
             if self.orientation() == Qt.Vertical:
                 subpath.moveTo(pos.x() - half_size, rect.bottom())
                 subpath.lineTo(pos.x() - half_size, pos.y() + radius)
                 subpath.quadTo(pos.x() - half_size, pos.y(),
                                pos.x() - half_size + radius, pos.y())
                 subpath.lineTo(pos.x() + half_size - radius, pos.y())
                 subpath.quadTo(pos.x() + half_size, pos.y(),
                                pos.x() + half_size, pos.y() + radius)
                 subpath.lineTo(pos.x() + half_size, rect.bottom())
                 subpath.lineTo(pos.x() - half_size, rect.bottom())
             
             # create a horizontal bar graph
             else:
                 subpath.moveTo(rect.left(), pos.y() - half_size)
                 subpath.lineTo(pos.x(),     pos.y() - half_size)
                 subpath.lineTo(pos.x(),     pos.y() + half_size)
                 subpath.lineTo(rect.left(), pos.y() + half_size)
                 subpath.lineTo(rect.left(), pos.y() - half_size)
             
             path.addPath(subpath)
             subpaths.append(subpath)
         
         item.setPath(path)
         item.setBuildData('subpaths', subpaths)
Ejemplo n.º 28
0
 def make_painter_path(self):
     """Return a new QPainterPath used for drawing the shape."""
     path = QPainterPath()
     points = self._points
     if points:
         point = points[0]
         path.moveTo(point[0], point[1])
         for i in range(1, len(self._points)):
             point = points[i]
             path.lineTo(point[0], point[1])
         path.closeSubpath()
     return path;
Ejemplo n.º 29
0
    def paintMilestone(self, painter):
        """
        Paints this item as the milestone look.
        
        :param      painter | <QPainter>
        """
        # generate the rect
        rect = self.rect()

        padding = self.padding()
        gantt = self.scene().ganttWidget()
        cell_w = gantt.cellWidth()
        cell_h = gantt.cellHeight()

        x = rect.width() - cell_w
        y = self.padding()
        w = cell_w
        h = rect.height() - padding - 2

        # grab the color options
        color = self.color()
        alt_color = self.alternateColor()

        if (self.isSelected()):
            color = self.highlightColor()
            alt_color = self.alternateHighlightColor()

        # create the background brush
        gradient = QLinearGradient()
        gradient.setStart(0, 0)
        gradient.setFinalStop(0, h)

        gradient.setColorAt(0, color)
        gradient.setColorAt(0.8, alt_color)
        gradient.setColorAt(1, color)

        painter.setPen(self.borderColor())
        painter.setBrush(QBrush(gradient))

        pen = painter.pen()
        pen.setWidthF(0.5)
        painter.setPen(pen)
        painter.setRenderHint(painter.Antialiasing)

        path = QPainterPath()
        path.moveTo(x - cell_w / 3.0, y + h / 2.0)
        path.lineTo(x, y)
        path.lineTo(x + cell_w / 3.0, y + h / 2.0)
        path.lineTo(x, y + h)
        path.lineTo(x - cell_w / 3.0, y + h / 2.0)

        painter.drawPath(path)
Ejemplo n.º 30
0
    def __init__(self,
                 id,
                 title='',
                 title_above=False,
                 title_location=AxisMiddle,
                 line=None,
                 arrows=0,
                 plot=None,
                 bounds=None):
        QGraphicsItem.__init__(self)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setZValue(AxisZValue)
        self.id = id
        self.title = title
        self.title_location = title_location
        self.data_line = line
        self.plot = plot
        self.graph_line = None
        self.size = None
        self.scale = None
        self.tick_length = (10, 5, 0)
        self.arrows = arrows
        self.title_above = title_above
        self.line_item = QGraphicsLineItem(self)
        self.title_item = QGraphicsTextItem(self)
        self.end_arrow_item = None
        self.start_arrow_item = None
        self.show_title = False
        self.scale = None
        path = QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.moveTo(0, 3.09)
        path.lineTo(0, -3.09)
        path.lineTo(9.51, 0)
        path.closeSubpath()
        self.arrow_path = path
        self.label_items = []
        self.label_bg_items = []
        self.tick_items = []
        self._ticks = []
        self.zoom_transform = QTransform()
        self.labels = None
        self.values = None
        self._bounds = bounds
        self.auto_range = None
        self.auto_scale = True

        self.zoomable = False
        self.update_callback = None
        self.max_text_width = 50
        self.text_margin = 5
        self.always_horizontal_text = False
Ejemplo n.º 31
0
    def _updatePath(self):
        p0 = self._startPos
        p1 = self._endPos
        if p0 is None or p1 is None:
            return

        path = QPainterPath()
        path.moveTo(p0)
        dx = p1.x() - p0.x()
        x0 = p0.x() + 0.7 * dx
        x1 = p1.x() - 0.7 * dx
        path.cubicTo(QPointF(x0, p0.y()), QPointF(x1, p1.y()), p1)
        self.setPath(path)
Ejemplo n.º 32
0
 def _addPath(self):
   iNode = 2 * model._nodes.index(self.__node)
   x0,y0 = record.states[0][iNode:iNode+2]
   path = QPainterPath()
   path.moveTo(x0,-y0)
   item = QGraphicsPathItem()
   item.setPen( QPen( QColor(0,0,255), 0 ) )
   item.setPath(path)
   self._path = item
   for state in record.states[1:]:
     self._addPoint(state)
   if hasattr(record,'changeListeners'):
     record.changeListeners.append(self._addPoint)
   groupCurves.addToGroup(item)
Ejemplo n.º 33
0
class ParallelCoordinatesCurve(OWCurve):
    def __init__(self, n_attributes, y_values, color, name=""):
        OWCurve.__init__(self, tooltip=name)
        self._item = QGraphicsPathItem(self)
        self.path = QPainterPath()
        self.fitted = False

        self.n_attributes = n_attributes
        self.n_rows = int(len(y_values) / n_attributes)

        self.set_style(OWCurve.Lines)
        if isinstance(color, tuple):
            self.set_pen(QPen(QColor(*color)))
        else:
            self.set_pen(QPen(QColor(color)))

        x_values = list(range(n_attributes)) * self.n_rows
        self.set_data(x_values, y_values)

    def update_properties(self):
        self.redraw_path()

    def redraw_path(self):
        self.path = QPainterPath()
        for segment in self.segment(self.data()):
            if self.fitted:
                self.draw_cubic_path(segment)
            else:
                self.draw_normal_path(segment)
        self._item.setPath(self.graph_transform().map(self.path))
        self._item.setPen(self.pen())

    def segment(self, data):
        for i in range(self.n_rows):
            yield data[i * self.n_attributes:(i + 1) * self.n_attributes]

    def draw_cubic_path(self, segment):
        for (x1, y1), (x2, y2) in zip(segment, segment[1:]):
            self.path.moveTo(x1, y1)
            self.path.cubicTo(QPointF(x1 + 0.5, y1),
                              QPointF(x2 - 0.5, y2), QPointF(x2, y2))

    def draw_normal_path(self, segment):
        if not segment:
            return

        x, y = segment[0]
        self.path.moveTo(x, y)
        for x, y in segment[1:]:
            self.path.lineTo(x, y)
class DataPipe(QtDeclarative.QDeclarativeItem):

    def __init__(self, color):
        super(DataPipe, self).__init__()
        self.color = color
        self.sourcePoint = QPoint(0,0,0)
        self.destinationPoint = QPoint(0,0,0)
        self.rect = QRectF(0, -20, 30, 40)
        self.path = QPainterPath()
        self.change = 1
        self.angle = 0

    def setSourcePoint(self,srcp):
        self.sourcePoint = srcp

    def setDestinationPoint(self,dstp):
        self.destinationPoint = dstp

    def boundingRect(self):
        return self.path.boundingRect()

    def shape(self):
        return self.path

    def paint(self, painter, option, widget=None):
        painter.setPen(QPen(QColor(0,0,0)))
        painter.setBrush(QBrush(self.color))
        painter.pen().setWidth(4);
        painter.setBrush(Qt.NoBrush);
        painter.drawPath(self.path);
        
        self.path.moveTo(sourcePoint);
        self.path.lineTo(self.destinationPoint);
        #self.path.cubicTo(cp1.x(),cp1.y(),cp2.x(),cp2.y(),destPoint.x(),destPoint.y()); 
        painter.drawPath(self.path);    

    def advance(self, phase):
        if phase == 0:
            matrix = self.matrix()
            matrix.reset()
            self.setMatrix(matrix)
            self.angle += self.change * random.random()
            if self.angle > 4.5:
                self.change = -1
                self.angle -= 0.00001
            elif self.angle < -4.5:
                self.change = 1
                self.angle += 0.00001
        elif phase == 1:
            self.rotate(self.angle)
Ejemplo n.º 35
0
class ParallelCoordinatesCurve(OWCurve):
    def __init__(self, n_attributes, y_values, color, name=""):
        OWCurve.__init__(self, tooltip=name)
        self._item = QGraphicsPathItem(self)
        self.path = QPainterPath()
        self.fitted = False

        self.n_attributes = n_attributes
        self.n_rows = int(len(y_values) / n_attributes)

        self.set_style(OWCurve.Lines)
        if isinstance(color, tuple):
            self.set_pen(QPen(QColor(*color)))
        else:
            self.set_pen(QPen(QColor(color)))

        x_values = list(range(n_attributes)) * self.n_rows
        self.set_data(x_values, y_values)

    def update_properties(self):
        self.redraw_path()

    def redraw_path(self):
        self.path = QPainterPath()
        for segment in self.segment(self.data()):
            if self.fitted:
                self.draw_cubic_path(segment)
            else:
                self.draw_normal_path(segment)
        self._item.setPath(self.graph_transform().map(self.path))
        self._item.setPen(self.pen())

    def segment(self, data):
        for i in range(self.n_rows):
            yield data[i * self.n_attributes:(i + 1) * self.n_attributes]

    def draw_cubic_path(self, segment):
        for (x1, y1), (x2, y2) in zip(segment, segment[1:]):
            self.path.moveTo(x1, y1)
            self.path.cubicTo(QPointF(x1 + 0.5, y1), QPointF(x2 - 0.5, y2),
                              QPointF(x2, y2))

    def draw_normal_path(self, segment):
        if not segment:
            return

        x, y = segment[0]
        self.path.moveTo(x, y)
        for x, y in segment[1:]:
            self.path.lineTo(x, y)
Ejemplo n.º 36
0
    def paint(self, painter, option, widget=None):
        myPen = self.pen()
        myPen.setColor(self.myColor)
        painter.setPen(myPen)
        painter.setBrush(self.myColor)

        controlPoints = []
        endPt = self.endItem.getLinkPointForParameter(self.endIndex)
        startPt = self.startItem.getLinkPointForOutput(self.startIndex)
        if isinstance(self.startItem.element, Algorithm):
            if self.startIndex != -1:
                controlPoints.append(self.startItem.pos() + startPt)
                controlPoints.append(self.startItem.pos() + startPt +
                                     QPointF(ModelerGraphicItem.BOX_WIDTH /
                                             2, 0))
                controlPoints.append(self.endItem.pos() + endPt -
                                     QPointF(ModelerGraphicItem.BOX_WIDTH /
                                             2, 0))
                controlPoints.append(self.endItem.pos() + endPt)
                pt = QPointF(self.startItem.pos() + startPt + QPointF(-3, -3))
                painter.drawEllipse(pt.x(), pt.y(), 6, 6)
                pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3))
                painter.drawEllipse(pt.x(), pt.y(), 6, 6)
            else:
                # Case where there is a dependency on an algorithm not
                # on an output
                controlPoints.append(self.startItem.pos() + startPt)
                controlPoints.append(self.startItem.pos() + startPt +
                                     QPointF(ModelerGraphicItem.BOX_WIDTH /
                                             2, 0))
                controlPoints.append(self.endItem.pos() + endPt -
                                     QPointF(ModelerGraphicItem.BOX_WIDTH /
                                             2, 0))
                controlPoints.append(self.endItem.pos() + endPt)
        else:
            controlPoints.append(self.startItem.pos())
            controlPoints.append(self.startItem.pos() +
                                 QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
            controlPoints.append(self.endItem.pos() + endPt -
                                 QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
            controlPoints.append(self.endItem.pos() + endPt)
            pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3))
            painter.drawEllipse(pt.x(), pt.y(), 6, 6)

        path = QPainterPath()
        path.moveTo(controlPoints[0])
        path.cubicTo(*controlPoints[1:])
        painter.strokePath(path, painter.pen())
        self.setPath(path)
Ejemplo n.º 37
0
 def drawValue(self, p, baseRect, value, delta):
     if value == self.m_min:
         return
     dataPath = QPainterPath()
     dataPath.setFillRule(Qt.WindingFill)
     if value == self.m_max:
         dataPath.addEllipse(baseRect)
     else:
         arcLength = 360 / delta
         dataPath.moveTo(baseRect.center())
         dataPath.arcTo(baseRect, self.m_nullPosition, -arcLength)
         dataPath.lineTo(baseRect.center())
     p.setBrush(self.palette().highlight())
     p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth))
     p.drawPath(dataPath)
Ejemplo n.º 38
0
    def paintEvent(self, QPaintEvent):

        back = (numpy.ones((100, 200, 300)) * 0).astype(numpy.uint8)
        back[0:60, 0:60, 0:60] = 255
        ol = (numpy.zeros((100, 200, 300))).astype(numpy.uint8)
        ol[0:99, 0:99, 0:99] = 120
        ol[0:99, 120:140, 0:99] = 255

        path = QPainterPath()
        path.addRect(20, 20, 60, 60)
        path.moveTo(0, 0)
        path.cubicTo(99, 0,  50, 50,  99, 99)
        path.cubicTo(0, 99,  50, 50,  0, 0)
        painter = QPainter(self)
        painter.fillRect(0, 0, 100, 100, Qt.Qt.red)
Ejemplo n.º 39
0
    def paintEvent(self, QPaintEvent):

        back = (numpy.ones((100, 200, 300)) * 0).astype(numpy.uint8)
        back[0:60, 0:60, 0:60] = 255
        ol = (numpy.zeros((100, 200, 300))).astype(numpy.uint8)
        ol[0:99, 0:99, 0:99] = 120
        ol[0:99, 120:140, 0:99] = 255

        path = QPainterPath()
        path.addRect(20, 20, 60, 60)
        path.moveTo(0, 0)
        path.cubicTo(99, 0, 50, 50, 99, 99)
        path.cubicTo(0, 99, 50, 50, 0, 0)
        painter = QPainter(self)
        painter.fillRect(0, 0, 100, 100, Qt.Qt.red)
Ejemplo n.º 40
0
 def update_properties(self):
     p = self.plot()
     if p is None:
         return
     x_id, y_id = self.axes()
     rect = p.data_rect_for_axes(x_id, y_id)
     path = QPainterPath()
     if self._x_enabled and x_id in p.axes:
         for pos, label, size, _w in p.axes[x_id].ticks():
             path.moveTo(pos, rect.bottom())
             path.lineTo(pos, rect.top())
     if self._y_enabled and y_id in p.axes:
         for pos, label, size, _w in p.axes[y_id].ticks():
             path.moveTo(rect.left(), pos)
             path.lineTo(rect.right(), pos)
     self._path_item.setPath(self.graph_transform().map(path))
Ejemplo n.º 41
0
def Path_toQtPath(geom):
    p = QPainterPath()
    anchor, points = geom
    if len(points) > 1:
        p.moveTo(*points[0])
        for (x, y) in points[1:]:
            p.lineTo(x, y)
    elif len(points) == 1:
        r = QRectF(0, 0, 1e-0, 1e-9)
        r.moveCenter(*points[0])
        p.addRect(r)
    elif len(points) == 0:
        r = QRectF(0, 0, 1e-16, 1e-16)
        r.moveCenter(QPointF(*anchor))
        p.addRect(r)
    return p
Ejemplo n.º 42
0
 def update_properties(self):
     p = self.plot()
     if p is None:
         return
     x_id, y_id = self.axes()
     rect = p.data_rect_for_axes(x_id, y_id)
     path = QPainterPath()
     if self._x_enabled and x_id in p.axes:
         for pos, label, size, _w in p.axes[x_id].ticks():
             path.moveTo(pos, rect.bottom())
             path.lineTo(pos, rect.top())
     if self._y_enabled and y_id in p.axes:
         for pos, label, size, _w in p.axes[y_id].ticks():
             path.moveTo(rect.left(), pos)
             path.lineTo(rect.right(), pos)
     self._path_item.setPath(self.graph_transform().map(path))
def Path_toQtPath(geom):
    p = QPainterPath()
    anchor, points = geom
    if len(points) > 1:
        p.moveTo(*points[0])
        for (x, y) in points[1:]:
            p.lineTo(x, y)
    elif len(points) == 1:
        r = QRectF(0, 0, 1e-0, 1e-9)
        r.moveCenter(*points[0])
        p.addRect(r)
    elif len(points) == 0:
        r = QRectF(0, 0, 1e-16, 1e-16)
        r.moveCenter(QPointF(*anchor))
        p.addRect(r)
    return p
Ejemplo n.º 44
0
def arrow_path_concave(line, width):
    """
    Return a :class:`QPainterPath` of a pretty looking arrow.
    """
    path = QPainterPath()
    p1, p2 = line.p1(), line.p2()

    if p1 == p2:
        return path

    baseline = QLineF(line)
    # Require some minimum length.
    baseline.setLength(max(line.length() - width * 3, width * 3))

    start, end = baseline.p1(), baseline.p2()
    mid = (start + end) / 2.0
    normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2()

    path.moveTo(start)
    path.lineTo(start + (normal * width / 4.0))

    path.quadTo(mid + (normal * width / 4.0),
                end + (normal * width / 1.5))

    path.lineTo(end - (normal * width / 1.5))
    path.quadTo(mid - (normal * width / 4.0),
                start - (normal * width / 4.0))
    path.closeSubpath()

    arrow_head_len = width * 4
    arrow_head_angle = 50
    line_angle = line.angle() - 180

    angle_1 = line_angle - arrow_head_angle / 2.0
    angle_2 = line_angle + arrow_head_angle / 2.0

    points = [p2,
              p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
              baseline.p2(),
              p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(),
              p2]

    poly = QPolygonF(points)
    path_head = QPainterPath()
    path_head.addPolygon(poly)
    path = path.united(path_head)
    return path
Ejemplo n.º 45
0
    def paint(self, painter, option, widget=None):
        myPen = self.pen()
        myPen.setColor(self.myColor)
        painter.setPen(myPen)
        painter.setBrush(self.myColor)

        controlPoints = []
        endPt = self.endItem.getLinkPointForParameter(self.endIndex)
        startPt = self.startItem.getLinkPointForOutput(self.startIndex)
        if isinstance(self.startItem.element, Algorithm):
            if self.startIndex != -1:
                controlPoints.append(self.startItem.pos() + startPt)
                controlPoints.append(self.startItem.pos() + startPt
                        + QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
                controlPoints.append(self.endItem.pos() + endPt
                        - QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
                controlPoints.append(self.endItem.pos() + endPt)
                pt = QPointF(self.startItem.pos() + startPt
                        + QPointF(-3, -3))
                painter.drawEllipse(pt.x(), pt.y(), 6, 6)
                pt = QPointF(self.endItem.pos() + endPt +
                        QPointF(-3, -3))
                painter.drawEllipse(pt.x(), pt.y(), 6, 6)
            else:
                # Case where there is a dependency on an algorithm not
                # on an output
                controlPoints.append(self.startItem.pos() + startPt)
                controlPoints.append(self.startItem.pos() + startPt
                        + QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
                controlPoints.append(self.endItem.pos() + endPt
                        - QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
                controlPoints.append(self.endItem.pos() + endPt)
        else:
            controlPoints.append(self.startItem.pos())
            controlPoints.append(self.startItem.pos()
                    + QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
            controlPoints.append(self.endItem.pos() + endPt
                    - QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
            controlPoints.append(self.endItem.pos() + endPt)
            pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3))
            painter.drawEllipse(pt.x(), pt.y(), 6, 6)

        path = QPainterPath()
        path.moveTo(controlPoints[0])
        path.cubicTo(*controlPoints[1:])
        painter.strokePath(path, painter.pen())
        self.setPath(path)
Ejemplo n.º 46
0
def _define_symbols():
    """
    Add symbol ? to ScatterPlotItemSymbols,
    reflect the triangle to point upwards
    """
    symbols = pyqtgraph.graphicsItems.ScatterPlotItem.Symbols
    path = QPainterPath()
    path.addEllipse(QRectF(-0.35, -0.35, 0.7, 0.7))
    path.moveTo(-0.5, 0.5)
    path.lineTo(0.5, -0.5)
    path.moveTo(-0.5, -0.5)
    path.lineTo(0.5, 0.5)
    symbols["?"] = path

    tr = QTransform()
    tr.rotate(180)
    symbols['t'] = tr.map(symbols['t'])
Ejemplo n.º 47
0
 def majorGridPainterPath(self):
     """
     Returns a QPainterPath object for the major grid lines.
     This is separated from the minor grid lines so different
     pens can be used for each.
     """
     if self._majorGridPainterPath:
         return self._majorGridPainterPath
     path = QPainterPath()
     canvasSize = self._vhelix.part().numBases()
     # major tick marks  FIX: 7 is honeycomb-specific
     for i in range(0, canvasSize + 1, 7):
         x = round(self.baseWidth * i) + .5
         path.moveTo(x, .5)
         path.lineTo(x, 2 * self.baseWidth - .5)
     self._majorGridPainterPath = path
     return path
Ejemplo n.º 48
0
def _define_symbols():
    """
    Add symbol ? to ScatterPlotItemSymbols,
    reflect the triangle to point upwards
    """
    symbols = pyqtgraph.graphicsItems.ScatterPlotItem.Symbols
    path = QPainterPath()
    path.addEllipse(QRectF(-0.35, -0.35, 0.7, 0.7))
    path.moveTo(-0.5, 0.5)
    path.lineTo(0.5, -0.5)
    path.moveTo(-0.5, -0.5)
    path.lineTo(0.5, 0.5)
    symbols["?"] = path

    tr = QTransform()
    tr.rotate(180)
    symbols['t'] = tr.map(symbols['t'])
Ejemplo n.º 49
0
    def __init__(self, id, title='', title_above=False, title_location=AxisMiddle,
                 line=None, arrows=0, plot=None, bounds=None):
        QGraphicsItem.__init__(self)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setZValue(AxisZValue)
        self.id = id
        self.title = title
        self.title_location = title_location
        self.data_line = line
        self.plot = plot
        self.graph_line = None
        self.size = None
        self.scale = None
        self.tick_length = (10, 5, 0)
        self.arrows = arrows
        self.title_above = title_above
        self.line_item = QGraphicsLineItem(self)
        self.title_item = QGraphicsTextItem(self)
        self.end_arrow_item = None
        self.start_arrow_item = None
        self.show_title = False
        self.scale = None
        path = QPainterPath()
        path.setFillRule(Qt.WindingFill)
        path.moveTo(0, 3.09)
        path.lineTo(0, -3.09)
        path.lineTo(9.51, 0)
        path.closeSubpath()
        self.arrow_path = path
        self.label_items = []
        self.label_bg_items = []
        self.tick_items = []
        self._ticks = []
        self.zoom_transform = QTransform()
        self.labels = None
        self.values = None
        self._bounds = bounds
        self.auto_range = None
        self.auto_scale = True

        self.zoomable = False
        self.update_callback = None
        self.max_text_width = 50
        self.text_margin = 5
        self.always_horizontal_text = False
Ejemplo n.º 50
0
    def piece_sign_path(self, tile):
        if tile.piece.sign == "N":
            return QPainterPath()
        else:
            path = QPainterPath()
            path.moveTo(tile.pos.x() - self.r_hex / 2, tile.pos.y())
            path.lineTo(tile.pos.x() + self.r_hex / 2, tile.pos.y())

            if tile.piece.sign == "E":
                return path
            else:
                vertical_line = QPainterPath()
                vertical_line.moveTo(tile.pos.x(),
                                     tile.pos.y() - self.r_hex / 2)
                vertical_line.lineTo(tile.pos.x(),
                                     tile.pos.y() + self.r_hex / 2)
                path += vertical_line
                return path
Ejemplo n.º 51
0
def arrow_path_concave(line, width):
    """
    Return a :class:`QPainterPath` of a pretty looking arrow.
    """
    path = QPainterPath()
    p1, p2 = line.p1(), line.p2()

    if p1 == p2:
        return path

    baseline = QLineF(line)
    # Require some minimum length.
    baseline.setLength(max(line.length() - width * 3, width * 3))

    start, end = baseline.p1(), baseline.p2()
    mid = (start + end) / 2.0
    normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2()

    path.moveTo(start)
    path.lineTo(start + (normal * width / 4.0))

    path.quadTo(mid + (normal * width / 4.0), end + (normal * width / 1.5))

    path.lineTo(end - (normal * width / 1.5))
    path.quadTo(mid - (normal * width / 4.0), start - (normal * width / 4.0))
    path.closeSubpath()

    arrow_head_len = width * 4
    arrow_head_angle = 50
    line_angle = line.angle() - 180

    angle_1 = line_angle - arrow_head_angle / 2.0
    angle_2 = line_angle + arrow_head_angle / 2.0

    points = [
        p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
        baseline.p2(), p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2
    ]

    poly = QPolygonF(points)
    path_head = QPainterPath()
    path_head.addPolygon(poly)
    path = path.united(path_head)
    return path
Ejemplo n.º 52
0
 def updatePath(self):
     self.endPoints = []
     controlPoints = []
     endPt = self.endItem.getLinkPointForParameter(self.endIndex)
     startPt = self.startItem.getLinkPointForOutput(self.startIndex)
     if isinstance(self.startItem.element, Algorithm):
         if self.startIndex != -1:
             controlPoints.append(self.startItem.pos() + startPt)
             controlPoints.append(self.startItem.pos() + startPt
                                  + QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
             controlPoints.append(self.endItem.pos() + endPt
                                  - QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
             controlPoints.append(self.endItem.pos() + endPt)
             pt = QPointF(self.startItem.pos() + startPt
                          + QPointF(-3, -3))
             self.endPoints.append(pt)
             pt = QPointF(self.endItem.pos() + endPt +
                          QPointF(-3, -3))
             self.endPoints.append(pt)
         else:
             # Case where there is a dependency on an algorithm not
             # on an output
             controlPoints.append(self.startItem.pos() + startPt)
             controlPoints.append(self.startItem.pos() + startPt
                                  + QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
             controlPoints.append(self.endItem.pos() + endPt
                                  - QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
             controlPoints.append(self.endItem.pos() + endPt)
     else:
         controlPoints.append(self.startItem.pos())
         controlPoints.append(self.startItem.pos()
                              + QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
         controlPoints.append(self.endItem.pos() + endPt
                              - QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
         controlPoints.append(self.endItem.pos() + endPt)
         pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3))
         self.endPoints.append(pt)
     path = QPainterPath()
     path.moveTo(controlPoints[0])
     path.cubicTo(*controlPoints[1:])
     self.setPath(path)
Ejemplo n.º 53
0
    def __updateCurve(self):
        self.prepareGeometryChange()
        if self.sourceAnchor and self.sinkAnchor:
            source_pos = self.sourceAnchor.anchorScenePos()
            sink_pos = self.sinkAnchor.anchorScenePos()
            source_pos = self.curveItem.mapFromScene(source_pos)
            sink_pos = self.curveItem.mapFromScene(sink_pos)
            # TODO: get the orthogonal angle to the anchors path.
            path = QPainterPath()
            path.moveTo(source_pos)
            path.cubicTo(source_pos + QPointF(60, 0),
                         sink_pos - QPointF(60, 0),
                         sink_pos)

            self.curveItem.setPath(path)
            self.sourceIndicator.setPos(source_pos)
            self.sinkIndicator.setPos(sink_pos)
            self.__updateText()
        else:
            self.setHoverState(False)
            self.curveItem.setPath(QPainterPath())
Ejemplo n.º 54
0
 def chart(self, v1, v2):
     self.data1.pop(0)
     self.data2.pop(0)
     self.data1.append(v1)
     self.data2.append(v2)
     self.scene1 = QGraphicsScene()
     self.scene2 = QGraphicsScene()
     self.setup_scene(self.scene1)
     self.setup_scene(self.scene2)
     path = QPainterPath()
     path.moveTo(0, -self.data1[0] / 6)
     for i in xrange(1, 100):
         path.lineTo(2 * (i + 1), -self.data1[i] / 6)
     self.scene1.addPath(path, QPen(QColor(0, 0, 255), 3))
     path = QPainterPath()
     path.moveTo(0, -self.data2[0] / 6)
     for i in xrange(1, 100):
         path.lineTo(2 * (i + 1), -self.data2[i] / 6)
     self.scene2.addPath(path, QPen(QColor(0, 0, 255), 3))
     self.ui.chart1.setScene(self.scene1)
     self.ui.chart2.setScene(self.scene2)
Ejemplo n.º 55
0
    def _test__2piece_simple(o, image_width, image_height):
        id1, id2 = 1, 2

        from PyQt4.QtCore import QPointF
        from PyQt4.QtGui import QPainterPath
        path1 = QPainterPath()
        path1.moveTo(QPointF(0, 0))
        path1.lineTo(QPointF(image_width * .3, 0))
        path1.lineTo(QPointF(image_width * 0.7, image_height))
        path1.lineTo(QPointF(0, image_height))
        path1.lineTo(QPointF(0, 0))
        o.make_piece_from_path(id1, path1)

        path2 = QPainterPath()
        path2.moveTo(QPointF(image_width, 0))
        path2.lineTo(QPointF(image_width, image_height))
        path2.lineTo(QPointF(image_width * 0.7, image_height))
        path2.lineTo(QPointF(image_width * .3, 0))
        path2.lineTo(QPointF(image_width, 0))
        o.make_piece_from_path(id2, path2)

        o.add_relation(id1, id2)
Ejemplo n.º 56
0
    def paint(self, painter, style, widget):
        painter.setRenderHint(QPainter.Antialiasing, True)

        rect = self.boundingRect()
        pen = QPen(self.borderColor)
        pen.setWidthF(10)
        pen.setJoinStyle(Qt.RoundJoin)

        path = QPainterPath()
        if (self.parentItem().property('direction') == 1):
            path.moveTo(5, rect.height() - 5)
            path.lineTo(rect.width() / 2, 5)
            path.lineTo(rect.width() - 5, rect.height() - 5)
            path.lineTo(5, rect.height() - 5)
        else:
            path.moveTo(5, 5)
            path.lineTo(rect.width() / 2, rect.height() - 5)
            path.lineTo(rect.width() - 5, 5)
            path.lineTo(5, 5)

        painter.fillPath(path, self.color)
        painter.strokePath(path, pen)
Ejemplo n.º 57
0
 def paintEvent(self, e):
     self._plotter.begin(self)
     if self._reaction.GetCatalyst().GetUsed():
         change = self._reaction.GetCatalyst().GetEfficacy()
     else:
         change = 1
     eqmpoint = 150 / change
     if change > 1:
         eqmpoint -= 0.1 * self._reaction.GetCatalyst().GetInitialMoles()
     elif change < 1:
         eqmpoint += 0.1 * self._reaction.GetCatalyst().GetInitialMoles()
     pen = QPen(Qt.black, 2, Qt.SolidLine)
     self._plotter.setPen(pen)
     self._plotter.drawLine(80, 20, 80, 220)
     self._plotter.drawLine(80, 220, 400, 220)
     self._plotter.setPen(QPen(self._reaction.GetReactantColour()))
     reactionpath = QPainterPath()
     reactionpath.moveTo(QPointF(80, 20))
     reactionpath.arcTo(80, -80 + self._plotter.GetFinalY(), eqmpoint * 2,
                        200 - (2 * self._plotter.GetFinalY()), 180, 90)
     reactionpath.lineTo(400, 120 - self._plotter.GetFinalY())
     self._plotter.drawPath(reactionpath)
     self._plotter.setPen(QPen(self._reaction.GetProductColour()))
     productpath = QPainterPath()
     productpath.moveTo(QPointF(80, 220))
     productpath.arcTo(80, 120 + self._plotter.GetFinalY(), eqmpoint * 2,
                       200 - (2 * self._plotter.GetFinalY()), 180, -90)
     productpath.lineTo(400, 120 + self._plotter.GetFinalY())
     self._plotter.drawPath(productpath)
     if not self._forprinting:
         white = QColor(240, 240, 240)
         self._plotter.setPen(QPen(white))
         self._plotter.setBrush(white)
         self._plotter.drawRect(82 + self.parent().GetAnimUpdates() * 0.23,
                                20, 320, 198)
     self._plotter.setPen(QColor(0, 0, 0))
     self._plotter.drawText(180, 235, "Time")
     self._plotter.drawText(0, 120, self._graphof)
     self._plotter.end()
Ejemplo n.º 58
0
 def drawGraph(self, plotter, change):
     pen = QPen(Qt.black, 2, Qt.SolidLine)
     plotter.setPen(pen)
     plotter.drawLine(20, 20, 20, 220)
     plotter.drawLine(20, 220, 220, 220)
     reactants = self._reaction.GetReactants()
     AverageReactantConc = 0
     for x in range(self._reaction.REACTING_SPECIES_LIMIT):
         AverageReactantConc += reactants[x].GetInitialMoles()
     AverageReactantConc /= (len(reactants) * self._reaction.GetVolume())
     plotter.setPen(QPen(plotter.GetReactantColour(), 2, Qt.SolidLine))
     reactionpath = QPainterPath()
     reactionpath.moveTo(QPointF(20, 20))
     reactionpath.arcTo(20, -70, 300 * change, 180, 180, 90)
     reactionpath.lineTo(220, 110)
     plotter.drawPath(reactionpath)
     plotter.setPen(QPen(plotter.GetProductColour(), 2, Qt.SolidLine))
     productpath = QPainterPath()
     productpath.moveTo(QPointF(20, 220))
     productpath.arcTo(20, 130, 300 * change, 180, 180, -90)
     productpath.lineTo(220, 130)
     plotter.drawPath(productpath)