Exemplo n.º 1
0
 def __init__(self, *args):
     QwtPlot.__init__(self, *args)
     self.setTitle('Cartesian Coordinate System Demo')
     # create a plot with a white canvas
     self.setCanvasBackground(Qt.white)
     # set plot layout
     self.plotLayout().setCanvasMargin(0)
     self.plotLayout().setAlignCanvasToScales(True)
     # attach a grid
     grid = QwtPlotGrid()
     grid.attach(self)
     grid.setPen(QPen(Qt.black, 0, Qt.DotLine))
     # attach a x-axis
     xaxis = CartesianAxis(QwtPlot.xBottom, QwtPlot.yLeft)
     xaxis.attach(self)
     self.enableAxis(QwtPlot.xBottom, False)
     # attach a y-axis
     yaxis = CartesianAxis(QwtPlot.yLeft, QwtPlot.xBottom)
     yaxis.attach(self)
     self.enableAxis(QwtPlot.yLeft, False)
     # calculate 3 NumPy arrays
     x = np.arange(-2*np.pi, 2*np.pi, 0.01)
     y = np.pi*np.sin(x)
     z = 4*np.pi*np.cos(x)*np.cos(x)*np.sin(x)
     # attach a curve
     curve = QwtPlotCurve('y = pi*sin(x)')
     curve.attach(self)
     curve.setPen(QPen(Qt.green, 2))
     curve.setData(x, y)
     # attach another curve
     curve = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2')
     curve.attach(self)
     curve.setPen(QPen(Qt.black, 2))
     curve.setData(x, z)
     self.replot()
Exemplo n.º 2
0
def make():
    # create a plot with a white canvas
    demo = QwtPlot(QwtText("Errorbar Demonstation"))
    demo.setCanvasBackground(Qt.white)
    demo.plotLayout().setAlignCanvasToScales(True)

    grid = QwtPlotGrid()
    grid.attach(demo)
    grid.setPen(QPen(Qt.black, 0, Qt.DotLine))

    # calculate data and errors for a curve with error bars
    x = np.arange(0, 10.1, 0.5, np.float)
    y = np.sin(x)
    dy = 0.2 * abs(y)
    # dy = (0.15 * abs(y), 0.25 * abs(y)) # uncomment for asymmetric error bars
    dx = 0.2  # all error bars the same size
    errorOnTop = False  # uncomment to draw the curve on top of the error bars
    # errorOnTop = True # uncomment to draw the error bars on top of the curve
    curve = ErrorBarPlotCurve(
        x=x,
        y=y,
        dx=dx,
        dy=dy,
        curvePen=QPen(Qt.black, 2),
        curveSymbol=QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red),
                              QPen(Qt.black, 2), QSize(9, 9)),
        errorPen=QPen(Qt.blue, 2),
        errorCap=10,
        errorOnTop=errorOnTop,
    )
    curve.attach(demo)
    demo.resize(640, 480)
    demo.show()
    return demo
Exemplo n.º 3
0
def make():
    demo = QwtPlot()
    demo.setCanvasBackground(Qt.white)
    demo.setTitle("Histogram")

    grid = QwtPlotGrid()
    grid.enableXMin(True)
    grid.enableYMin(True)
    grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine))
    grid.setMinorPen(QPen(Qt.gray, 0, Qt.DotLine))
    grid.attach(demo)

    histogram = HistogramItem()
    histogram.setColor(Qt.darkCyan)

    numValues = 20
    samples = []
    pos = 0.0
    for i in range(numValues):
        width = 5 + random.randint(0, 4)
        value = random.randint(0, 99)
        samples.append(QwtIntervalSample(value, QwtInterval(pos, pos + width)))
        pos += width

    histogram.setData(QwtIntervalSeriesData(samples))
    histogram.attach(demo)
    demo.setAxisScale(QwtPlot.yLeft, 0.0, 100.0)
    demo.setAxisScale(QwtPlot.xBottom, 0.0, pos)
    demo.replot()
    demo.resize(600, 400)
    demo.show()
    return demo
Exemplo n.º 4
0
def qwtDrawRectSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    painter.setRenderHint(QPainter.Antialiasing, False)
    if QwtPainter.roundingAlignment(painter):
        sw = size.width()
        sh = size.height()
        sw2 = size.width() // 2
        sh2 = size.height() // 2
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            r = QRectF(x - sw2, y - sh2, sw, sh)
            QwtPainter.drawRect(painter, r)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5 * size.width()
        sh2 = .5 * size.height()
        for pos in points:
            x = pos.x()
            y = pos.y()
            r = QRectF(x - sw2, y - sh2, sw, sh)
            QwtPainter.drawRect(painter, r)
Exemplo n.º 5
0
    def __init__(self, *args):

        colors = [
            Qt.red, Qt.darkRed, Qt.green, Qt.darkGreen, Qt.blue, Qt.darkBlue,
            Qt.cyan, Qt.darkCyan, Qt.magenta, Qt.darkMagenta, Qt.yellow,
            Qt.darkYellow, Qt.gray, Qt.darkGray, Qt.lightGray, Qt.black
        ]
        QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.white)
        self.alignScales()

        # grid
        self.grid = QwtPlotGrid()
        self.grid.attach(self)
        self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine))

        # set titles
        self.setTitle("Gráfico")
        self.setAxisTitle(QwtPlot.xBottom, 'Tempo [hh:mm:ss] -->')
        self.setAxisTitle(QwtPlot.yLeft, 'Nível [mm] -->')
        """Habilita e denomina eixo Y2"""
        self.enableAxis(QwtPlot.yRight)
        self.setAxisTitle(QwtPlot.yRight, '<-- Temp. [ºC]')

        self.nplots = 16
        self.Plots = np.array([])
        self.Data = np.array([])

        for i in range(self.nplots):
            self.Plots = np.append(self.Plots, QwtPlotCurve())
            self.Plots[i].setPen(QPen(colors[i]))
            self.Plots[i].attach(self)
            """define como valor plotado será escrito no eixo x"""
            self.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw())
            self.Data = np.append(self.Data, dataclass())
            """Os índices pares se referem à plots no eixo Y1,
            e os índices ímpares são ligados ao eixo Y2"""
            if divmod(i, 2)[1] == 1:
                self.Plots[i].setYAxis(QwtPlot.yRight)
            self.Plots[i].setData(self.Data[i].x, self.Data[i].y)

        # legend
        #self.legend = QwtLegend
        #QwtLegend().setFrameStyle(QFrame.Box)
        #self.insertLegend(QwtLegend().setFrameStyle(QFrame.Box), QwtPlot.BottomLegend)
        self.insertLegend(QwtLegend(), QwtPlot.BottomLegend)

        # replot
        self.replot()

        # zoom
        # self.zoomer = QwtPlotZoomer(QwtPlot.xBottom,
        #                                 QwtPlot.yLeft,
        #                                 QwtPicker.DragSelection,
        #                                 QwtPicker.AlwaysOn,
        #                                 self.canvas())
        #
        # self.zoomer.setRubberBandPen(QPen(Qt.green))
        self.startTimer(50)
Exemplo n.º 6
0
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    doAlign = QwtPainter.roundingAlignment(painter)
    sw2 = .5 * size.width()
    sh2 = .5 * size.height()
    if doAlign:
        sw2 = np.floor(sw2)
        sh2 = np.floor(sh2)
    for pos in points:
        x = pos.x()
        y = pos.y()
        if doAlign:
            x = round(x)
            y = round(y)
        x1 = x - sw2
        x2 = x1 + size.width()
        y1 = y - sh2
        y2 = y1 + size.height()
        if type == QwtTriangle.Left:
            triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)]
        elif type == QwtTriangle.Right:
            triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)]
        elif type == QwtTriangle.Up:
            triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)]
        elif type == QwtTriangle.Down:
            triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)]
        QwtPainter.drawPolygon(painter, QPolygonF(triangle))
Exemplo n.º 7
0
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    if QwtPainter.roundingAlignment(painter):
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            x1 = x - size.width() // 2
            y1 = y - size.height() // 2
            x2 = x1 + size.width()
            y2 = y1 + size.height()
            polygon = QPolygonF()
            polygon += QPointF(x, y1)
            polygon += QPointF(x1, y)
            polygon += QPointF(x, y2)
            polygon += QPointF(x2, y)
            QwtPainter.drawPolygon(painter, polygon)
    else:
        for pos in points:
            x1 = pos.x() - .5 * size.width()
            y1 = pos.y() - .5 * size.height()
            x2 = x1 + size.width()
            y2 = y1 + size.height()
            polygon = QPolygonF()
            polygon += QPointF(pos.x(), y1)
            polygon += QPointF(x1, pos.y())
            polygon += QPointF(pos.x(), y2)
            polygon += QPointF(x2, pos.y())
            QwtPainter.drawPolygon(painter, polygon)
Exemplo n.º 8
0
def qwtDrawRectSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    painter.setRenderHint(QPainter.Antialiasing, False)
    if QwtPainter.roundingAlignment(painter):
        sw = size.width()
        sh = size.height()
        sw2 = size.width()//2
        sh2 = size.height()//2
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            r = QRectF(x-sw2, y-sh2, sw, sh)
            QwtPainter.drawRect(painter, r)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5*size.width()
        sh2 = .5*size.height()
        for pos in points:
            x = pos.x()
            y = pos.y()
            r = QRectF(x-sw2, y-sh2, sw, sh)
            QwtPainter.drawRect(painter, r)
Exemplo n.º 9
0
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width() // 2
        sh2 = size.height() // 2
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            x1 = x - sw2
            x2 = x1 + sw + off
            y1 = y - sh2
            y2 = y1 + sh + off
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5 * size.width()
        sh2 = .5 * size.height()
        for pos in points:
            x1 = pos.x() - sw2
            x2 = x1 + sw
            y1 = pos.y() - sh2
            y2 = y1 + sh
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
Exemplo n.º 10
0
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol):
    size =symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    doAlign = QwtPainter.roundingAlignment(painter)
    sw2 = .5*size.width()
    sh2 = .5*size.height()
    if doAlign:
        sw2 = np.floor(sw2)
        sh2 = np.floor(sh2)
    for pos in points:
        x = pos.x()
        y = pos.y()
        if doAlign:
            x = round(x)
            y = round(y)
        x1 = x-sw2
        x2 = x1+size.width()
        y1 = y-sh2
        y2 = y1+size.height()
        if type == QwtTriangle.Left:
            triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)]
        elif type == QwtTriangle.Right:
            triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)]
        elif type == QwtTriangle.Up:
            triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)]
        elif type == QwtTriangle.Down:
            triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)]
        QwtPainter.drawPolygon(painter, QPolygonF(triangle))
Exemplo n.º 11
0
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol):
    size =symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    if QwtPainter.roundingAlignment(painter):
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            x1 = x-size.width()//2
            y1 = y-size.height()//2
            x2 = x1+size.width()
            y2 = y1+size.height()
            polygon = QPolygonF()
            polygon += QPointF(x, y1)
            polygon += QPointF(x1, y)
            polygon += QPointF(x, y2)
            polygon += QPointF(x2, y)
            QwtPainter.drawPolygon(painter, polygon)
    else:
        for pos in points:
            x1 = pos.x()-.5*size.width()
            y1 = pos.y()-.5*size.height()
            x2 = x1+size.width()
            y2 = y1+size.height()
            polygon = QPolygonF()
            polygon += QPointF(pos.x(), y1)
            polygon += QPointF(x1, pos.y())
            polygon += QPointF(pos.x(), y2)
            polygon += QPointF(x2, pos.y())
            QwtPainter.drawPolygon(painter, polygon)
Exemplo n.º 12
0
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size =symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width()//2
        sh2 = size.height()//2
        for pos in points:
            x = round(pos.x())
            y = round(pos.y())
            x1 = x-sw2
            x2 = x1+sw+off
            y1 = y-sh2
            y2 = y1+sh+off
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5*size.width()
        sh2 = .5*size.height()
        for pos in points:
            x1 = pos.x()-sw2
            x2 = x1+sw
            y1 = pos.y()-sh2
            y2 = y1+sh
            QwtPainter.drawLine(painter, x1, y1, x2, y2)
            QwtPainter.drawLine(painter, x2, y1, x1, y2)
Exemplo n.º 13
0
 def __init__(self, *args):
     QMainWindow.__init__(self, *args)
     self.plot = QwtPlot(self)
     self.plot.setTitle("A Simple Map Demonstration")
     self.plot.setCanvasBackground(Qt.white)
     self.plot.setAxisTitle(QwtPlot.xBottom, "x")
     self.plot.setAxisTitle(QwtPlot.yLeft, "y")
     self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0)
     self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0)
     self.setCentralWidget(self.plot)
     # Initialize map data
     self.count = self.i = 1000
     self.xs = np.zeros(self.count, np.float)
     self.ys = np.zeros(self.count, np.float)
     self.kappa = 0.2
     self.curve = QwtPlotCurve("Map")
     self.curve.attach(self.plot)
     self.curve.setSymbol(
         QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue),
                   QSize(5, 5)))
     self.curve.setPen(QPen(Qt.cyan))
     toolBar = QToolBar(self)
     self.addToolBar(toolBar)
     # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz)
     self.ticks = 10
     self.tid = self.startTimer(self.ticks)
     self.timer_tic = None
     self.user_tic = None
     self.system_tic = None
     self.plot.replot()
Exemplo n.º 14
0
 def __init__(self):
     self.xEnabled = True
     self.yEnabled = True
     self.xMinEnabled = False
     self.yMinEnabled = False
     self.xScaleDiv = QwtScaleDiv()
     self.yScaleDiv = QwtScaleDiv()
     self.majorPen = QPen()
     self.minorPen = QPen()
Exemplo n.º 15
0
    def __init__(self,
                 x=[],
                 y=[],
                 dx=None,
                 dy=None,
                 curvePen=None,
                 curveStyle=None,
                 curveSymbol=None,
                 errorPen=None,
                 errorCap=0,
                 errorOnTop=False):
        """A curve of x versus y data with error bars in dx and dy.

        Horizontal error bars are plotted if dx is not None.
        Vertical error bars are plotted if dy is not None.

        x and y must be sequences with a shape (N,) and dx and dy must be
        sequences (if not None) with a shape (), (N,), or (2, N):
        - if dx or dy has a shape () or (N,), the error bars are given by
          (x-dx, x+dx) or (y-dy, y+dy),
        - if dx or dy has a shape (2, N), the error bars are given by
          (x-dx[0], x+dx[1]) or (y-dy[0], y+dy[1]).

        curvePen is the pen used to plot the curve
        
        curveStyle is the style used to plot the curve
        
        curveSymbol is the symbol used to plot the symbols
        
        errorPen is the pen used to plot the error bars
        
        errorCap is the size of the error bar caps
        
        errorOnTop is a boolean:
        - if True, plot the error bars on top of the curve,
        - if False, plot the curve on top of the error bars.
        """

        QwtPlotCurve.__init__(self)

        if curvePen is None:
            curvePen = QPen(Qt.NoPen)
        if curveStyle is None:
            curveStyle = QwtPlotCurve.Lines
        if curveSymbol is None:
            curveSymbol = QwtSymbol()
        if errorPen is None:
            errorPen = QPen(Qt.NoPen)

        self.setData(x, y, dx, dy)
        self.setPen(curvePen)
        self.setStyle(curveStyle)
        self.setSymbol(curveSymbol)
        self.errorPen = errorPen
        self.errorCap = errorCap
        self.errorOnTop = errorOnTop
Exemplo n.º 16
0
 def __insertCurve(self, orientation, color, base):
     curve = QwtPlotCurve()
     curve.attach(self)
     curve.setPen(QPen(color))
     curve.setSymbol(
         QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.gray), QPen(color),
                   QSize(8, 8)))
     fixed = base * np.ones(10, np.float)
     changing = np.arange(0, 95.0, 10.0, np.float) + 5.0
     if orientation == Qt.Horizontal:
         curve.setData(changing, fixed)
     else:
         curve.setData(fixed, changing)
Exemplo n.º 17
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        # Initialize Decice address,
        #self.uut_dev = GPIBdevice.GPIBdevice(args[0])
        self.rm = visa.ResourceManager()
        print(self.rm.list_resources())
        self.uut_dev = self.rm.open_resource(args[0])

        print('open pass')
        # Initialize 坐标轴
        self.setCanvasBackground(Qt.white)
        self.alignScales()
        grid = QwtPlotGrid()
        grid.attach(self)
        grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine))

        self.setAxisScale(QwtPlot.xBottom, 0.0, 300.1, 10.0)
        self.setAxisAutoScale(QwtPlot.yLeft, True)
        #self.setAxisScale(QwtPlot.yLeft,4.0,20.0,2.0)

        self.x = np.arange(
            0.0, 300.1, 0.5
        )  #0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms

        self.z = np.zeros(len(self.x), np.float)

        self.setTitle("UUT Reading Monitor")
        self.insertLegend(QwtLegend(), QwtPlot.RightLegend)

        self.curveL = QwtPlotCurve("UUT Reading")
        self.curveL.attach(self)

        self.curveL.setPen(QPen(Qt.red))

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading")
        self.replot()

        self.startTimer(500)  #ms# FOR GET READING

        self.starttime = time.clock()
        #unit: s
        self.idx = 0
        self.readfmt = "%.8f"
        self.Saveinfo("Starting...")

        IDN = self.uut_get_val(self.uut_dev, "*IDN?\r")
        print IDN

        print "Starting..."
Exemplo n.º 18
0
    def drawBar(self, painter, orientation, rect):
        painter.save()
        color = painter.pen().color()
        r = rect.normalized()
        factor = 125
        light = color.lighter(factor)
        dark = color.darker(factor)

        painter.setBrush(color)
        painter.setPen(Qt.NoPen)
        QwtPainter.drawRect(painter,
                            r.x() + 1,
                            r.y() + 1,
                            r.width() - 2,
                            r.height() - 2)

        painter.setBrush(Qt.NoBrush)

        painter.setPen(QPen(light, 2))
        QwtPainter.drawLine(painter,
                            r.left() + 1,
                            r.top() + 2,
                            r.right() + 1,
                            r.top() + 2)

        painter.setPen(QPen(dark, 2))
        QwtPainter.drawLine(painter,
                            r.left() + 1, r.bottom(),
                            r.right() + 1, r.bottom())

        painter.setPen(QPen(light, 1))
        QwtPainter.drawLine(painter, r.left(),
                            r.top() + 1, r.left(), r.bottom())
        QwtPainter.drawLine(painter,
                            r.left() + 1,
                            r.top() + 2,
                            r.left() + 1,
                            r.bottom() - 1)

        painter.setPen(QPen(dark, 1))
        QwtPainter.drawLine(painter,
                            r.right() + 1,
                            r.top() + 1,
                            r.right() + 1, r.bottom())
        QwtPainter.drawLine(painter, r.right(),
                            r.top() + 2, r.right(),
                            r.bottom() - 1)

        painter.restore()
Exemplo n.º 19
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)
	# make a QwtPlot widget
        self.plotLayout().setCanvasMargin(0)
        self.plotLayout().setAlignCanvasToScales(1)
        self.setTitle('QwtImagePlot: (un)zoom & (un)hide')
	# set axis titles
        self.setAxisTitle(QwtPlot.xBottom, 'time (s)')
        self.setAxisTitle(QwtPlot.yLeft, 'frequency (Hz)')
	# insert a few curves
        self.cSin = QwtPlotCurve('y = pi*sin(x)')
        self.cCos = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2')
        self.cSin.attach(self)
        self.cCos.attach(self)
	# set curve styles
        self.cSin.setPen(QPen(Qt.green, 2))
        self.cCos.setPen(QPen(Qt.black, 2))
        self.xzoom_loc = None
        self.yzoom_loc = None
        self.xpos = None
        self.ypos = None

	# attach a grid
        grid = QwtPlotGrid()
        grid.attach(self)
        grid.setPen(Qt.black, 0, Qt.DotLine)

        # create zoom curve
        self.zoom_outline = QwtPlotCurve()
        self.zoom_outline.setStyle(QwtPlotCurve.Lines) 

        # create and initialize an image display
        self.plotImage = QwtPlotImage(self)
        self.plotImage.attach(self)
        self.gain = 2.0
        self.updateDisplay()

        self.zoomStack = []

        self.spy = Spy(self.canvas())
        self.prev_xpos = None
        self.prev_ypos = None

#       self.connect(self, Qt.SIGNAL("legendClicked(QwtPlotItem*)"),
#                    self.toggleVisibility)

        self.spy.MouseMove.connect(self.onmouseMoveEvent)
        self.spy.MousePress.connect(self.onmousePressEvent)
        self.spy.MouseRelease.connect(self.onmouseReleaseEvent)
Exemplo n.º 20
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     """
     Draw a round frame
     
     :param QPainter painter: Painter
     :param QRectF rect: Target rectangle
     :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders
     :param int lineWidth: Line width
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5 * lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Exemplo n.º 21
0
def create_log_plot():
    plot = QwtPlot('LogCurveDemo.py (or how to handle -inf values)')
    plot.enableAxis(QwtPlot.xBottom)
    plot.setAxisScaleEngine(QwtPlot.yLeft, QwtLogScaleEngine())
    curve = QwtPlotCurve()
    curve.setRenderHint(QwtPlotCurve.RenderAntialiased)
    pen = QPen(Qt.magenta)
    pen.setWidth(1.5)
    curve.setPen(pen)
    curve.attach(plot)
    x = np.arange(0.0, 10.0, 0.1)
    y = 10 * np.cos(x)**2 - .1
    print("y<=0:", y <= 0)
    curve.setData(x, y)
    plot.replot()
    return plot
Exemplo n.º 22
0
def create_log_plot():
    plot = QwtPlot('LogCurveDemo.py (or how to handle -inf values)')
    plot.enableAxis(QwtPlot.xBottom)
    plot.setAxisScaleEngine(QwtPlot.yLeft, QwtLogScaleEngine())
    curve = QwtPlotCurve()
    curve.setRenderHint(QwtPlotCurve.RenderAntialiased)
    pen = QPen(Qt.magenta)
    pen.setWidth(1.5)
    curve.setPen(pen)
    curve.attach(plot)
    x = np.arange(0.0, 10.0, 0.1)
    y = 10*np.cos(x)**2-.1
    print("y<=0:", y<=0)
    curve.setData(x, y)
    plot.replot()
    return plot
Exemplo n.º 23
0
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol):
    size =symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    for pos in points:
        x1 = pos.x()-.5*size.width()
        y1 = pos.y()-.5*size.height()
        x2 = x1+size.width()
        y2 = y1+size.height()
        polygon = QPolygonF()
        polygon += QPointF(pos.x(), y1)
        polygon += QPointF(x1, pos.y())
        polygon += QPointF(pos.x(), y2)
        polygon += QPointF(x2, pos.y())
        painter.drawPolygon(polygon)
Exemplo n.º 24
0
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size =symbol.size()
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    painter.setPen(pen)
    sw = size.width()
    sh = size.height()
    sw2 = .5*size.width()
    sh2 = .5*size.height()
    for pos in points:
        x1 = pos.x()-sw2
        x2 = x1+sw
        y1 = pos.y()-sh2
        y2 = y1+sh
        painter.drawLine(x1, y1, x2, y2)
        painter.drawLine(x2, y1, x1, y2)
Exemplo n.º 25
0
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    for pos in points:
        x1 = pos.x() - .5 * size.width()
        y1 = pos.y() - .5 * size.height()
        x2 = x1 + size.width()
        y2 = y1 + size.height()
        polygon = QPolygonF()
        polygon += QPointF(pos.x(), y1)
        polygon += QPointF(x1, pos.y())
        polygon += QPointF(pos.x(), y2)
        polygon += QPointF(x2, pos.y())
        painter.drawPolygon(polygon)
Exemplo n.º 26
0
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    painter.setPen(pen)
    sw = size.width()
    sh = size.height()
    sw2 = .5 * size.width()
    sh2 = .5 * size.height()
    for pos in points:
        x1 = pos.x() - sw2
        x2 = x1 + sw
        y1 = pos.y() - sh2
        y2 = y1 + sh
        painter.drawLine(x1, y1, x2, y2)
        painter.drawLine(x2, y1, x1, y2)
Exemplo n.º 27
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        self.curves = {}
        self.data = {}
        self.timeData = 1.0 * np.arange(0, HISTORY, 1)
        self.MemStat = MemStat()

        self.setAutoReplot(False)

        self.plotLayout().setAlignCanvasToScales(True)
        self.setAxisScale(QwtPlot.xBottom, HISTORY, 0)
        self.setAxisScale(QwtPlot.yLeft, 0, 100)
        self.setAxisLabelAlignment(QwtPlot.xBottom,
                                   Qt.AlignLeft | Qt.AlignBottom)

        grid = QwtPlotGrid()
        grid.enableXMin(True)
        grid.enableYMin(True)
        grid.setMajPen(QPen(Qt.black, 0, Qt.DotLine))
        grid.setMinPen(QPen(Qt.gray, 0, Qt.DotLine))

        grid.attach(self)

        stat = MemStat.statistic()

        self.data["MemTotal"] = np.zeros(HISTORY, float)
        self.data["MemFree"] = np.zeros(HISTORY, float)
        self.data["SwapTotal"] = np.zeros(HISTORY, float)
        self.data["SwapFree"] = np.zeros(HISTORY, float)

        curve = MemoryCurve("Memory")
        curve.setColor(self.colors[0])
        curve.attach(self)
        self.curves["Memory"] = curve
        self.data["Memory"] = np.zeros(HISTORY, float)

        curve = MemoryCurve("Swap")
        curve.setColor(self.colors[1])
        curve.attach(self)
        self.curves["Swap"] = curve
        self.data["Swap"] = np.zeros(HISTORY, float)

        self.startTimer(1000)
        self.replot()
Exemplo n.º 28
0
 def __init__(self, size):
     super(QwtStyleSheetRecorder, self).__init__()
     self.__size = size
     self.__pen = QPen()
     self.__brush = QBrush()
     self.__origin = QPointF()
     self.clipRects = []
     self.border = Border()
     self.background = Background()
Exemplo n.º 29
0
 def __init__(self):
     QwtPlotItem_PrivateData.__init__(self)
     self.style = QwtPlotCurve.Lines
     self.baseline = 0.
     self.symbol = None
     self.attributes = 0
     self.legendAttributes = QwtPlotCurve.LegendShowLine
     self.pen = QPen(Qt.black)
     self.brush = QBrush()
Exemplo n.º 30
0
 def __init__(self):
     self.labelAlignment = Qt.AlignCenter
     self.labelOrientation = Qt.Horizontal
     self.spacing = 2
     self.symbol = None
     self.style = QwtPlotMarker.NoLine
     self.xValue = 0.
     self.yValue = 0.
     self.label = QwtText()
     self.pen = QPen()
Exemplo n.º 31
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)
        self.insertLegend(QwtLegend(), QwtPlot.RightLegend)
        self.enableAxis(self.xBottom)

        # insert a few curves
        self.Alpha = QwtPlotCurve('Alpha')
        self.Alpha.setPen(QPen(Qt.red))
        self.Alpha.attach(self)
        self.Epsilon = QwtPlotCurve('Epsilon')
        self.Epsilon.setPen(QPen(Qt.blue))
        self.Epsilon.attach(self)

        # initialize the data
        self.Alpha.setData([0], [0])
        self.Epsilon.setData([0], [0])

        # replot
        self.replot()
Exemplo n.º 32
0
 def params(self, *args):
     symbols, = args
     symb1 = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue),
                       QSize(5, 5))
     symb2 = QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta),
                       QSize(5, 5))
     if symbols:
         return (
             ('Sticks', symb1),
             ('Lines', symb1),
             ('Steps', symb2),
             ('Dots', symb2),
         )
     else:
         return (
             ('Sticks', None),
             ('Lines', None),
             ('Steps', None),
             ('Dots', None),
         )
Exemplo n.º 33
0
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing, False)
    sw = size.width()
    sh = size.height()
    sw2 = .5 * size.width()
    sh2 = .5 * size.height()
    for pos in points:
        if orientations & Qt.Horizontal:
            x = round(pos.x()) - sw2
            y = round(pos.y())
            painter.drawLine(x, y, x + sw, y)
        if orientations & Qt.Vertical:
            x = round(pos.x())
            y = round(pos.y()) - sh2
            painter.drawLine(x, y, x, y + sh)
Exemplo n.º 34
0
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol):
    size =symbol.size()
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing, False)
    sw = size.width()
    sh = size.height()
    sw2 = .5*size.width()
    sh2 = .5*size.height()
    for pos in points:
        if orientations & Qt.Horizontal:
            x = round(pos.x())-sw2
            y = round(pos.y())
            painter.drawLine(x, y, x+sw, y)
        if orientations & Qt.Vertical:
            x = round(pos.x())
            y = round(pos.y())-sh2
            painter.drawLine(x, y, x, y+sh)
Exemplo n.º 35
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)
        self.setTitle('ReallySimpleDemo.py')
        self.insertLegend(QwtLegend(), QwtPlot.RightLegend)
        self.setAxisTitle(QwtPlot.xBottom, 'x -->')
        self.setAxisTitle(QwtPlot.yLeft, 'y -->')
        self.enableAxis(self.xBottom)

        # insert a few curves
        cSin = QwtPlotCurve('y = sin(x)')
        cSin.setPen(QPen(Qt.red))
        cSin.attach(self)
        cCos = QwtPlotCurve('y = cos(x)')
        cCos.setPen(QPen(Qt.blue))
        cCos.attach(self)

        # make a Numeric array for the horizontal data
        x = np.arange(0.0, 10.0, 0.1)

        # initialize the data
        cSin.setData(x, np.sin(x))
        cCos.setData(x, np.cos(x))

        # insert a horizontal marker at y = 0
        mY = QwtPlotMarker()
        mY.setLabel(QwtText('y = 0'))
        mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop)
        mY.setLineStyle(QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        # insert a vertical marker at x = 2 pi
        mX = QwtPlotMarker()
        mX.setLabel(QwtText('x = 2 pi'))
        mX.setLabelAlignment(Qt.AlignRight | Qt.AlignTop)
        mX.setLineStyle(QwtPlotMarker.VLine)
        mX.setXValue(2 * np.pi)
        mX.attach(self)

        # replot
        self.replot()
Exemplo n.º 36
0
 def __init__(self):
     QwtPlotItem_PrivateData.__init__(self)
     self.style = QwtPlotCurve.Lines
     self.baseline = 0.
     self.symbol = None
     self.attributes = 0
     self.paintAttributes = QwtPlotCurve.FilterPoints
     #TODO: uncomment next line when QwtClipper will be implemented
     #        self.paintAttributes = QwtPlotCurve.ClipPolygons|QwtPlotCurve.FilterPoints
     self.legendAttributes = QwtPlotCurve.LegendShowLine
     self.pen = QPen(Qt.black)
     self.brush = QBrush()
Exemplo n.º 37
0
def qwtDrawStar2Symbols(painter, points, numPoints, symbol):
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    cos30 = np.cos(30*np.pi/180.)
    dy = .25*symbol.size().height()
    dx = .5*symbol.size().width()*cos30/3.
    for pos in points:
        x = pos.x()
        y = pos.y()
        x1 = x-3*dx
        y1 = y-2*dy
        x2 = x1+1*dx
        x3 = x1+2*dx
        x4 = x1+3*dx
        x5 = x1+4*dx
        x6 = x1+5*dx
        x7 = x1+6*dx
        y2 = y1+1*dy
        y3 = y1+2*dy
        y4 = y1+3*dy
        y5 = y1+4*dy
        star = [QPointF(x4, y1), QPointF(x5, y2), QPointF(x7, y2),
                QPointF(x6, y3), QPointF(x7, y4), QPointF(x5, y4),
                QPointF(x4, y5), QPointF(x3, y4), QPointF(x1, y4),
                QPointF(x2, y3), QPointF(x1, y2), QPointF(x3, y2)]
        painter.drawPolygon(QPolygonF(star))
Exemplo n.º 38
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        p = QPalette()
        p.setColor(self.backgroundRole(), QColor(30, 30, 50))
        self.setPalette(p)
        # make curves and maps
        self.tuples = []
        # curve 1
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(150, 150, 200), 2))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setSymbol(QwtSymbol(QwtSymbol.XCross,
                                      QBrush(),
                                      QPen(Qt.yellow, 2),
                                      QSize(7, 7)))
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, -1.5, 1.5),
                            QwtScaleMap(0, 100, 0.0, 2*np.pi)))
        # curve 2
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(200, 150, 50),
                                1,
                                Qt.DashDotDotLine))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse,
                                      QBrush(Qt.blue),
                                      QPen(Qt.yellow),
                                      QSize(5, 5)))
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, 0.0, 2*np.pi),
                            QwtScaleMap(0, 100, -3.0, 1.1)))
        # curve 3
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(100, 200, 150)))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, -1.1, 3.0),
                            QwtScaleMap(0, 100, -1.1, 3.0)))
        # curve 4
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, -5.0, 1.1),
                            QwtScaleMap(0, 100, -1.1, 5.0)))
        # data
        self.phase = 0.0
        self.base = np.arange(0.0, 2.01*np.pi, 2*np.pi/(USize-1))
        self.uval = np.cos(self.base)
        self.vval = np.sin(self.base)
        self.uval[1::2] *= 0.5
        self.vval[1::2] *= 0.5
        self.newValues()
        # start timer
        self.tid = self.startTimer(250)
Exemplo n.º 39
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.xMap = QwtScaleMap()
        self.xMap.setScaleInterval(-0.5, 10.5)
        self.yMap = QwtScaleMap()
        self.yMap.setScaleInterval(-1.1, 1.1)

        # frame style
        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        # calculate values
        self.x = np.arange(0, 10.0, 10.0 / 27)
        self.y = np.sin(self.x) * np.cos(2 * self.x)

        # make curves with different styles
        self.curves = []
        self.titles = []
        # curve 1
        self.titles.append('Style: Sticks, Symbol: Ellipse')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue),
                      QSize(5, 5)))
        self.curves.append(curve)
        # curve 2
        self.titles.append('Style: Lines, Symbol: None')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        self.curves.append(curve)
        # curve 3
        self.titles.append('Style: Lines, Symbol: None, Antialiased')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setRenderHint(QwtPlotItem.RenderAntialiased)
        self.curves.append(curve)
        # curve 4
        self.titles.append('Style: Steps, Symbol: None')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkCyan))
        curve.setStyle(QwtPlotCurve.Steps)
        self.curves.append(curve)
        # curve 5
        self.titles.append('Style: NoCurve, Symbol: XCross')
        curve = QwtPlotCurve()
        curve.setStyle(QwtPlotCurve.NoCurve)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta),
                      QSize(5, 5)))
        self.curves.append(curve)

        # attach data, using Numeric
        for curve in self.curves:
            curve.setData(self.x, self.y)
Exemplo n.º 40
0
def qwtDrawLineSymbols(painter, orientations, points, numPoints, symbol):
    size =symbol.size()
    off = 0
    pen = QPen(symbol.pen())
    if pen.width() > 1:
        pen.setCapStyle(Qt.FlatCap)
        off = 1
    painter.setPen(pen)
    painter.setRenderHint(QPainter.Antialiasing, False)
    if QwtPainter.roundingAlignment(painter):
        sw = np.floor(size.width())
        sh = np.floor(size.height())
        sw2 = size.width()//2
        sh2 = size.height()//2
        for pos in points:
            if orientations & Qt.Horizontal:
                x = round(pos.x())-sw2
                y = round(pos.y())
                QwtPainter.drawLine(painter, x, y, x+sw+off, y)
            if orientations & Qt.Vertical:
                x = round(pos.x())
                y = round(pos.y())-sh2
                QwtPainter.drawLine(painter, x, y, x, y+sh+off)
    else:
        sw = size.width()
        sh = size.height()
        sw2 = .5*size.width()
        sh2 = .5*size.height()
        for pos in points:
            if orientations & Qt.Horizontal:
                x = round(pos.x())-sw2
                y = round(pos.y())
                QwtPainter.drawLine(painter, x, y, x+sw, y)
            if orientations & Qt.Vertical:
                x = round(pos.x())
                y = round(pos.y())-sh2
                QwtPainter.drawLine(painter, x, y, x, y+sh)
Exemplo n.º 41
0
 def draw(self, painter, xMap, yMap, canvasRect):
     minorPen = QPen(self.__data.minorPen)
     minorPen.setCapStyle(Qt.FlatCap)
     painter.setPen(minorPen)
     if self.__data.xEnabled and self.__data.xMinEnabled:
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MinorTick))
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MediumTick))
     if self.__data.yEnabled and self.__data.yMinEnabled:
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MinorTick))
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MediumTick))
     majorPen = QPen(self.__data.majorPen)
     majorPen.setCapStyle(Qt.FlatCap)
     painter.setPen(majorPen)
     if self.__data.xEnabled:
         self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                        self.__data.xScaleDiv.ticks(QwtScaleDiv.MajorTick))
     if self.__data.yEnabled:
         self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                        self.__data.yScaleDiv.ticks(QwtScaleDiv.MajorTick))
Exemplo n.º 42
0
    def draw(self, painter, xMap, yMap, canvasRect):
        """
        Draw the grid

        The grid is drawn into the bounding rectangle such that
        grid lines begin and end at the rectangle's borders. The X and Y
        maps are used to map the scale divisions into the drawing region
        screen.

        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap xMap: X axis map
        :param qwt.scale_map.QwtScaleMap yMap: Y axis
        :param QRectF canvasRect: Contents rectangle of the plot canvas
        """
        minorPen = QPen(self.__data.minorPen)
        minorPen.setCapStyle(Qt.FlatCap)
        painter.setPen(minorPen)
        if self.__data.xEnabled and self.__data.xMinEnabled:
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MinorTick))
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MediumTick))
        if self.__data.yEnabled and self.__data.yMinEnabled:
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MinorTick))
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MediumTick))
        majorPen = QPen(self.__data.majorPen)
        majorPen.setCapStyle(Qt.FlatCap)
        painter.setPen(majorPen)
        if self.__data.xEnabled:
            self.drawLines(painter, canvasRect, Qt.Vertical, xMap,
                           self.__data.xScaleDiv.ticks(QwtScaleDiv.MajorTick))
        if self.__data.yEnabled:
            self.drawLines(painter, canvasRect, Qt.Horizontal, yMap,
                           self.__data.yScaleDiv.ticks(QwtScaleDiv.MajorTick))
Exemplo n.º 43
0
 def drawRoundedFrame(self, painter, rect, xRadius, yRadius,
                      palette, lineWidth, frameStyle):
     """
     Draw a rectangular frame with rounded borders
     
     :param QPainter painter: Painter
     :param QRectF rect: Frame rectangle
     :param float xRadius: x-radius of the ellipses defining the corners
     :param float yRadius: y-radius of the ellipses defining the corners
     :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders
     :param int lineWidth: Line width
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(Qt.NoBrush)
     lw2 = lineWidth*.5
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     path = QPainterPath()
     path.addRoundedRect(r, xRadius, yRadius)
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     if (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     if style != Plain and path.elementCount() == 17:
         pathList = [QPainterPath() for _i in range(8)]
         for i in range(4):
             j = i*4+1
             pathList[2*i].moveTo(path.elementAt(j-1).x,
                                  path.elementAt(j-1).y)
             pathList[2*i].cubicTo(
                     path.elementAt(j+0).x, path.elementAt(j+0).y,
                     path.elementAt(j+1).x, path.elementAt(j+1).y,
                     path.elementAt(j+2).x, path.elementAt(j+2).y)
             pathList[2*i+1].moveTo(path.elementAt(j+2).x,
                                    path.elementAt(j+2).y)
             pathList[2*i+1].lineTo(path.elementAt(j+3).x,
                                    path.elementAt(j+3).y)
         c1 = QColor(palette.color(QPalette.Dark))
         c2 = QColor(palette.color(QPalette.Light))
         if style == Raised:
             c1, c2 = c2, c1
         for i in range(5):
             r = pathList[2*i].controlPointRect()
             arcPen = QPen()
             arcPen.setCapStyle(Qt.FlatCap)
             arcPen.setWidth(lineWidth)
             linePen = QPen()
             linePen.setCapStyle(Qt.FlatCap)
             linePen.setWidth(lineWidth)
             if i == 0:
                 arcPen.setColor(c1)
                 linePen.setColor(c1)
             elif i == 1:
                 gradient = QLinearGradient()
                 gradient.setStart(r.topLeft())
                 gradient.setFinalStop(r.bottomRight())
                 gradient.setColorAt(0., c1)
                 gradient.setColorAt(1., c2)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c2)
             elif i == 2:
                 arcPen.setColor(c2)
                 linePen.setColor(c2)
             elif i == 3:
                 gradient = QLinearGradient()
                 gradient.setStart(r.bottomRight())
                 gradient.setFinalStop(r.topLeft())
                 gradient.setColorAt(0., c2)
                 gradient.setColorAt(1., c1)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c1)
             painter.setPen(arcPen)
             painter.drawPath(pathList[2*i])
             painter.setPen(linePen)
             painter.drawPath(pathList[2*i+1])
     else:
         pen = QPen(palette.color(QPalette.WindowText), lineWidth)
         painter.setPen(pen)
         painter.drawPath(path)
     painter.restore()
Exemplo n.º 44
0
 def drawRoundedFrame(self, painter, rect, xRadius, yRadius,
                      palette, lineWidth, frameStyle):
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing, True)
     painter.setBrush(Qt.NoBrush)
     lw2 = lineWidth*.5
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     path = QPainterPath()
     path.addRoundedRect(r, xRadius, yRadius)
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     if (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     if style != Plain and path.elementCount() == 17:
         pathList = [QPainterPath() for _i in range(8)]
         for i in range(4):
             j = i*4+1
             pathList[2*i].moveTo(path.elementAt(j-1).x,
                                  path.elementAt(j-1).y)
             pathList[2*i].cubicTo(
                     path.elementAt(j+0).x, path.elementAt(j+0).y,
                     path.elementAt(j+1).x, path.elementAt(j+1).y,
                     path.elementAt(j+2).x, path.elementAt(j+2).y)
             pathList[2*i+1].moveTo(path.elementAt(j+2).x,
                                    path.elementAt(j+2).y)
             pathList[2*i+1].lineTo(path.elementAt(j+3).x,
                                    path.elementAt(j+3).y)
         c1 = QColor(palette.color(QPalette.Dark))
         c2 = QColor(palette.color(QPalette.Light))
         if style == Raised:
             c1, c2 = c2, c1
         for i in range(5):
             r = pathList[2*i].controlPointRect()
             arcPen = QPen()
             arcPen.setCapStyle(Qt.FlatCap)
             arcPen.setWidth(lineWidth)
             linePen = QPen()
             linePen.setCapStyle(Qt.FlatCap)
             linePen.setWidth(lineWidth)
             if i == 0:
                 arcPen.setColor(c1)
                 linePen.setColor(c1)
             elif i == 1:
                 gradient = QLinearGradient()
                 gradient.setStart(r.topLeft())
                 gradient.setFinalStop(r.bottomRight())
                 gradient.setColorAt(0., c1)
                 gradient.setColorAt(1., c2)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c2)
             elif i == 2:
                 arcPen.setColor(c2)
                 linePen.setColor(c2)
             elif i == 3:
                 gradient = QLinearGradient()
                 gradient.setStart(r.bottomRight())
                 gradient.setFinalStop(r.topLeft())
                 gradient.setColorAt(0., c2)
                 gradient.setColorAt(1., c1)
                 arcPen.setBrush(gradient)
                 linePen.setColor(c1)
             painter.setPen(arcPen)
             painter.drawPath(pathList[2*i])
             painter.setPen(linePen)
             painter.drawPath(pathList[2*i+1])
     else:
         pen = QPen(palette.color(QPalette.WindowText), lineWidth)
         painter.setPen(pen)
         painter.drawPath(path)
     painter.restore()