Esempio n. 1
0
    def drawLines(self, qp):
        pen = QPen(Qt.gray, 3, Qt.SolidLine)

        qp.setPen(pen)
        qp.drawLine(20, 300, 400, 0)

        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(20, 320, 400, 0)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 340, 400, 0)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(20, 360, 400, 40)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 380, 400, 40)

        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 400, 400, 40)
Esempio n. 2
0
class SlidingWindow(pg.PlotWidget):
    """SlidingWindow gives access to the windowSize most recent values that were appended to it.
    Since the class inherits the pg.PlotWidget it can be added to the UI as a plot widget with a 
    sliding window. It is not yet verified that this will work. However it is worth a try ;)."""
    def __init__(self, windowSize, *args, **kwargs):
        super().__init__(*args, **kwargs) #Call the pg.PlotWidget so this class has the same behaviour as the PlotWidget object
        self.data = np.array([])
        self.n = 0
        self.windowSize = windowSize
        
        self.pen = QPen()
        self.pen.setColor(QColor(145,255,244))
        self.pen.setWidth(.7)
        self.pen.setStyle(Qt.DashLine)
        self.plotData = self.plot(pen=self.pen) #call plot, so it is not needed to calll this in the UI. However, you can still change the pen variables in the UI.
        
    def append_(self, values):
        """Append new values to the sliding window."""
        lenValues = len(values)
        if self.n+lenValues > self.windowSize:
            #Buffer is full so make room.
            copySize = self.windowSize-lenValues
            self.data = self.data[-copySize:]
            self.n = copySize
            
        self.data = np.append(self.data, values)
        
        self.n += lenValues
        
    def updateWindow(self):
        """Get a window of the most recent 'windowSize' samples (or less if not available)."""
        self.plotData.setData(self.data)
Esempio n. 3
0
    def drawLines(self, qp):
        #画笔,颜色、线宽、线型
        pen = QPen(Qt.black, 2, Qt.SolidLine)

        qp.setPen(pen)  #设置画笔
        qp.drawLine(20, 40, 250, 40)  #绘制直线

        pen.setStyle(Qt.DashLine)  #更改线型
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 4
0
    def drawLines(self, qp):
        # 新建一个`QPen`对象,设置颜色黑色,宽2像素,这样就能看出来各个笔样式的区别。`Qt.SolidLine`是预定义样式的一种。
        pen = QPen(Qt.black, 2, Qt.SolidLine)
        qp.setPen(pen)
        # 绘制直线,前两个参数为左端点的坐标,后两个参数为右端点的坐标
        qp.drawLine(50, 100, 280, 100)

        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(50, 140, 280, 140)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(50, 180, 280, 180)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(50, 220, 280, 220)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(50, 260, 280, 260)

        # 这里我们自定义了一个笔的样式。定义为`Qt.CustomDashLine`然后调用`setDashPattern()`方法。
        # 数字列表是线的样式,要求必须是个数为奇数,奇数位定义的是空格,偶数位为线长,数字越大,空格或线长越大
        # 比如本例的就是1像素线,4像素空格,5像素线,4像素空格。
        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(50, 300, 280, 300)
Esempio n. 5
0
    def drawLines(self, painter):
        """自定义绘制参数"""
        pen = QPen(Qt.black, 2, Qt.SolidLine)

        painter.setPen(pen)
        painter.drawLine(20, 40, 250, 40)

        pen.setStyle(Qt.DashLine)
        painter.setPen(pen)
        painter.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        painter.setPen(pen)
        painter.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        painter.setPen(pen)
        painter.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        painter.setPen(pen)
        painter.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)
        # 线 + 空格 + 线 + 空格 : 单位像素
        pen.setDashPattern([1, 4, 5, 4])
        painter.setPen(pen)
        painter.drawLine(20, 240, 250, 240)
Esempio n. 6
0
File: main.py Progetto: zif108/paint
class Rectangle:
    def __init__(self, x, y, width, hight):
        global color
        global thickness
        global highlight
        self.x = x
        self.y = y
        self.width = width
        self.hight = hight
        self.fon = 0
        self.r = 173
        self.g = 173
        self.b = 173
        if not highlight:
            self.pen = QPen(QColor(color[0], color[1], color[2]))
            self.pen.setWidth(thickness)
        else:
            self.pen = QPen(QColor(173, 173, 173))
            self.pen.setStyle(Qt.DashLine)
            self.pen.setWidth(2)

    def draw(self, painter):
        if not highlight:
            painter.setBrush(QBrush(QColor(0, 0, 0, 0)))
            painter.setPen(self.pen)
            painter.drawRect(self.x, self.y, self.width, self.hight)
        else:
            painter.setBrush(QBrush(QColor(self.r, self.g, self.b, self.fon)))
            painter.setPen(self.pen)
            painter.drawRect(self.x, self.y, self.width, self.hight)
Esempio n. 7
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        W = self.width()
        H = self.height()
        side = min(W, H)
        rect = QRect((W-side)/2, (H-side)/2, side, side)
        painter.drawRect((rect))
        painter.setViewport(rect)
        painter.setWindow(-100, -100, 200, 200)

        pen = QPen()
        pen.setWidth(1)
        pen.setColor(Qt.blue)
        pen.setStyle(Qt.SolidLine)
        painter.setPen(pen)

        linearGrad = QLinearGradient(0, 0, 100, 0)
        linearGrad.setColorAt(0, Qt.yellow)
        linearGrad.setColorAt(0.8, Qt.green)
        linearGrad.setSpread(QGradient.ReflectSpread)
        painter.setBrush(linearGrad)

        painter.setCompositionMode(QPainter.CompositionMode_Difference)


        for i in range(36):
            painter.drawEllipse(QPoint(50, 0), 50, 50)
            painter.rotate(10)
Esempio n. 8
0
    def update_chart(self, update_axis=True, update_lines=True):
        pixmap = QPixmap(self.legend.size())
        pixmap.fill(QColor(0, 0, 0, 0))
        qp = QPainter()
        qp.begin(pixmap)

        y_spacing = 30
        legend_pen = QPen()
        qp.setPen(legend_pen)
        for i in range(len(self.page['lines'])):
            line = self.page['lines'][i]
            qp.setPen(legend_pen)
            qp.drawText(QRect(10, 12 + i * y_spacing, 120, 20), Qt.AlignLeft,
                        line.name)
            line_pen = QPen()
            line_pen.setWidth(4)
            line_pen.setColor(line.line_colour)
            line_pen.setStyle(line.line_style)
            if line.line_pattern and line.line_style is Qt.CustomDashLine:
                line_pen.setDashPattern(line.line_pattern)
            qp.setPen(line_pen)
            qp.drawLine(140, 10 + i * y_spacing + 10, 190,
                        10 + i * y_spacing + 10)
        qp.end()
        self.legend.setPixmap(pixmap)

        if self.page['lines'] and self.datasets:
            self.chart.paint_lines(self.page['lines'], update_lines,
                                   update_axis)
Esempio n. 9
0
 def updateCircle(self, s):
     size = s * self.zoom
     pixmap = QPixmap(self.width(), self.height())
     pixmap.fill(Qt.transparent)
     #painter ellipse 1
     painter = QPainter()
     painter.begin(pixmap)
     painter.setRenderHint(QPainter.Antialiasing)
     pen = QPen(Qt.red)
     pen.setWidth(3)
     painter.setPen(pen)
     brush = QBrush(Qt.green)
     painter.setBrush(brush)
     painter.drawEllipse(QRect(old_div(self.width(),2) - old_div(size,2), old_div(self.height(),2) - old_div(size,2), size, size))
     painter.end()
     #painter ellipse 2
     painter2 = QPainter()
     painter2.begin(pixmap)
     painter2.setRenderHint(QPainter.Antialiasing)
     pen2 = QPen(Qt.green)
     pen2.setStyle(Qt.DotLine)
     pen2.setWidth(3)
     painter2.setPen(pen2)
     painter2.drawEllipse(QRect(old_div(self.width(),2) - old_div(size,2), old_div(self.height(),2) - old_div(size,2), size, size))
     painter2.end()
     
     self.ellipseLabel.setPixmap(QPixmap(pixmap))
     self.lastSize = s
Esempio n. 10
0
 def mouseMoveEvent(self, event):
     e = event.pos()
     e = self.mapToScene(e)
     area_select = QRectF(e.x() - 3, e.y() - 3, 6, 6)
     items = self.scene_v.items(area_select)
     if not self.buttonPressed:
         dx = e.x() - self._startPos.x()
         dy = e.y() - self._startPos.y()
         new_x = self.horizontalScrollBar().value() - dx
         new_y = self.verticalScrollBar().value() - dy
         self.horizontalScrollBar().setValue(new_x)
         self.verticalScrollBar().setValue(new_y)
     if self.is_pipe and self.cond_pipe:
         if items:
             l_n = self.l_i_nodes + self.l_i_reservoir
             l_n_2 = self.l_nodes + self.l_reservoir
             if items[0] in l_n:
                 e.setX(l_n_2[l_n.index(items[0])].x)
                 e.setY(l_n_2[l_n.index(items[0])].y)
         self.current_item.setLine(self.start_e.x(), self.start_e.y(),
                                   e.x(), e.y())
         pen = QPen(QColor('black'))
         pen.setWidth(1)
         pen.setStyle(Qt.DotLine)
         self.current_item.setPen(pen)
     if self.is_area_select and len(self.area_select) > 1:
         self.area_select.append(e)
         self.current_item.setPolygon(QPolygonF(self.area_select))
         self.area_select = self.area_select[:-1]
Esempio n. 11
0
    def drawGlyph(self,
                  scene,
                  glyph,
                  offsetX=0,
                  offsetY=0,
                  color=(255, 255, 255)):
        path = QPainterPath()
        path.setFillRule(Qt.WindingFill)
        for c in self.decomposedPaths(glyph):
            segs = c.segments
            path.moveTo(segs[-1].points[-1].x, segs[-1].points[-1].y)
            for seg in segs:
                tuples = [(a.x, a.y) for a in seg.points]
                flattuples = list(sum(tuples, ()))
                if len(tuples) == 2:
                    path.quadTo(*flattuples)
                elif len(tuples) == 3:
                    path.cubicTo(*flattuples)
                else:
                    path.lineTo(*flattuples)

        line = QGraphicsPathItem()
        line.setBrush(QColor(*color))
        p = QPen()
        p.setStyle(Qt.NoPen)
        line.setPen(p)
        line.setPath(path)
        reflect = QTransform(1, 0, 0, -1, 0, 0)
        reflect.translate(offsetX, offsetY)
        # print(f"Drawing {glyph} at offset {offsetX} {offsetY}")
        line.setTransform(reflect)
        scene.addItem(line)
    def drawLine(self, paint):
        pen = QPen(Qt.blue, 4, Qt.SolidLine)
        paint.setPen(pen)
        paint.drawLine(100, 40, 400, 40)

        pen.setStyle(Qt.DashLine)
        pen.setColor(Qt.yellow)
        paint.setPen(pen)
        paint.drawLine(100, 80, 400, 80)

        pen.setStyle(Qt.DashDotLine)
        pen.setColor(Qt.red)
        paint.setPen(pen)
        paint.drawLine(100, 120, 400, 120)

        pen.setStyle(Qt.DashDotDotLine)
        pen.setColor(Qt.darkMagenta)
        paint.setPen(pen)
        paint.drawLine(100, 160, 400, 160)

        pen.setStyle(Qt.DotLine)
        pen.setColor(Qt.darkGreen)
        pen.setWidth(2)
        paint.setPen(pen)
        paint.drawLine(100, 200, 400, 200)

        pen.setStyle(Qt.CustomDashLine)  # 내가 직접 제작하는 라인
        pen.setDashPattern([4, 4, 6, 4])  # Dash, 공간, Dash, 공간
        pen.setColor(Qt.darkGray)
        pen.setWidth(8)
        paint.setPen(pen)
        paint.drawLine(100, 240, 400, 240)
Esempio n. 13
0
    def draw_lines(self, qp):
        pen = QPen(Qt.black, 2, Qt.SolidLine)  # 钢笔样式 2px 黑色

        qp.setPen(pen)
        qp.drawLine(20, 40, 250, 40)

        # 以下是五种风格的钢笔
        pen.setStyle(Qt.DashLine)  # 虚线
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)  # 虚+点线
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)  # 点线
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)  # 虚+点+点线
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)  # 自定义了一个形状

        # 第一个数 1 表示 1px 实点的宽度,第二个数 4 表示 4px 的空白
        # 第三个数 5 表示 5px 实点的宽度,第四个数 4 表示 4px 的空白
        # 我们可以增加或减少列表里的数字
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 14
0
    def drawLines(self, qp):
        pen = QPen(Qt.black, 2, Qt.SolidLine)  # создание объекта, цвет - черный, жирность - 2px,
        # Qt.SolidLine – это один из стилей (жирная линия)
        qp.setPen(pen)  # создание объекта, и установка параметров ручки
        qp.drawLine(20, 40, 250, 40)  # рисование линии

        pen.setStyle(Qt.DashLine)  # стиль пунктир
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)  # стиль пунктир точка
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)  # стиль пунктир мелкий
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)  # стиль пунктир точка точка
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        # определяем пользовательский стиль ручки.
        # Мы устанавливаем стиль ручки Qt.CustomDashLine и вызываем метод setDashPattern().
        # Список чисел определяет стиль. Может быть даже несколько чисел.
        # Нечётные числа определяют сплошную линию, чётные числа – промежутки.
        # Чем больше число, тем больше промежуток или штрих.
        # Наш образец – штрих в 1 пиксель, промежуток в 4 пикселя, штрих в 5 пикселей, промежуток в 4 пикселя
        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 15
0
 def paintEvent(self, event):
     _size = self.size() - QSize(2, 2)
     if (_size.isEmpty()):
         return
     origX = (_size.width() - self.mNewSize.width() * self.mScale) / 2 + 0.5
     origY = (_size.height() -
              self.mNewSize.height() * self.mScale) / 2 + 0.5
     oldRect = QRect(self.mOffset, self.mOldSize)
     painter = QPainter(self)
     painter.translate(origX, origY)
     painter.scale(self.mScale, self.mScale)
     pen = QPen(Qt.black)
     pen.setCosmetic(True)
     painter.setPen(pen)
     painter.drawRect(QRect(QPoint(0, 0), self.mNewSize))
     pen.setColor(Qt.white)
     painter.setPen(pen)
     painter.setBrush(Qt.white)
     painter.setOpacity(0.5)
     painter.drawRect(oldRect)
     pen.setColor(Qt.black)
     pen.setStyle(Qt.DashLine)
     painter.setOpacity(1.0)
     painter.setBrush(Qt.NoBrush)
     painter.setPen(pen)
     painter.drawRect(oldRect)
     painter.end()
Esempio n. 16
0
def render_avatar_image(image: QImage, size: float):
    if image.isNull():
        return None

    aspect_ratio = image.width() / image.height()
    if aspect_ratio > 1:
        width = size
        height = size / aspect_ratio
    else:
        width = size * aspect_ratio
        height = size

    x0 = (size - width) / 2
    y0 = (size - height) / 2

    path = QPainterPath()
    path.addEllipse(QRectF(x0, y0, width, height))
    picture = QPicture()
    painter = QPainter(picture)
    painter.setRenderHint(QPainter.Antialiasing, True)
    pen = QPen(Qt.black, 5)
    pen.setStyle(Qt.SolidLine)
    painter.setPen(pen)
    painter.setClipPath(path)
    painter.drawImage(
        QRectF(x0, y0, width, height),
        image,
    )
    painter.end()
    return picture
Esempio n. 17
0
    def drawRectangles(self, painter):
        """
        Examples of how to draw rectangles with QPainter.
        """
        pen = QPen(QColor(self.black))
        brush = QBrush(QColor(self.black))

        painter.setPen(pen)
        painter.drawRect(20, 220, 80, 80)

        painter.setPen(pen)
        painter.setBrush(brush)
        painter.drawRect(120, 220, 80, 80)

        red_pen = QPen(QColor(self.red), 5)
        green_brush = QBrush(QColor(self.green))

        painter.setPen(red_pen)
        painter.setBrush(green_brush)
        painter.drawRect(20, 320, 80, 80)

        # Demonstrate how to change the alpha channel
        # to include transparency
        blue_pen = QPen(QColor(32, 85, 230, 100), 5)
        blue_pen.setStyle(Qt.DashLine)
        painter.setPen(blue_pen)
        painter.setBrush(green_brush)
        painter.drawRect(120, 320, 80, 80)
Esempio n. 18
0
    def drawPath(self, paths):

        pen = QPen(QColor('#000000'))
        pen.setStyle(Qt.DashLine)
        pen.setDashPattern([10, 4])

        self.painter.setPen(pen)

        gs = controller.gridSize

        for path in paths:
            for i in range(len(path) - 1):
                a = path[i]
                b = path[i + 1]
                vx, vy = b[0] - a[0], b[1] - a[1]
                d = math.sqrt(vx * vx + vy * vy)

                # Chuyển về vector đơn vị
                vx = vx / d
                vy = vy / d
                # Xoay 90 độ
                vx, vy = -vy, vx

                vx = vx * 2 + gs / 2
                vy = vy * 2 + gs / 2

                self.qpDrawLine(a[0] * gs + vx, a[1] * gs + vy, b[0] * gs + vx,
                                b[1] * gs + vy)

        self.painter.setPen(Qt.SolidLine)
Esempio n. 19
0
    def paint(self, painter, option, widget=None):
        # Draw header
        rect = QRectF(0, 0, 20, 20)

        if self.stage:
            brush = QBrush(self.on_color_1)
        else:
            brush = QBrush(self.off_color_1)

        pen = QPen()
        pen.setStyle(LINE_SOLID)
        pen.setWidthF(1)
        pen.setWidth(2)
        pen.setCapStyle(ROUND_CAP)
        pen.setJoinStyle(ROUND_JOIN)
        painter.setBrush(brush)
        painter.setPen(pen)
        painter.drawEllipse(-5, -5, 10, 10)

        if self.stage:
            brush = QBrush(self.on_color_2)
        else:
            brush = QBrush(self.off_color_2)
        painter.setBrush(brush)
        painter.setPen(pen)
        painter.drawEllipse(-7, -7, 14, 14)
Esempio n. 20
0
    def to_draw_lines(self, painter):
        # 初始化, 使用实线
        pen = QPen(Qt.black, 2.0, Qt.SolidLine)
        painter.setPen(pen)
        painter.drawLine(20, 40, 250, 40)

        pen.setStyle(Qt.DashLine)
        painter.setPen(pen)
        painter.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        painter.setPen(pen)
        painter.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        painter.setPen(pen)
        painter.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        painter.setPen(pen)
        painter.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)
        painter.setPen(pen)
        painter.drawLine(20, 240, 250, 240)
Esempio n. 21
0
    def updateCircle(self, s):
        size = s * self.zoom
        pixmap = QPixmap(self.width(), self.height())
        pixmap.fill(Qt.transparent)
        #painter ellipse 1
        painter = QPainter()
        painter.begin(pixmap)
        painter.setRenderHint(QPainter.Antialiasing)
        pen = QPen(Qt.red)
        pen.setWidth(3)
        painter.setPen(pen)
        brush = QBrush(Qt.green)
        painter.setBrush(brush)
        painter.drawEllipse(
            QRect(
                old_div(self.width(), 2) - old_div(size, 2),
                old_div(self.height(), 2) - old_div(size, 2), size, size))
        painter.end()
        #painter ellipse 2
        painter2 = QPainter()
        painter2.begin(pixmap)
        painter2.setRenderHint(QPainter.Antialiasing)
        pen2 = QPen(Qt.green)
        pen2.setStyle(Qt.DotLine)
        pen2.setWidth(3)
        painter2.setPen(pen2)
        painter2.drawEllipse(
            QRect(
                old_div(self.width(), 2) - old_div(size, 2),
                old_div(self.height(), 2) - old_div(size, 2), size, size))
        painter2.end()

        self.ellipseLabel.setPixmap(QPixmap(pixmap))
        self.lastSize = s
Esempio n. 22
0
    def drawFundBlock(self, qp):
        pen = QPen(Qt.black, 2, Qt.SolidLine)
        pen.setStyle(Qt.DashLine)

        qp.setPen(pen)
        for i in range(1, 10):
            qp.drawLine(self.x0, i * self.y0, self.x1, self.y0 * i)
Esempio n. 23
0
    def pintar(self, qp: QPainter, seleccionada: bool):
        pen = QPen()
        pen.setStyle(self.tipo_linea)
        pen.setWidth(self.ancho_linea)
        pen.setColor(self.color_linea)

        brush = QBrush()
        brush.setColor(self.color_fondo)
        brush.setStyle(Qt.SolidPattern)

        qp.setPen(pen)
        qp.setBrush(brush)
        self._pintar(qp)

        if seleccionada:
            brush = QBrush()
            brush.setColor(Qt.green)
            brush.setStyel(Qt.SolidPattern)
            pen = QPen()
            pen.setWidth(1)
            pen.setColor(Qt.black)
            qp.setPen(pen)
            qp.setBrush(brush)
            qp.drawEllipse(self.punto_1.x() - 5, self.punto_1.y() - 5, 7, 7)
            qp.drawEllipse(self.punto_2.x() - 5, self.punto_2.y() - 5, 7, 7)
            qp.drawEllipse(self.punto_1.x() - 5, self.punto_2.y() - 5, 7, 7)
            qp.drawEllipse(self.punto_2.x() - 5, self.punto_1.y() - 5, 7, 7)
Esempio n. 24
0
 def paint(self, painter, option, widget=None):
     # init graphics
     pen = QPen(QColor(0, 0, 0))
     pen.setWidth(0)
     pen.setStyle(Qt.DashDotLine)
     redPen = QPen(QColor(255, 0, 0))
     redPen.setWidth(0)
     # current points
     points = self.__apply_offset(self.points, self.offset)
     if len(points) > 0:
         # draw
         painter.setPen(pen)
         painter.drawPolyline(QPolygonF(points))
         if PolygonBase.highlight_selection:
             brush = QBrush(QColor(0, 0, 0, 64))
             painter.fillRect(self.dots_rect, brush)
         if PolygonBase.close_polygon:
             painter.drawLine(points[-1], points[0])
     scale = painter.transform().m11()
     if PolygonBase.mark_points:
         if len(points) > 0:
             painter.drawEllipse(points[0], L_SIZE / scale, L_SIZE / scale)
         for point in points:
             painter.drawEllipse(point, S_SIZE / scale, S_SIZE / scale)
     if self.point_id >= 0:
         painter.setPen(redPen)
         if len(points) > 0:
             painter.drawEllipse(points[self.point_id], M_SIZE / scale, M_SIZE / scale)
Esempio n. 25
0
    def draw(self, painter, draw=True):
        if self.color is None:
            return

        if draw:
            painter.save()
            pen = QPen(QColor(self.color))
            if self.stroke is not None:
                pen.setWidthF(self.stroke)
            if self.line_style is not None:
                if self.line_style in [Qt.SolidLine, Qt.DashLine, Qt.DashDotLine, Qt.DotLine, Qt.DashDotDotLine]:
                    pen.setStyle(self.line_style)
                elif isinstance(self.line_style, list):
                    pen.setStyle(Qt.CustomDashLine)
                    pen.setDashPattern(self.line_style)
            painter.setPen(pen)
            painter.setOpacity(self.opacity)
            polyline_to_draw = self.translated(0, 0)
            if self.scale is not None and self.scale != 1:
                polyline_to_draw = self.__scaled()
            # print('mid rect_to_plot', rect_to_plot)
            if self.translation is not None:
                # rect_to_plot.setX(rect_to_plot.x()+self.translation.x())
                # rect_to_plot.setY(rect_to_plot.y()+self.translation.y())
                polyline_to_draw.translate(self.translation.x(), self.translation.y())
            # painter.drawPolygon(polygon_to_draw)
            if self.theta is not None and self.theta != 0:
                painter.translate(polyline_to_draw.boundingRect().center())
                painter.rotate(self.theta)
                painter.translate(-polyline_to_draw.boundingRect().center())

            painter.drawPolyline(polyline_to_draw)
            painter.restore()
Esempio n. 26
0
    def addTriangles(self):
        leftTriangle, rightTriangle = loadTriangles(self.leftPath, self.rightPath)
        pen = QPen()
        if len(self.tempLeft) == 0:
            pen.setColor(Qt.red)
        else:
            pen.setColor(Qt.cyan)
        pen.setStyle(Qt.SolidLine)
        for l_tri, r_tri in zip(leftTriangle, rightTriangle):
            l = np.divide(l_tri.vertices, 5)
            r = np.divide(r_tri.vertices, 5)

            self.leftlines.append(QGraphicsLineItem(l[0][0], l[0][1], l[1][0], l[1][1]))
            self.leftlines.append(QGraphicsLineItem(l[0][0], l[0][1], l[2][0], l[2][1]))
            self.leftlines.append(QGraphicsLineItem(l[2][0], l[2][1], l[1][0], l[1][1]))

            self.rightlines.append(QGraphicsLineItem(r[0][0], r[0][1], r[1][0], r[1][1]))
            self.rightlines.append(QGraphicsLineItem(r[0][0], r[0][1], r[2][0], r[2][1]))
            self.rightlines.append(QGraphicsLineItem(r[2][0], r[2][1], r[1][0], r[1][1]))

        for lline,rline in zip(self.leftlines, self.rightlines):
            lline.setPen(pen)
            rline.setPen(pen)
            self.leftScene.addItem(lline)
            self.rightScene.addItem(rline)
Esempio n. 27
0
    def drawLines(self, qp):
      
        pen = QPen(Qt.black, 2, Qt.SolidLine)

        qp.setPen(pen)
        qp.drawLine(20, 40, 250, 40)

        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 28
0
    def __init__(self, parent=None):
        super(ImageViewer, self).__init__(parent)
        self.setRenderHints(QPainter.Antialiasing
                            | QPainter.SmoothPixmapTransform)
        #self.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setDragMode(QGraphicsView.ScrollHandDrag)
        #self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        #self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self._scene = ImageViewerScene(self)
        self.setScene(self._scene)
        self._create_grid()
        self._create_grid_lines()
        self._pixmap = None
        self._selection_mode = SELECTION_MODE.NONE

        # polygon selection
        _polygon_guide_line_pen = QPen(QtGui.QColor(235, 72, 40))
        _polygon_guide_line_pen.setWidth(2)
        _polygon_guide_line_pen.setStyle(QtCore.Qt.DotLine)
        self._polygon_guide_line = QGraphicsLineItem()
        self._polygon_guide_line.setVisible(False)
        self._polygon_guide_line.setPen(_polygon_guide_line_pen)
        self._scene.addItem(self._polygon_guide_line)
        self._current_polygon = None
        # rectangle selection
        self._box_origin = QPoint()
        self._box_picker = QRubberBand(QRubberBand.Rectangle, self)

        # free selection
        self._current_free_path = None
        self._is_drawing = False
        self._last_point_drawn = QPoint()
        self._current_label = None
Esempio n. 29
0
    def drawLines(self, qp):

        # 新建一个QPen对象,设置颜色黑色,宽2像素,Qt.SolidLine是预定义样式的一种
        pen = QPen(Qt.black, 2, Qt.SolidLine)

        qp.setPen(pen)
        qp.drawLine(20, 40, 250, 40)

        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        # 自定义了一个笔的样式。
        # 定义为Qt.CustomDashLine然后调用setDashPattern()方法
        # 数字列表是线的样式,要求必须是个数为奇数,奇数位定义的是空格,偶数位为线长,
        # 数字越大,空格或线长越大,比如本例的就是1像素线,4像素空格,5像素线,4像素空格。
        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 30
0
    def drawLines(self, qp):
        # QPen(画笔),此处画了6条线段,其中前5条为预定义样式,最后一条为自定义样式
        pen = QPen(Qt.black, 2, Qt.SolidLine)

        qp.setPen(pen)
        qp.drawLine(20, 40, 250, 40)

        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)
        # 该方法,它的参数(一个数字列表)定义了一种风格,必须有偶数个数字;
        # 其中奇数表示绘制实线,偶数表示留空。数值越大,直线或空白就越大。
        # 这里我们定义了1像素的实线,4像素的空白,5像素实线,4像素空白
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 31
0
def _paintRegistrationMarks(printer, painter):
    page = printer.pageLayout().fullRectPoints()
    margin = printer.pageLayout().marginsPoints()

    # Get ourselves some nice abbreviations
    pw = page.width()
    ph = page.height()
    ml = margin.left()
    mr = margin.right()
    mt = margin.top()
    mb = margin.bottom()

    # A caution factor of 90% to keep our registration lines from
    # running into the main page area
    cf = 0.9

    pen = QPen()
    pen.setStyle(Qt.SolidLine)
    pen.setWidth(1)
    pen.setBrush(Qt.black)

    painter.save()
    painter.setPen(pen)
    painter.drawLine(0, mt, ml * cf, mt)
    painter.drawLine(ml, 0, ml, mt * cf)
    painter.drawLine(pw, mt, pw - mr * cf, mt)
    painter.drawLine(pw - mr, 0, pw - mr, mt * cf)
    painter.drawLine(0, ph - mb, ml * cf, ph - mb)
    painter.drawLine(ml, ph, ml, ph - mb * cf)
    painter.drawLine(pw, ph - mb, pw - mr * cf, ph - mb)
    painter.drawLine(pw - mr, ph, pw - mr, ph - mb * cf)
    painter.restore()
Esempio n. 32
0
    def drawLines(self, qp):
        pen = QPen(Qt.black, 2, Qt.SolidLine)

        qp.setPen(pen)
        qp.drawLine(20, 40, 250, 40)

        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(20, 80, 250, 80)

        pen.setStyle(Qt.DashDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 120, 250, 120)

        pen.setStyle(Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(20, 160, 250, 160)

        pen.setStyle(Qt.DashDotDotLine)
        qp.setPen(pen)
        qp.drawLine(20, 200, 250, 200)

        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 4, 5, 4])
        qp.setPen(pen)
        qp.drawLine(20, 240, 250, 240)
Esempio n. 33
0
 def paintEvent(self, event):
     _size = self.size() - QSize(2, 2)
     if (_size.isEmpty()):
         return
     origX = (_size.width() - self.mNewSize.width() * self.mScale) / 2 + 0.5
     origY = (_size.height() - self.mNewSize.height() * self.mScale) / 2 + 0.5
     oldRect = QRect(self.mOffset, self.mOldSize)
     painter = QPainter(self)
     painter.translate(origX, origY)
     painter.scale(self.mScale, self.mScale)
     pen = QPen(Qt.black)
     pen.setCosmetic(True)
     painter.setPen(pen)
     painter.drawRect(QRect(QPoint(0, 0), self.mNewSize))
     pen.setColor(Qt.white)
     painter.setPen(pen)
     painter.setBrush(Qt.white)
     painter.setOpacity(0.5)
     painter.drawRect(oldRect)
     pen.setColor(Qt.black)
     pen.setStyle(Qt.DashLine)
     painter.setOpacity(1.0)
     painter.setBrush(Qt.NoBrush)
     painter.setPen(pen)
     painter.drawRect(oldRect)
     painter.end()
Esempio n. 34
0
    def __init__(self, widget, pixmap=None):
        super().__init__(widget, pixmap=pixmap, crop_image=False)

        self.crop_left_px = None
        self.crop_right_px = None
        self.crop_top_px = None
        self.crop_bottom_px = None

        # used to create dummy rectangles
        TL = QPoint(0, 0)
        BR = QPoint(0, 0)

        # draw the rectangles in a see through black
        brush = QBrush(QColor(0, 0, 0, 50))

        # create pen that draws nothing, used for rectangles without border
        empty_pen = QPen(QColor(0, 0, 0, 255))
        empty_pen.setStyle(0)

        # these two together create a white/black dotted line
        full_pen = QPen(QColor(255, 255, 255))
        dot_pen = QPen(QColor(0, 0, 0))
        dot_pen.setStyle(3)

        self.graphics_crop_rect_bottom = self.graphics.addRect(QRectF(TL, BR),
                                                               brush=brush,
                                                               pen=empty_pen)
        self.graphics_crop_rect_top = self.graphics.addRect(QRectF(TL, BR),
                                                            brush=brush,
                                                            pen=empty_pen)
        self.graphics_crop_rect_left = self.graphics.addRect(QRectF(TL, BR),
                                                             brush=brush,
                                                             pen=empty_pen)
        self.graphics_crop_rect_right = self.graphics.addRect(QRectF(TL, BR),
                                                              brush=brush,
                                                              pen=empty_pen)

        # the full line with the crop line simulates a white/black dotted line
        self.graphics_crop_line_full_bottom = self.graphics.addLine(
            QLineF(TL, BR), pen=full_pen)
        self.graphics_crop_line_full_top = self.graphics.addLine(QLineF(
            TL, BR),
                                                                 pen=full_pen)
        self.graphics_crop_line_full_left = self.graphics.addLine(QLineF(
            TL, BR),
                                                                  pen=full_pen)
        self.graphics_crop_line_full_right = self.graphics.addLine(
            QLineF(TL, BR), pen=full_pen)

        self.graphics_crop_line_dot_bottom = self.graphics.addLine(QLineF(
            TL, BR),
                                                                   pen=dot_pen)
        self.graphics_crop_line_dot_top = self.graphics.addLine(QLineF(TL, BR),
                                                                pen=dot_pen)
        self.graphics_crop_line_dot_left = self.graphics.addLine(QLineF(
            TL, BR),
                                                                 pen=dot_pen)
        self.graphics_crop_line_dot_right = self.graphics.addLine(QLineF(
            TL, BR),
                                                                  pen=dot_pen)
class ResizeableRectItemSettings(object):
    """
    Settings for a ResizeableRectItem
    """
    def __init__(self,
                 bordersize=15,
                 color=QColor("red"),
                 minimumSize=QSizeF(8.0, 8.0),
                 maximumSize=QSizeF(1000000, 1000000)):

        self.minimumSize = minimumSize
        self.maximumSize = maximumSize
        # width the rect shall use for allowing resize interactions
        self.resizeableBorderSize = bordersize

        self.color = color
        self.pen = QPen(self.color)
        self.pen.setStyle(Qt.DashLine)

        self.color.setAlpha(255/3)
        self.brush = QBrush(self.color)

    def validateRect(self, r: QRectF, resizeDirections):

        left = r.left()
        top = r.top()
        right = left + r.width()
        bottom = top + r.height()

        # The qBound() is used for enforcement of the minimum and maximum sizes.
        # It's derived after solving the following inequalities (example is for
        # left-resizing):

        # minWidth <= newWidth <= maxWidth
        # minWidth <= right-newLeft <= maxWidth
        # minWidth-right <= -newLeft <= maxWidth-right
        # right-minWidth >= newLeft >= right-maxWidth

        # Ditto for the other 3 directions.
        def qBound(minVal, current, maxVal):
            return max(min(current, maxVal), minVal)

        if resizeDirections.horizontal == ResizeDirectionHorizontal.Left:
            left = qBound(right - self.maximumSize.width(), left, right - self.minimumSize.width())
        elif resizeDirections.horizontal == ResizeDirectionHorizontal.Right:
            right = qBound(self.minimumSize.width() + left, right, self.maximumSize.width() + left)

        if resizeDirections.vertical == ResizeDirectionVertical.Top:
            top = qBound(bottom - self.maximumSize.height(), top, bottom - self.minimumSize.height())
        elif resizeDirections.vertical == ResizeDirectionVertical.Bottom:
            bottom = qBound(self.minimumSize.height() + top, bottom, self.maximumSize.height() + top)

        return QRectF(left, top, right - left, bottom - top)
Esempio n. 36
0
 def paintEvent(self, ev):
     pen = QPen()
     pen.setStyle(Qt.DotLine)
     pen.setWidth(2)
     pen.setColor(QColor(Qt.white))
     brush = QBrush()
     brush.setStyle(Qt.SolidPattern)
     brush.setColor(QColor(0, 0, 0))
     painter = QPainter(self)
     painter.setPen(pen)
     painter.setBrush(brush)
     painter.drawRect(ev.rect())
 def create_distance_pointer(self):
     self.distance_pointer = QGraphicsLineItem()
     pen = QPen()
     pen.setWidthF(1.0)
     pen.setStyle(Qt.DashDotLine)
     color = Color.create_qcolor_from_rgb_tuple_f((1,0,0))
     pen.setColor(color)
     self.distance_pointer.setPen(pen)
     self.distance_pointer.setZValue(1.0)
     self.addToGroup(self.distance_pointer)
     self.distance_label = QGraphicsSimpleTextItem()
     self.distance_label.setZValue(1.0)
     self.addToGroup(self.distance_label)
Esempio n. 38
0
 def __init__(self, size, scene: QGraphicsScene):
     self.rectItems = []
     self.pixmap = QPixmap(QSize(820,820))
     self.painter = QPainter(self.pixmap)
     self.scene = scene
     self.owners = None
     self.values = None
     pen = QPen()
     pen.setStyle(Qt.NoPen)
     for index in range(size**2):
         item = QGraphicsRectItem()
         item.setRect(int(index/size), int(index%size), 0.9, 0.9)
         item.setPen(pen)
         scene.addItem(item)
         self.rectItems.append(item)
Esempio n. 39
0
    def drawLine(self, event, qp):
        pen = QPen()
        pen.setWidth(3)
        pen.setColor(QColor(128, 250, 25, 255))
        pen.setStyle(Qt.DotLine)

        qp.setPen(pen)
        qp.drawLine(QPoint(10, 10), QPoint(1280 - 10, 10))

        color = QColor()
        color.setNamedColor('#c2h6b4')

        pen.setColor(color)
        pen.setStyle(Qt.DashLine)

        qp.setPen(pen)
        qp.drawLine(QPoint(10, 10 + 20), QPoint(1280 - 10, 10 + 20))
Esempio n. 40
0
def getPenObj(hex_string: str,
            stroke_width: int,
            alpha: int = None,
            lighter: int=None,
            penstyle: Qt.PenStyle = None,
            capstyle: Qt.PenCapStyle = None,
            joinstyle: Qt.PenJoinStyle = None) -> QPen:
    """If the specified :class:`QPen` is cached, return it.
    Otherwise, cache and return a new :class:`QPen`.

    Args:
        hex_string (str): hexadecimal color code in the form: #RRGGBB
        stroke_width (int)
        alpha (int): 0–255
        lighter (int): see `QColor.lighter <http://doc.qt.io/qt-5/qcolor.html#lighter>`_.
        penstyle: see `QPen.pen-style <http://doc.qt.io/qt-5/qt.html#PenStyle-enum>`_.
        capstyle: see `QPen.cap-style <http://doc.qt.io/qt-5/qt.html#PenCapStyle-enum>`_.
        joinstyle: see `QPen.join-style <http://doc.qt.io/qt-5/qt.html#PenJoinStyle-enum>`_.

    Returns:
        :class:`QPen` object
    """
    global pen_cache
    if alpha is not None:
        hex_string = '#%0.2x%s' % (alpha, hex_string[1:])
    # print(hex_string)
    key = (hex_string, stroke_width, lighter, capstyle, joinstyle, penstyle)
    pen = pen_cache.get(key)
    if pen is None:
        color = getColorObj(hex_string, lighter=lighter)
        pen = QPen(color, stroke_width)
        if penstyle is not None:
            pen.setStyle(penstyle)
        if capstyle is not None:
            pen.setCapStyle(capstyle)
        if joinstyle is not None:
            pen.setJoinStyle(joinstyle)
        pen_cache[key] = pen
    return pen
 def add_surface_element(self):
     element_wrapper_dict = self.parent.element_name_dict
     element_item_dict = self.parent.element_list_item_dict
     x_init = self.graph_zero[0] + self.line_extend
     y_init = self.graph_zero[1]
     y_unit_distance = self.surface_analysis.sampling_distance * self.height_multiplier
     x_unit_distance = self.surface_analysis.section_distance * self.length_multiplier
     for i in range(len(self.surface)):
         for j in range(len(self.surface[i])):
             point_object = self.surface[i][j]
             if point_object:
                 #element_name = point_object.element.name
                 element = get_parent_element(point_object.element)
                 element_name = element.name
                 element_wrapper = element_wrapper_dict.get(element_name)
                 material = point_object.material
                 self.material_legend.add_to_dict(material)
                 scene_x = point_object.point.Y() * self.length_multiplier + x_init - x_unit_distance/2
                 scene_y = point_object.point.X() * self.height_multiplier + y_init - y_unit_distance/2
                 rect = ElementRect(scene_x, scene_y, x_unit_distance, y_unit_distance)
                 rect.set_element_name(element_name)
                 rect.set_element_dict(element_wrapper_dict, element_item_dict)
                 pen = QPen()
                 pen.setStyle(Qt.NoPen)
                 rect.setPen(pen)
                 surface_color = material.get_surface_colour()
                 transparency = material.get_transparency()
                 reflectance = material.get_reflectance()
                 reflectance_method = material.get_reflectance_method()
                 slip_coefficient = material.get_slip_coefficient()
                 imperviousness = material.get_imperviousness()
                 self.rect_list.append((rect, surface_color, transparency, reflectance,reflectance_method, slip_coefficient, imperviousness))
                 self.set_rect_fill(self.visualization_mode, rect, surface_color)
                 rect.setZValue(-1.0)
                 if element_wrapper:
                     element_wrapper.add_graphic_item(rect, material)
                     element_wrapper.is_analyzed = True
                 self.addToGroup(rect)
 def add_height_clearance_graph(self):
     vertical_clearance = self.clearance_analysis.vertical_clearance
     x_init = self.graph_zero[0] + self.line_extend
     y_init = self.graph_zero[1]
     y_unit_distance = self.clearance_analysis.sampling_distance * self.height_multiplier
     x_unit_distance = self.clearance_analysis.section_distance * self.length_multiplier
     for i in range(len(vertical_clearance)):
         for j in range(len(vertical_clearance[i])):
             vertical_distance = vertical_clearance[i][j]
             if vertical_distance:
                 vertical_distance_value = vertical_distance[0]
                 scene_x = (vertical_distance[1].point.Y() * self.length_multiplier + x_init) - x_unit_distance/2
                 scene_y = (vertical_distance[1].point.X() * self.height_multiplier + y_init) - y_unit_distance/2
                 rect = QGraphicsRectItem(scene_x, scene_y, x_unit_distance, y_unit_distance)
                 color = self.color_interpolation.get_interpolation_from_value(vertical_distance_value)
                 pen = QPen()
                 pen.setStyle(Qt.NoPen)
                 brush = QBrush(color)
                 rect.setPen(pen)
                 rect.setBrush(brush)
                 rect.setZValue(-1.0)
                 self.addToGroup(rect)
                 pass
Esempio n. 43
0
    w.xAxis.setAutoTicks(False)
    w.xAxis.setAutoTickLabels(False)
    w.xAxis.setTickVector(ticks)
    w.xAxis.setTickVectorLabels(labels)
    w.xAxis.setTickLabelRotation(60)
    w.xAxis.setSubTickCount(0)
    w.xAxis.grid().setVisible(True)
    w.xAxis.setRange(0, 8)

    w.yAxis.setRange(0, 12.1)
    w.yAxis.setPadding(5)
    w.yAxis.setLabel('Power Consumption in\nKilowatts per Capita (2007)')
    w.yAxis.grid().setSubGridVisible(True)

    grid_pen = QPen()
    grid_pen.setStyle(Qt.SolidLine)
    grid_pen.setColor(QColor(0, 0, 0, 25))
    w.yAxis.grid().setSubGridPen(grid_pen)

    fossil_data = [0.86 * 10.5, 0.83 * 5.5, 0.84 * 5.5, 0.52 * 5.8, 0.89 * 5.2, 0.90 * 4.2, 0.67 * 11.2]
    nuclear_data = [0.08 * 10.5, 0.12 * 5.5, 0.12 * 5.5, 0.40 * 5.8, 0.09 * 5.2, 0.00 * 4.2, 0.07 * 11.2]
    regen_data = [0.06 * 10.5, 0.05 * 5.5, 0.04 * 5.5, 0.06 * 5.8, 0.02 * 5.2, 0.07 * 4.2, 0.25 * 11.2]
    fossil.setData(ticks, fossil_data)
    nuclear.setData(ticks, nuclear_data)
    regen.setData(ticks, regen_data)

    w.legend.setVisible(True)
    w.axisRect().insetLayout().setInsetAlignment(0, Qt.AlignTop|Qt.AlignHCenter)
    w.legend.setBrush(QColor(255, 255, 255, 200))
    legendPen = QPen()
    legendPen.setColor(QColor(130, 130, 130, 200))
Esempio n. 44
0
    def drawMapObject(self, painter, object, color):
        painter.save()
        pen = QPen(Qt.black)
        pen.setCosmetic(True)
        cell = object.cell()
        if (not cell.isEmpty()):
            tile = cell.tile
            imgSize = tile.size()
            pos = self.pixelToScreenCoords_(object.position())
            tileOffset = tile.offset()
            CellRenderer(painter).render(cell, pos, object.size(), CellRenderer.BottomCenter)
            if (self.testFlag(RenderFlag.ShowTileObjectOutlines)):
                rect = QRectF(QPointF(pos.x() - imgSize.width() / 2 + tileOffset.x(),
                                    pos.y() - imgSize.height() + tileOffset.y()),
                            QSizeF(imgSize))
                pen.setStyle(Qt.SolidLine)
                painter.setPen(pen)
                painter.drawRect(rect)
                pen.setStyle(Qt.DotLine)
                pen.setColor(color)
                painter.setPen(pen)
                painter.drawRect(rect)
        else:
            lineWidth = self.objectLineWidth()
            scale = self.painterScale()
            x = 1
            if lineWidth != 0:
                x = lineWidth
            shadowOffset = x / scale
            brushColor = QColor(color)
            brushColor.setAlpha(50)
            brush = QBrush(brushColor)
            pen.setJoinStyle(Qt.RoundJoin)
            pen.setCapStyle(Qt.RoundCap)
            pen.setWidth(lineWidth)
            
            colorPen = QPen(pen)
            colorPen.setColor(color)
        
            painter.setPen(pen)
            painter.setRenderHint(QPainter.Antialiasing)
            # TODO: Do something sensible to make null-sized objects usable
            x = object.shape()
            if x==MapObject.Ellipse:
                polygon = self.pixelRectToScreenPolygon(object.bounds())
                tw = self.map().tileWidth()
                th = self.map().tileHeight()
                transformScale = QPointF(1, 1)
                if (tw > th):
                    transformScale = QPointF(1, th/tw)
                else:
                    transformScale = QPointF(tw/th, 1)
                l1 = polygon.at(1) - polygon.at(0)
                l2 = polygon.at(3) - polygon.at(0)
                trans = QTransform()
                trans.scale(transformScale.x(), transformScale.y())
                trans.rotate(45)
                iTrans, ok = trans.inverted()
                l1x = iTrans.map(l1)
                l2x = iTrans.map(l2)
                ellipseSize = QSizeF(l1x.manhattanLength(), l2x.manhattanLength())
                if (ellipseSize.width() > 0 and ellipseSize.height() > 0):
                    painter.save()
                    painter.setPen(pen)
                    painter.translate(polygon.at(0))
                    painter.scale(transformScale.x(), transformScale.y())
                    painter.rotate(45)
                    painter.drawEllipse(QRectF(QPointF(0, 0), ellipseSize))
                    painter.restore()

                painter.setBrush(Qt.NoBrush)
                painter.drawPolygon(polygon)
                
                painter.setPen(colorPen)
                painter.setBrush(Qt.NoBrush)
                painter.translate(QPointF(0, -shadowOffset))
                painter.drawPolygon(polygon)
                painter.setBrush(brush)
                if (ellipseSize.width() > 0 and ellipseSize.height() > 0):
                    painter.save()
                    painter.translate(polygon.at(0))
                    painter.scale(transformScale.x(), transformScale.y())
                    painter.rotate(45)
                    painter.drawEllipse(QRectF(QPointF(0, 0), ellipseSize))
                    painter.restore()
            elif x==MapObject.Rectangle:
                polygon = self.pixelRectToScreenPolygon(object.bounds())
                painter.drawPolygon(polygon)
                painter.setPen(colorPen)
                painter.setBrush(brush)
                polygon.translate(0, -shadowOffset)
                painter.drawPolygon(polygon)
            elif x==MapObject.Polygon:
                pos = object.position()
                polygon = object.polygon().translated(pos)
                screenPolygon = self.pixelToScreenCoords_(polygon)
                thickPen = QPen(pen)
                thickColorPen = QPen(colorPen)
                thickPen.setWidthF(thickPen.widthF() * 4)
                thickColorPen.setWidthF(thickColorPen.widthF() * 4)
            
                painter.drawPolygon(screenPolygon)
                
                painter.setPen(thickPen)
                painter.drawPoint(screenPolygon.first())

                painter.setPen(colorPen)
                painter.setBrush(brush)
                screenPolygon.translate(0, -shadowOffset)
                painter.drawPolygon(screenPolygon)
                painter.setPen(thickColorPen)
                painter.drawPoint(screenPolygon.first())
                
            elif x==MapObject.Polyline:
                pos = object.position()
                polygon = object.polygon().translated(pos)
                screenPolygon = self.pixelToScreenCoords_(polygon)
                thickPen = QPen(pen)
                thickColorPen = QPen(colorPen)
                thickPen.setWidthF(thickPen.widthF() * 4)
                thickColorPen.setWidthF(thickColorPen.widthF() * 4)
                
                painter.drawPolyline(screenPolygon)
                painter.setPen(thickPen)
                painter.drawPoint(screenPolygon.first())
                
                painter.setPen(colorPen)
                screenPolygon.translate(0, -shadowOffset)
                painter.drawPolyline(screenPolygon)
                
                painter.setPen(thickColorPen)
                painter.drawPoint(screenPolygon.first())

        painter.restore()
Esempio n. 45
0
from PyQt5.QtWidgets import (QFormLayout,
                             QGraphicsItem,
                             QGraphicsRectItem,
                             QGraphicsScene,
                             QGraphicsView,
                             QGroupBox,
                             QVBoxLayout,
                             )

from .settings import Config, FormInt
from .utils import convert_name_to_color, LINE_WIDTH

lg = getLogger(__name__)

NoPen = QPen()
NoPen.setStyle(Qt.NoPen)

NoBrush = QBrush()
NoBrush.setStyle(Qt.NoBrush)

STAGES = {'Wake': {'pos0': 5, 'pos1': 25, 'color': Qt.black},
          'Movement': {'pos0': 5, 'pos1': 25, 'color': Qt.darkGray},
          'REM': {'pos0': 10, 'pos1': 20, 'color': Qt.magenta},
          'NREM1': {'pos0': 15, 'pos1': 15, 'color': Qt.cyan},
          'NREM2': {'pos0': 20, 'pos1': 10, 'color': Qt.blue},
          'NREM3': {'pos0': 25, 'pos1': 5, 'color': Qt.darkBlue},
          'Undefined': {'pos0': 0, 'pos1': 30, 'color': Qt.gray},
          'Unknown': {'pos0': 30, 'pos1': 0, 'color': NoBrush},
          }

BARS = {'markers': {'pos0': 15, 'pos1': 10, 'tip': 'Markers in Dataset'},
Esempio n. 46
0
    def _drawTransition(self, qp, xpos, width, ttype, hoverLeft, hoverRight):

        # Set pen and brush style
        color = SignalLogWidget.SIGNAL_COLOR
        brush = QBrush(color)
        qp.setBrush(brush)
        pen = QPen()
        pen.setStyle(Qt.NoPen)
        qp.setPen(pen)

        size = self.size()
        h = size.height()

        if ttype == 'sameData':
            if hoverLeft:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            qp.drawRect(xpos, 2, width / 2, h - 4)

            if hoverRight:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            qp.drawRect(xpos + width / 2, 2, width / 2, h - 4)

        elif ttype == 'dataChange':
            if hoverLeft:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            points = [QPoint(xpos, 2), QPoint(xpos, h - 2),
                      QPoint(xpos + width / 2, h / 2)]
            qp.drawPolygon(QPolygon(points))

            if hoverRight:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            points = [QPoint(xpos + width, 2), QPoint(xpos + width, h - 2),
                      QPoint(xpos + width / 2, h / 2)]
            qp.drawPolygon(QPolygon(points))

        elif ttype == 'empty2data':
            if hoverRight:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            points = [QPoint(xpos + width / 2, h / 2),
                      QPoint(xpos + width, 2), QPoint(xpos + width, h - 2)]
            qp.setBrush(brush)
            qp.drawPolygon(QPolygon(points))

            if hoverLeft:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            qp.drawRect(xpos, h / 2 - 1, width / 2 + 1, 2)

        elif ttype == 'data2empty':
            if hoverLeft:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            points = [QPoint(xpos, 2), QPoint(xpos, h - 2), QPoint(xpos + width / 2, h / 2)]
            qp.setBrush(brush)
            qp.drawPolygon(QPolygon(points))

            if hoverRight:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else:
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            qp.drawRect(xpos + width / 2 - 1, h / 2 - 1, width / 2, 2)
        else:
            # 'empty2empty' case
            if hoverLeft:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else: 
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            qp.drawRect(xpos, h / 2 - 1, width / 2 + 1, 2)

            if hoverRight:
                brush.setColor(self.SIGNAL_COLOR_HOVER)
            else: 
                brush.setColor(self.SIGNAL_COLOR)
            qp.setBrush(brush)
            qp.drawRect(xpos + width / 2 - 1, h / 2 - 1, width / 2, 2)
Esempio n. 47
0
    def drawMapObject(self, painter, object, color):
        painter.save()
        bounds = object.bounds()
        rect = QRectF(bounds)
        painter.translate(rect.topLeft())
        rect.moveTopLeft(QPointF(0, 0))
        cell = object.cell()
        if (not cell.isEmpty()):
            CellRenderer(painter).render(cell, QPointF(), object.size(), CellRenderer.BottomLeft)
            if (self.testFlag(RenderFlag.ShowTileObjectOutlines)):
                tile = cell.tile
                imgSize = tile.size()
                tileOffset = tile.offset()
                rect = QRectF(QPointF(tileOffset.x(), tileOffset.y() - imgSize.height()), QSizeF(imgSize))
                pen = QPen(Qt.SolidLine)
                pen.setCosmetic(True)
                painter.setPen(pen)
                painter.drawRect(rect)
                pen.setStyle(Qt.DotLine)
                pen.setColor(color)
                painter.setPen(pen)
                painter.drawRect(rect)
        else:
            lineWidth = self.objectLineWidth()
            scale = self.painterScale()
            if lineWidth == 0:
                x = 1
            else:
                x = lineWidth
            shadowDist = x / scale
            shadowOffset = QPointF(shadowDist * 0.5, shadowDist * 0.5)
            linePen = QPen(color, lineWidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
            #linePen.setCosmetic(True)
            shadowPen = QPen(linePen)
            shadowPen.setColor(Qt.black)
            brushColor = QColor(color)
            fillBrush = QBrush(brushColor)
            painter.setRenderHint(QPainter.Antialiasing)
            # Trying to draw an ellipse with 0-width is causing a hang in
            # CoreGraphics when drawing the path requested by the
            # QCoreGraphicsPaintEngine. Draw them as rectangle instead.
            shape = object.shape()
            if (shape == MapObject.Ellipse and ((rect.width() == 0.0) ^ (rect.height() == 0.0))):
                shape = MapObject.Rectangle
            x = shape
            if x==MapObject.Rectangle:
                if (rect.isNull()):
                    rect = QRectF(QPointF(-10, -10), QSizeF(20, 20))
                # Draw the shadow
                painter.setPen(shadowPen)
                painter.drawRect(rect.translated(shadowOffset))
                painter.setPen(linePen)
                painter.setBrush(fillBrush)
                painter.drawRect(rect)
            elif x==MapObject.Polyline:
                screenPolygon = self.pixelToScreenCoords_(object.polygon())
                thickShadowPen = QPen(shadowPen)
                thickLinePen = QPen(linePen)
                thickShadowPen.setWidthF(thickShadowPen.widthF() * 4)
                thickLinePen.setWidthF(thickLinePen.widthF() * 4)
            
                painter.setPen(shadowPen)
                painter.drawPolyline(screenPolygon.translated(shadowOffset))
                painter.setPen(thickShadowPen)
                painter.drawPoint(screenPolygon.first() + shadowOffset)
            
                painter.setPen(linePen)
                painter.setBrush(fillBrush)
                painter.drawPolyline(screenPolygon)
                painter.setPen(thickLinePen)
                painter.drawPoint(screenPolygon.first())
            
            elif x==MapObject.Polygon:
                screenPolygon = self.pixelToScreenCoords_(object.polygon())
                thickShadowPen = QPen(shadowPen)
                thickLinePen = QPen(linePen)
                thickShadowPen.setWidthF(thickShadowPen.widthF() * 4)
                thickLinePen.setWidthF(thickLinePen.widthF() * 4)
                
                painter.setPen(shadowPen)
                painter.drawPolygon(screenPolygon.translated(shadowOffset))
                painter.setPen(thickShadowPen)
                painter.drawPoint(screenPolygon.first() + shadowOffset)
                
                painter.setPen(linePen)
                painter.setBrush(fillBrush)
                painter.drawPolygon(screenPolygon)
                
                painter.setPen(thickLinePen)
                painter.drawPoint(screenPolygon.first())
                
            elif x==MapObject.Ellipse:
                if (rect.isNull()):
                    rect = QRectF(QPointF(-10, -10), QSizeF(20, 20))
                # Draw the shadow
                painter.setPen(shadowPen)
                painter.drawEllipse(rect.translated(shadowOffset))
                painter.setPen(linePen)
                painter.setBrush(fillBrush)
                painter.drawEllipse(rect)

        painter.restore()