Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
0
    def mouseMoveEvent(self, event):
        """
        Normally our base class (QGraphicsScene) distributes mouse events to the
        various QGraphicsItems in the scene. But when the mouse is being dragged,
        it only sends events to the one object that was under the mouse when the
        button was first pressed.

        Here, we forward all events to QGraphicsItems on the drag path, even if
        they're just brushed by the mouse incidentally.
        """
        super(ImageScene2D, self).mouseMoveEvent(event)

        if not event.isAccepted() and event.buttons() != Qt.NoButton:
            if self.last_drag_pos is None:
                self.last_drag_pos = event.scenePos()

            # As a special feature, find the item and send it this event.
            path = QPainterPath(self.last_drag_pos)
            path.lineTo(event.scenePos())
            items = self.items(path)
            for item in items:
                item.mouseMoveEvent(event)
            self.last_drag_pos = event.scenePos()
        else:
            self.last_drag_pos = None
Ejemplo n.º 5
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.º 6
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.º 7
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.º 8
0
    def __init__(self, edge):
        QGraphicsPathItem.__init__(self)
        self.__edge = edge

        startPoint = QPointF(edge.points[0][0], edge.points[0][1])
        painterPath = QPainterPath(startPoint)

        index = 1
        while index + 3 <= len(edge.points):
            painterPath.cubicTo(edge.points[index][0], edge.points[index][1],
                                edge.points[index + 1][0],
                                edge.points[index + 1][1],
                                edge.points[index + 2][0],
                                edge.points[index + 2][1])
            index = index + 3
        if index + 2 <= len(edge.points):
            painterPath.quadTo(edge.points[index + 1][0],
                               edge.points[index + 1][1],
                               edge.points[index + 2][0],
                               edge.points[index + 2][1])
            index = index + 2

        if index + 1 <= len(edge.points):
            painterPath.lineTo(edge.points[index + 1][0],
                               edge.points[index + 1][1])

        if edge.head != edge.tail:
            lastIndex = len(edge.points) - 1
            self.addArrow(painterPath, edge.points[lastIndex - 1][0],
                          edge.points[lastIndex - 1][1],
                          edge.points[lastIndex][0], edge.points[lastIndex][1])

        self.setPath(painterPath)
        return
Ejemplo n.º 9
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.º 10
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.º 11
0
    def __init__(self, edge, modObj):
        QGraphicsPathItem.__init__(self)
        self.__edge = edge
        self.__modObj = modObj

        startPoint = QPointF(edge.points[0][0], edge.points[0][1])
        painterPath = QPainterPath(startPoint)

        index = 1
        while index + 3 <= len(edge.points):
            painterPath.cubicTo(edge.points[index][0], edge.points[index][1],
                                edge.points[index + 1][0],
                                edge.points[index + 1][1],
                                edge.points[index + 2][0],
                                edge.points[index + 2][1])
            index = index + 3
        if index + 2 <= len(edge.points):
            painterPath.quadTo(edge.points[index + 1][0],
                               edge.points[index + 1][1],
                               edge.points[index + 2][0],
                               edge.points[index + 2][1])
            index = index + 2

        if index + 1 <= len(edge.points):
            painterPath.lineTo(edge.points[index + 1][0],
                               edge.points[index + 1][1])

        self.setPath(painterPath)
        return
Ejemplo n.º 12
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.º 13
0
    def __init__( self, edge, modObj, connObj ):
        QGraphicsPathItem.__init__( self )
        self.__edge = edge
        self.__modObj = modObj
        self.__connObj = connObj

        startPoint = QPointF( edge.points[ 0 ][ 0 ], edge.points[ 0 ][ 1 ] )
        painterPath = QPainterPath( startPoint )

        index = 1
        while index + 3 <= len( edge.points ):
            painterPath.cubicTo(edge.points[index][0],  edge.points[index][1],
                                edge.points[index+1][0],edge.points[index+1][1],
                                edge.points[index+2][0],edge.points[index+2][1])
            index = index + 3
        if index + 2 <= len( edge.points ):
            painterPath.quadTo(edge.points[index+1][0], edge.points[index+1][1],
                               edge.points[index+2][0], edge.points[index+2][1])
            index = index + 2

        if index + 1 <= len( edge.points ):
            painterPath.lineTo(edge.points[index+1][0], edge.points[index+1][1])

        lastIndex = len( edge.points ) - 1
        self.addArrow( painterPath,
                       edge.points[lastIndex-1][0],
                       edge.points[lastIndex-1][1],
                       edge.points[lastIndex][0],
                       edge.points[lastIndex][1] )

        self.setPath( painterPath )
        return
Ejemplo n.º 14
0
Archivo: Track.py Proyecto: Pesa/forse
 def __init__(self, parent, pos, angle):
     Sector.__init__(self, parent, pos, angle)
     self.setZValue(1)
     path = QPainterPath()
     path.lineTo(_pitDistance, 0)
     self.setPath(path)
     self.setPen(QPen(_pitColor, _pitWidth))
Ejemplo n.º 15
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.º 16
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.º 17
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.º 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 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.º 20
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.º 21
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.º 22
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.º 23
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.º 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 rebuildSmooth( self ):
     """
     Rebuilds a smooth path based on the inputed points and set \
     parameters for this item.
     
     :return     <QPainterPath>
     """
     # collect the control points
     points = self.controlPoints()
     
     # create the path
     path = QPainterPath()
     
     if ( len(points) == 3 ):
         x0, y0 = points[0]
         x1, y1 = points[1]
         xN, yN = points[2]
         
         path.moveTo(x0, y0)
         path.quadTo(x1, y1, xN, yN)
     
     elif ( len(points) == 4 ):
         x0, y0 = points[0]
         x1, y1 = points[1]
         x2, y2 = points[2]
         xN, yN = points[3]
         
         path.moveTo(x0, y0)
         path.cubicTo(x1, y1, x2, y2, xN, yN)
         
     elif ( len(points) == 6 ):
         x0, y0 = points[0]
         x1, y1 = points[1]
         x2, y2 = points[2]
         x3, y3 = points[3]
         x4, y4 = points[4]
         xN, yN = points[5]
         
         xC      = (x2+x3) / 2.0
         yC      = (y2+y3) / 2.0
         
         path.moveTo(x0, y0)
         path.cubicTo(x1, y1, x2, y2, xC, yC)
         path.cubicTo(x3, y3, x4, y4, xN, yN)
         
     else:
         x0, y0 = points[0]
         xN, yN = points[-1]
         
         path.moveTo(x0, y0)
         path.lineTo(xN, yN)
     
     return path
Ejemplo n.º 27
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.º 28
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
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.º 30
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.º 31
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.º 32
0
    def updatePosition(self, scene):
        path = QPainterPath()

        self.prepareGeometryChange()

        count = len(self._longitudes)
        if count > 0:
            x, y = scene.posFromLonLat(self._longitudes, self._latitudes)
            dx = x - x[0]
            dy = y - y[0]
            for i in range(1, count):
                path.lineTo(dx[i], dy[i])
            self.setPos(x[0], y[0])

        self.setPath(path)
Ejemplo n.º 33
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.º 34
0
 def path_for(points):
     path = QPainterPath(points[0])
     for point in points[1:]:
         path.lineTo(point)
     path.lineTo(points[-1].x(), 0)
     path.lineTo(points[0].x(), 0)
     path.lineTo(points[0])
     return path
Ejemplo n.º 35
0
    def updatePosition(self, scene):
        path = QPainterPath()

        self.prepareGeometryChange()

        count = len(self._longitudes)
        if count > 0:
            x, y = scene.posFromLonLat(self._longitudes, self._latitudes)
            dx = x - x[0]
            dy = y - y[0]
            for i in range(1, count):
                path.lineTo(dx[i], dy[i])
            self.setPos(x[0], y[0])

        self.setPath(path)
Ejemplo n.º 36
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.º 37
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.º 38
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.º 40
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.º 41
0
    def updateShape(self, point=None, pos=None):
        # Main arrow direction
        params = parameters.instance
        scale = self.scale
        ms = min(scale)
        head_size = params.arrow_head_size * ms
        width = params.arrow_line_size * ms
        self.prepareGeometryChange()
        if point == self.source:
            p1 = pos
        else:
            p1 = self.source.pos()
        self.setPos(p1)
        if point == self.target:
            p2 = pos
        else:
            p2 = self.target.pos()
        tip = p2 - p1
        if abs(tip.x()) > 0.001 or abs(tip.y()) > 0.001:
            # Normalised
            #ntip = tip/stip
            ntip = tip
            # Arrow head base
            orth = QPointF(ntip.y(), -ntip.x()) * (head_size * 0.5)
            base_center = tip * (1 - 2 * head_size)
            base1 = base_center + orth
            base2 = base_center - orth
            base_center = tip * (1 - head_size * 1.50)
        else:
            ntip = tip
            base_center = tip
            base1 = tip
            base2 = tip

        self.tip = tip
        self.base_center = base_center
        self.base1 = base1
        self.base2 = base2

        path = QPainterPath()
        path.lineTo(base_center)
        path.addPolygon(QPolygonF([base_center, base1, tip, base2]))
        path.closeSubpath()
        self.rect = path.controlPointRect().adjusted(-width, -width, 2 * width,
                                                     2 * width)
        self.path = path
        self.update()
Ejemplo n.º 42
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.º 43
0
    def updateShape(self, point=None, pos=None):
# Main arrow direction
        params = parameters.instance
        scale = self.scale
        ms = min(scale)
        head_size = params.arrow_head_size*ms
        width = params.arrow_line_size*ms
        self.prepareGeometryChange()
        if point == self.source:
            p1 = pos
        else:
            p1 = self.source.pos()
        self.setPos(p1)
        if point == self.target:
            p2 = pos
        else:
            p2 = self.target.pos()
        tip = p2-p1
        if abs(tip.x()) > 0.001 or abs(tip.y()) > 0.001:
# Normalised
            #ntip = tip/stip
            ntip = tip
# Arrow head base
            orth = QPointF(ntip.y(), -ntip.x())*(head_size*0.5)
            base_center = tip*(1-2*head_size)
            base1 = base_center + orth
            base2 = base_center - orth
            base_center = tip*(1-head_size*1.50)
        else:
            ntip = tip
            base_center = tip
            base1 = tip
            base2 = tip

        self.tip = tip
        self.base_center = base_center
        self.base1 = base1
        self.base2 = base2

        path = QPainterPath()
        path.lineTo(base_center)
        path.addPolygon(QPolygonF([base_center, base1, tip, base2]))
        path.closeSubpath()
        self.rect = path.controlPointRect().adjusted(-width, -width, 2*width, 2*width)
        self.path = path
        self.update()
Ejemplo n.º 44
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.º 45
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.º 46
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.º 47
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.º 48
0
 def rebuildBlock( self ):
     """
     Rebuilds a blocked path from the output to input points.
     
     :return     <QPainterPath>
     """
     # collect the control points
     points = self.controlPoints()
     
     # create the path
     path = QPainterPath()
     for i, point in enumerate(points):
         if ( not i ):
             path.moveTo( point[0], point[1] )
         else:
             path.lineTo( point[0], point[1] )
     
     return path
Ejemplo n.º 49
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.º 50
0
 def rebuildLinear( self ):
     """ 
     Rebuilds a linear path from the output to input points.
     
     :return     <QPainterPath>
     """
     
     points = self.controlPoints()
     
     x0, y0 = points[0]
     xN, yN = points[-1]
     
     # create a simple line between the output and
     # input points
     path = QPainterPath()
     path.moveTo(x0, y0)
     path.lineTo(xN, yN)
     
     return path
 def paint(self, painter, option, widget=None):
     painter.setBrush(QBrush(self.color))
     my_pen = QPen(self.color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin);
     my_pen.setWidth(5)
     painter.setPen(my_pen)
     painter.setBrush(Qt.NoBrush);
     path = QPainterPath()  
     #path.moveTo(self.sourcePoint)
     #path.lineTo(self.destinationPoint); 
     # lookup the output port position by using the object name to index to the object type, then look in outputOffsets
     startx = self.sourceObject.pos().x()+outputOffsets[operationsType[self.sourceObject.objectName()]][0]
     starty = self.sourceObject.pos().y()+outputOffsets[operationsType[self.sourceObject.objectName()]][1]
     # lookup the input port position by converting object name to type and looking in inputOffsets
     endx = self.destinationObject.pos().x() + inputOffsets[operationsType[self.destinationObject.objectName()]][0]
     endy = self.destinationObject.pos().y() + inputOffsets[operationsType[self.destinationObject.objectName()]][1]
     path.moveTo(QPointF(startx,starty));
     path.lineTo(QPointF(endx,endy));
     #self.path.cubicTo(cp1.x(),cp1.y(),cp2.x(),cp2.y(),destPoint.x(),destPoint.y()); 
     painter.drawPath(path);    
Ejemplo n.º 52
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.º 53
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.º 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 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.º 56
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)
Ejemplo n.º 57
0
 def __call__(o, gridfunc, piece_count, image_width, image_height):
     p = QPainterPath(QPointF(0.0, 0.0))
     p.lineTo(QPointF(image_width, 0.0))
     p.lineTo(QPointF(image_width, image_height))
     p.lineTo(QPointF(0.0, image_height))
     p.closeSubpath()
     o._boundary_path = p
     gridfunc(o, piece_count, image_width, image_height)
Ejemplo n.º 58
0
def arrow_path_plain(line, width):
    """
    Return an :class:`QPainterPath` of a plain 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))
    path.moveTo(baseline.p1())
    path.lineTo(baseline.p2())

    stroker = QPainterPathStroker()
    stroker.setWidth(width)
    path = stroker.createStroke(path)

    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(),
        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