Пример #1
0
 def slot_fill_combobox(self):
     if self.currentPalette is None:
         pass
     palette = self.currentPalette
     self.colorComboBox.clear()
     self.colorList = list()
     for i in range(palette.colorsCountTotal()):
         entry = palette.colorSetEntryByIndex(i)
         color = palette.colorForEntry(entry).colorForCanvas(self.canvas())
         colorSquare = QPixmap(12, 12)
         if entry.spotColor() is True:
             img = colorSquare.toImage()
             circlePainter = QPainter()
             img.fill(self.colorComboBox.palette().color(QPalette.Base))
             circlePainter.begin(img)
             brush = QBrush(Qt.SolidPattern)
             brush.setColor(color)
             circlePainter.setBrush(brush)
             circlePainter.pen().setWidth(0)
             circlePainter.drawEllipse(0, 0, 11, 11)
             circlePainter.end()
             colorSquare = QPixmap.fromImage(img)
         else:
             colorSquare.fill(color)
         name = entry.name()
         if len(entry.id()) > 0:
             name = entry.id() + " - " + entry.name()
         self.colorList.append(name)
         self.colorComboBox.addItem(QIcon(colorSquare), name)
     self.colorComboBox.setEditable(True)
     self.colorComboBox.setInsertPolicy(QComboBox.NoInsert)
     self.colorComboBox.completer().setCompletionMode(
         QCompleter.PopupCompletion)
     self.colorComboBox.completer().setCaseSensitivity(False)
     self.colorComboBox.completer().setFilterMode(Qt.MatchContains)
Пример #2
0
    def paintEvent(self, event):
        dst = self.imgRect()
        qp = QPainter()
        qp.begin(self)

        # draw background
        brush = QBrush(Qt.SolidPattern)
        # brush.setColor(Qt.white)
        brush.setColor(Qt.black)
        qp.setBrush(brush)
        qp.drawRect(dst)
        # brush = QBrush(Qt.DiagCrossPattern)
        # brush.setColor(Qt.black)
        # qp.setBrush(brush)
        # qp.drawRect(dst)

        self.state.paintImage(qp, dst)

        # draw orientation lines
        qp.setPen(QColor(255,255,255,150))
        qp.drawLine(dst.x()+dst.width()/3,dst.y()+0,
            dst.x()+dst.width()/3,dst.y()+dst.height())
        qp.drawLine(dst.x()+dst.width()/2,dst.y()+0,
            dst.x()+dst.width()/2,dst.y()+dst.height())
        qp.drawLine(dst.x()+dst.width()*2/3,dst.y()+0,
            dst.x()+dst.width()*2/3,dst.y()+dst.height())
        qp.drawLine(dst.x()+0,dst.y()+dst.height()/3,
            dst.x()+dst.width(),dst.y()+dst.height()/3)
        qp.drawLine(dst.x()+0,dst.y()+dst.height()/2,
            dst.x()+dst.width(),dst.y()+dst.height()/2)
        qp.drawLine(dst.x()+0,dst.y()+dst.height()*2/3,
            dst.x()+dst.width(),dst.y()+dst.height()*2/3)

        qp.end()
Пример #3
0
Файл: ui.py Проект: xmye/games
        def paintEvent(self, paintEvent: QPaintEvent):
            painter = QPainter(self)
            painter.setBackgroundMode(Qt.TransparentMode)
            painter.setRenderHint(QPainter.Antialiasing)
            brush = QBrush()
            brush.setStyle(Qt.SolidPattern)
            pen = QPen()
            pen.setJoinStyle(Qt.RoundJoin)
            pen.setCapStyle(Qt.RoundCap)

            center = QPoint(self.width() // 2, self.height() // 2)
            radius = 0.45 * min(self.width(), self.height())

            pen.setColor(self.palette().color(self.color[0]))
            brush.setColor(self.palette().color(self.color[1]))
            if self.highlight is True:
                pen.setColor(self.palette().color(QPalette.Highlight))
            pen.setWidth(round(0.15 * radius))
            painter.setBrush(brush)
            painter.setPen(pen)
            painter.drawEllipse(center, radius, radius)

            if self.checked is True:
                brush.setColor(self.palette().color(QPalette.Background))
                pen.setColor(self.palette().color(QPalette.Background))
                painter.setPen(pen)
                painter.setBrush(brush)
                painter.drawEllipse(center, 0.40 * radius, 0.40 * radius)
            del painter, brush, pen
Пример #4
0
 def fillOpacityModel(self):
     self.brushOpacityModel.clear()
     self.brushFlowModel.clear()
     for s in range(len(self.opacityList)):
         # we're gonna itterate over our list, and make a new item for each entry.
         item = QStandardItem()
         item.setCheckable(False)
         item.setEditable(False)
         item.setDragEnabled(False)
         item.setText(str(self.opacityList[s]) + " %")
         brushImage = QPixmap(64, 64)
         img = QImage(64, 64, QImage.Format_RGBA8888)
         circlePainter = QPainter()
         img.fill(Qt.transparent)
         circlePainter.begin(img)
         brush = QBrush(Qt.SolidPattern)
         brush.setColor(self.brushSizeTableView.palette().color(
             QPalette.Text))
         circlePainter.setBrush(brush)
         circlePainter.setPen(QPen(QBrush(Qt.transparent), 0))
         circlePainter.setOpacity(float(self.opacityList[s]) / 100.0)
         circlePainter.drawEllipse(QPointF(32, 32), 32, 32)
         circlePainter.end()
         brushImage = QPixmap.fromImage(img)
         item.setIcon(QIcon(brushImage))
         # the flow and opacity models will use virtually the same items, but Qt would like us to make sure we understand
         # these are not really the same items, so hence the clone.
         itemFlow = item.clone()
         self.brushOpacityModel.appendRow(item)
         self.brushFlowModel.appendRow(itemFlow)
     self.brushOpacityTableView.setModel(self.brushOpacityModel)
     self.brushFlowTableView.setModel(self.brushFlowModel)
Пример #5
0
    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)

        size = self.size()
        brush = QBrush()
        brush.setColor(self.background_color)
        brush.setStyle(Qt.SolidPattern)
        rect = QtCore.QRect(2, 2, size.width() - 4, size.height() - 4)
        painter.fillRect(rect, brush)

        self.numberFont.setPixelSize(0.9 * size.height())
        painter.setFont(self.numberFont)
        painter.setPen(self.fontColor)
        rect = event.rect()

        if len(self.thousands_separator) > 0:
            if self.thousands_separator != ".":
                textstr = format(self.getFrequency(), self.thousands_separator)
            else:
                textstr = format(self.getFrequency(), ",")
                textstr = textstr.replace(",", ".")
        else:
            textstr = str(self.getFrequency())

        rect = QtCore.QRect(0, 0, size.width() - 4, size.height())

        painter.drawText(rect, Qt.AlignRight + Qt.AlignVCenter, textstr)
Пример #6
0
    def draw(self, painter: QPainter):
        painter.save()

        brush = QBrush(Qt.SolidPattern)
        pen = QPen()
        brush.setColor(self.color)
        pen.setColor(self.color)
        painter.setBrush(brush)
        painter.setPen(pen)

        painter.drawEllipse(self.origin, self.base_radius, self.base_radius)

        painter.drawPolygon(
            QPoint(
                self.origin.x() +
                self.base_radius * cos(radians(self.angle - 90)),
                self.origin.y() +
                self.base_radius * sin(radians(self.angle - 90))),
            QPoint(
                self.origin.x() +
                self.base_radius * cos(radians(self.angle + 90)),
                self.origin.y() +
                self.base_radius * sin(radians(self.angle + 90))),
            QPoint(
                self.origin.x() +
                self.needle_length * cos(radians(self.angle)),
                self.origin.y() +
                self.needle_length * sin(radians(self.angle))))

        painter.restore()
Пример #7
0
    def draw(self, painter: QPainter):
        painter.save()

        brush = QBrush()
        pen = QPen()
        brush.setColor(self.fillColor)
        brush.setStyle(Qt.SolidPattern)
        pen.setColor(self.lineColor)
        painter.setBrush(brush)
        painter.setPen(pen)

        # Delta values
        delta_x = (self.width / 2) * cos(radians(self.angle - 90))
        delta_y = (self.width / 2) * sin(radians(self.angle - 90))

        # Building up the polygon
        bottom_x = self.radius_one * cos(radians(self.angle)) + self.origin.x()
        bottom_y = self.radius_one * sin(radians(self.angle)) + self.origin.y()
        top_x = self.radius_two * cos(radians(self.angle)) + self.origin.x()
        top_y = self.radius_two * sin(radians(self.angle)) + self.origin.y()

        painter.drawPolygon(QPoint(bottom_x - delta_x, bottom_y - delta_y),
                            QPoint(bottom_x + delta_x, bottom_y + delta_y),
                            QPoint(top_x + delta_x, top_y + delta_y),
                            QPoint(top_x - delta_x, top_y - delta_y))

        painter.restore()
Пример #8
0
 def drawCircle(self, painter, centerX, centerY, color, size):
     pen = QPen(color, size)
     painter.setPen(pen)
     brush = QBrush(Qt.SolidPattern)
     brush.setColor(QColor(Qt.blue))
     painter.setBrush(brush)
     painter.drawEllipse(centerX, centerY, 5, 5)
Пример #9
0
    def paint(self, QPainter, QStyleOptionGraphicsItem, QWidget_widget=None):

        # setPen
        pen = QPen()
        pen.setWidth(2)
        pen.setJoinStyle(Qt.MiterJoin)
        QPainter.setPen(pen)

        # setBrush
        brush = QBrush()
        brush.setColor(Qt.black)
        brush.setStyle(Qt.SolidPattern)
        QPainter.setBrush(brush)

        v = self.line.unitVector()
        v.setLength(10)
        v.translate(QPointF(self.line.dx(), self.line.dy()))

        n = v.normalVector()
        n.setLength(n.length() * 0.5)
        n2 = n.normalVector().normalVector()

        p1 = v.p2()
        p2 = n.p2()
        p3 = n2.p2()

        QPainter.drawLine(self.line)
        QPainter.drawPolygon(p1, p2, p3)
Пример #10
0
    def __init__(self, data):
        super(QGraphicsObject, self).__init__()
        self.stateData = data
        self.setAcceptHoverEvents(True)
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setAcceptDrops(True)

        # position of the graphics item on the scene
        self.setPos(self.stateData.x, self.stateData.y)

        self.dragging = False

        # create an ellipse
        self.ellipse = QGraphicsEllipseItem(-StateGraphicsItem.NODE_WIDTH / 2,
                                            -StateGraphicsItem.NODE_WIDTH / 2,
                                            StateGraphicsItem.NODE_WIDTH,
                                            StateGraphicsItem.NODE_WIDTH, self)
        brush = QBrush(Qt.SolidPattern)
        brush.setColor(Qt.blue)
        self.ellipse.setBrush(brush)

        self.textGraphics = IdTextBoxGraphicsItem(self.stateData.name, self)
        textWidth = self.textGraphics.boundingRect().width()
        self.textGraphics.setPos(
            -textWidth / 2, StateGraphicsItem.NODE_WIDTH -
            (StateGraphicsItem.NODE_WIDTH / 2) + 5)
        self.textGraphics.textChanged.connect(self.nameChanged)
        self.textGraphics.textEditStarted.connect(self.textEditStarted)
        self.textGraphics.textEditFinished.connect(self.textEditFinished)

        self.initGraphics = None
        self.setInitial(self.stateData.initial)
Пример #11
0
    def paintStripe(self, st, p, coord, color):
        # left right
        if st == 0:
            left1 = QPoint(coord[0],
                           coord[1] + self.grid_size // 2 - self.radius)
            left2 = QPoint(coord[0],
                           coord[1] + self.grid_size // 2 + self.radius)
            right1 = QPoint(left1.x() + self.grid_size, left1.y())
            right2 = QPoint(left2.x() + self.grid_size, left2.y())
            poly = QPolygonF([left1, right1, right2, left2])
        # top to bottom
        elif st == 1:
            top1 = QPoint(coord[0] + self.grid_size // 2 - self.radius,
                          coord[1])
            top2 = QPoint(coord[0] + self.grid_size // 2 + self.radius,
                          coord[1])
            bot1 = QPoint(top1.x(), top1.y() + self.grid_size)
            bot2 = QPoint(top2.x(), top2.y() + self.grid_size)
            poly = QPolygonF([top1, top2, bot2, bot1])

        path = QPainterPath()
        path.addPolygon(poly)
        p.drawPolygon(poly)

        brush = QBrush()
        brush.setColor(color)
        brush.setStyle(Qt.SolidPattern)
        p.fillPath(path, brush)
Пример #12
0
    def paintEvent(self, event):
        """Draws the current state of the game in the window. """
        painter = QPainter(self)
        brush = QBrush()

        window_width = painter.device().width()
        window_height = painter.device().height()

        # Paint background
        brush.setColor(QColor(BACKGROUND_COLOR))
        brush.setStyle(Qt.SolidPattern)
        background = QRect(0, 0, window_width, window_height)
        painter.fillRect(background, brush)

        # Keep game centered in window
        start_x = (window_width - GAME_WIDTH) / 2
        start_y = (window_height - GAME_HEIGHT) / 2
        cell_width = GAME_WIDTH / N_COLS
        cell_height = GAME_HEIGHT / N_ROWS

        # Paint living cells
        for i in range(N_ROWS):
            for j in range(N_COLS):
                if self._cells[i][j].alive:
                    # Get cell color based on age
                    brush.setColor(QColor(self._cells[i][j].get_color()))

                    # Calculate cell coordinates
                    cell_x = start_x + cell_width * j
                    cell_y = start_y + cell_height * i

                    # Draw cell in window
                    cell = QRect(cell_x, cell_y, cell_width, cell_height)
                    painter.fillRect(cell, brush)
Пример #13
0
    def plot_markers(self):

        s = self.scene
        bs = self.box_size
        x0, y1, x1, y0 = self.canvas_box

        from PyQt5.QtGui import QPen, QColor, QBrush
        from PyQt5.QtCore import Qt
        p = QPen(QColor('black'))
        b = QBrush()

        for m in self.markers:
            if m.graphics_item is None:
                x, y = self.user_xy_to_canvas_xy(m.xy)
                color = hex_color_name(m.rgba[:3])
                c = QColor(color)
                b.setColor(c)
                b.setStyle(Qt.SolidPattern)
                if self.marker_type == 'line':
                    m.graphics_item = gi = s.addRect(x - bs,
                                                     y0 + bs,
                                                     2 * bs,
                                                     y1 - y0 - bs,
                                                     pen=p,
                                                     brush=b)
                    gi.setZValue(1.0)  # Show on top of histogram
                elif self.marker_type == 'box':
                    m.graphics_item = gi = s.addRect(x - bs,
                                                     y - bs,
                                                     2 * bs,
                                                     2 * bs,
                                                     pen=p,
                                                     brush=b)
                    gi.setZValue(1.0)  # Show on top of histogram
Пример #14
0
 def hoverLeaveEvent(self, event):
     '''event: QGraphicsSceneHoverEvent '''
     # change color to dark cyan
     brush = QBrush()
     brush.setStyle(Qt.SolidPattern)
     brush.setColor(Qt.darkCyan)
     self.setBrush(brush)
Пример #15
0
    def test_paint(self, event):
        #QPainter
        # 练习画图的例子
        p1 = QPoint()
        point_list = []

        w = self.width()  # 绘图区的宽度
        h = self.height()  # 绘图区的高度

        rect = QRect(w / 4, h / 4, w / 2, h / 2)  # 中间区域矩形框

        # 设置画笔
        pen = QPen()
        pen.setWidth(3)  # 线宽
        pen.setColor(Qt.red)  # 划线颜色
        pen.setStyle(Qt.SolidLine)  # 线的样式
        pen.setCapStyle(Qt.FlatCap)  # 线端点式样
        pen.setJoinStyle(Qt.BevelJoin)  # 线的连接点样式
        # 设置画刷
        brush = QBrush()
        brush.setColor(Qt.yellow)
        brush.setStyle(Qt.SolidPattern)
        painter = QPainter()

        painter.begin(self)
        painter.setPen(pen)
        painter.setBrush(brush)
        painter.drawRect(rect)

        painter.end()

        pass
Пример #16
0
    def draw(self, painter: QPainter):
        delta_x = (int)(cos(self.angle) * BOT_POINTER_LENGTH)
        delta_y = (int)(sin(self.angle) * BOT_POINTER_LENGTH)

        if self.id == 0:
            color = QColor(0xFF, 0x00, 0x00, 0xFF)
        else:
            color = QColor(0x00, 0x00, 0xFF, 0xFF)

        pen = QPen(color)
        brush = QBrush(Qt.SolidPattern)
        brush.setColor(color)

        painter.setPen(pen)
        painter.setBrush(brush)

        painter.drawPie(
            SCALE(self.x - BOT_RADIUS),
            SCALE(self.y - BOT_RADIUS),
            SCALE(2 * BOT_RADIUS),
            SCALE(2 * BOT_RADIUS),
            0,
            360 * 64,
        )
        pen.setWidth(1)

        painter.drawLine(
            SCALE(self.x),
            SCALE(self.y),
            SCALE(self.x + delta_x),
            SCALE(self.y + delta_y),
        )
Пример #17
0
    def __init__(self, parent, name="", color=Qt.white, typ="X"):
        super().__init__(None)

        polygon = QPolygonF()

        if typ == "Y":
            polygon.append(QPointF(0, 0))
            polygon.append(QPointF(0, 16))
            polygon.append(QPointF(12, 16))
            polygon.append(QPointF(20, 8))
            polygon.append(QPointF(12, 0))

        if typ == "X":
            polygon.append(QPointF(0, 0))
            polygon.append(QPointF(6, 6))
            polygon.append(QPointF(12, 0))

        self.setPolygon(polygon)

        # we want black background
        bg = QBrush()
        col = QColor(color)
        col.setAlpha(200)
        bg.setColor(col)
        bg.setStyle(Qt.SolidPattern)
        self.setBrush(bg)

        if typ == "Y":
            text = QGraphicsTextItem(self)
            text.setPlainText(name)
            text.setY(text.y() - 4)

        self.typ = typ
        self.show()
Пример #18
0
 def drawCircle(self, painter, centerX, centerY, color, size):
     pen = QPen(color, size)
     painter.setPen(pen)
     brush = QBrush(Qt.SolidPattern)
     brush.setColor(QColor(Qt.blue))
     painter.setBrush(brush)
     painter.drawEllipse(centerX, centerY, 5, 5)
Пример #19
0
    def __init__(self, parent, text="", color=Qt.white, text_col=Qt.black):
        super().__init__(None)

        polygon = QPolygonF()

        self.width = 175
        self.height = 24

        polygon.append(QPointF(0, 0))
        polygon.append(QPointF(0, self.height))
        polygon.append(QPointF(self.width, self.height))
        polygon.append(QPointF(self.width, 0))

        self.setPolygon(polygon)

        # we want black background
        bg = QBrush()
        col = QColor(color)
        col.setAlpha(200)
        bg.setColor(col)
        bg.setStyle(Qt.SolidPattern)
        self.setBrush(bg)

        self.text = QGraphicsTextItem(self)
        self.text.setDefaultTextColor(QColor(text_col))
        self.text.setPlainText(text)

        self.show()
Пример #20
0
class ModCrossButton(QPushButton):
    def __init__(self,parent,path=None):
        QPushButton.__init__(self,parent)

        self.parent=parent


        #self.setAttribute(Qt.WA_TranslucentBackground, True)
        self.backgroundColor = QPalette().light().color()
        self.backgroundColor.setRgb(157,157,157) #(220,203,231)
        #self.backgroundColor.setAlpha(100)
        self.brush=QBrush(Qt.SolidPattern)


    def paintEvent(self,event):
        self.wide=self.width()
        self.high=self.height()
        self.xdis=self.wide/7
        self.ydis=self.xdis

        self.path=QPainterPath()
        self.path.setFillRule(Qt.OddEvenFill)

        self.path.moveTo(self.wide/2, self.high/2-self.xdis)
        self.path.arcTo(0,0, self.wide, self.high,0,360)
        #self.path.closeSubpath()

        self.path.moveTo(self.wide/2-self.xdis/2, self.ydis)
        self.path.lineTo(self.wide/2-self.xdis/2, self.high/2-self.xdis/2)
        self.path.lineTo(self.ydis, self.high/2-self.xdis/2)
        self.path.lineTo(self.ydis, self.high/2+self.xdis/2)
        self.path.lineTo(self.wide/2-self.xdis/2, self.high/2+self.xdis/2)
        self.path.lineTo(self.wide/2-self.xdis/2, self.high-self.ydis)
        self.path.lineTo(self.wide/2+self.xdis/2, self.high-self.ydis)
        self.path.lineTo(self.wide/2+self.xdis/2, self.high/2+self.xdis/2)
        self.path.lineTo(self.wide-self.ydis, self.high/2+self.xdis/2)
        self.path.lineTo(self.wide-self.ydis, self.high/2-self.xdis/2)
        self.path.lineTo(self.wide/2+self.xdis/2, self.high/2-self.xdis/2)
        self.path.lineTo(self.wide/2+self.xdis/2, self.ydis)
        self.path.closeSubpath()

        self.brush.setColor(self.backgroundColor)
        self.painter=QPainter(self)
        self.painter.setRenderHint(QPainter.Antialiasing)

        self.painter.setPen(Qt.NoPen)
        self.painter.setBrush(self.brush)
        self.painter.drawPath(self.path)
        self.painter.end()

    #def mousePressEvent(self,ev):
    #    self.parent.close()

    def enterEvent(self,ev):
        self.backgroundColor.setRgb(242,146,52) 
        self.update()
        
    def leaveEvent(self,ev):
        self.backgroundColor.setRgb(157,157,157)
        self.update()
Пример #21
0
    def __init__(self, dataList, orderIndex=4):
        super(QtTableWidget, self).__init__()

        self.orderIndex = int(orderIndex)

        if len(dataList) == 0:
            self.dataHeader = []
            self.dataBody = []
        elif len(dataList) == 1:
            self.dataHeader = dataList[0]
            self.dataBody = []
        else:
            self.dataHeader = dataList[0]
            self.dataBody = dataList[1:]
            self.dataBody.sort(key=lambda x: x[self.orderIndex], reverse=True)

        self.model = QStandardItemModel()
        self.model.setHorizontalHeaderLabels(["Details"] + self.dataHeader)

        for row in range(len(self.dataBody)):
            RowContents = []
            ButtonItem = QStandardItem()
            RowContents.append(ButtonItem)
            for column in range(len(self.dataBody[row])):
                if column == 0:
                    brush = QBrush()
                    brush.setColor(Color[self.dataBody[row][0]])
                item = QStandardItem("{0}".format(self.dataBody[row][column]))
                item.setForeground(brush)
                RowContents.append(item)
            self.model.invisibleRootItem().appendRow(RowContents)
        self.setSourceModel(self.model)
Пример #22
0
    def __init__(self, name, height=200, width=50, parent=None):
        '''name: str '''
        super().__init__(parent)
        # Set locked atribute
        self.locked = False

        # create my signal
        self.s = ButtonSignal()

        # draw the rect
        self.setRect(0, 0, height, width)

        # change color of rect
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)
        brush.setColor(Qt.darkCyan)
        self.setBrush(brush)

        # draw the text
        self.text = QGraphicsTextItem(name, self)
        x_pos = self.rect().width() / 2 - self.text.boundingRect().width() / 2
        y_pos = self.rect().height() / 2 - self.text.boundingRect().height() / 2
        self.text.setPos(x_pos, y_pos)

        # allow responding to hover events
        self.setAcceptHoverEvents(True)
Пример #23
0
    def drawPolygonOnVideo(values, painter, surface, gt):
        ''' Draw Polygons on Video '''
        poly = []
        for pt in values:
            if hasElevationModel():
                pt = GetLine3DIntersectionWithPlane(
                    GetSensor(), pt, GetFrameCenter()[2])
            scr_x, scr_y = vut.GetInverseMatrix(
                pt[1], pt[0], gt, surface)
            center = QPoint(scr_x, scr_y)
            poly.append(center)

        poly.append(poly[0])

        radius = 3
        polygon = QPolygonF(poly)
        pen = QPen()
        pen.setColor(Qt.green)
        pen.setWidth(radius)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        brush = QBrush()
        brush.setColor(QColor(176, 255, 128, 28))
        brush.setStyle(Qt.SolidPattern)

        path = QPainterPath()
        path.addPolygon(polygon)

        painter.setPen(pen)
        painter.drawPolygon(polygon)
        painter.fillPath(path, brush)
        return
Пример #24
0
    def draw(self, qp: QPainter):
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)

        unselected_color = QColor(
            "white") if not self.is_computed() else QColor(200, 255, 200)
        selected_color = QColor(100, 100,
                                200) if not self.is_computed() else QColor(
                                    100, 150, 100)

        if self.error:
            unselected_color = QColor(255, 200, 200)
            selected_color = QColor(150, 50, 50)

        brush.setColor(
            unselected_color if not self.selected else selected_color)
        qp.setBrush(brush)

        rect = self.get_global_rect()
        brush = QBrush()
        brush.setColor(
            unselected_color if not self.selected else selected_color)
        brush.setStyle(Qt.SolidPattern)
        pen = QPen(QColor("black"))
        pen.setWidth(3 if self.hover else 1)
        qp.setPen(pen)
        qp.drawRect(rect)
        for i in self.input_handlers:
            i.draw(qp)
        for o in self.output_handlers:
            o.draw(qp)
        qp.drawText(self.get_text_rect(), 5, self.name)
Пример #25
0
class Winkenlight(QWidget):
    on_color = (255,90,90)
    off_color = (80,0,0)
    def __init__(self, *args):
        QWidget.__init__(self, *args)
        self.setMinimumSize(30,30)
        self._pen = Qt.QPen()
        self._pen.setWidth(5)
        self._brush = QBrush(QColor(255,255,0))
        self._ts = QtCore.QDateTime.currentDateTime().toPyDateTime()
        self._cold = (self.on_color[0]-self.off_color[0], self.on_color[1]-self.off_color[1], self.on_color[2]-self.off_color[2])
    def resizeEvent(self, foo):
        self.update()
    def paintEvent(self, foo):
        td = QtCore.QDateTime.currentDateTime().toPyDateTime() - self._ts
        lum = pow(.67,pow((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6)/75000.,1.33))
        r = int(self.off_color[0] + lum*self._cold[0])
        g = int(self.off_color[1] + lum*self._cold[1])
        b = int(self.off_color[2] + lum*self._cold[2])
        self._brush.setColor(QColor(r,g,b))
        self._pen.setColor(QColor(r*2/3,g*2/3,b*2/3))
        p = QPainter(self)
        diam = min(self.width(),self.height()) * 2 / 3
        x = (self.width()-diam)/2
        y = (self.height()-diam)/2
        p.setPen(self._pen)
        p.setBrush(self._brush)
        p.drawEllipse(x,y,diam,diam)
    def ping(self):
        self._rgb = list(self.on_color)
        self._ts = QtCore.QDateTime.currentDateTime().toPyDateTime()
Пример #26
0
class Node(QGraphicsItem):
    def __init__(self, colour, name):
        super().__init__()
        self.name = name
        self.wires = []
        self.setFlags(QGraphicsItem.ItemIsFocusable |
                      QGraphicsItem.ItemIsMovable |
                      QGraphicsItem.ItemIsSelectable |
                      QGraphicsItem.ItemSendsGeometryChanges)
        self.brush = QBrush(colour)
        self.rect = QRectF(0, 0, 100, 50)
        # Selection border
        self.focus_rect = QRectF(self.rect.x() - 1, self.rect.y() - 1,
                                self.rect.width() + 1, self.rect.height() + 1)

    def boundingRect(self):
        """Has to be re-implemented for the sub-classed item to work"""
        return self.rect

    def paint(self, painter, option, widget=None):
        painter.setPen(Qt.black)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(self.brush)
        painter.drawRoundedRect(0, 0, 100, 50, 5, 5)
        painter.drawText(self.rect, self.name)
        if self.isSelected():
            self.drawFocusRect(painter)

    def drawFocusRect(self, painter):
        """Highlight selected"""
        return
        focus_brush = QBrush()
        focus_pen = QPen(Qt.DotLine)
        focus_pen.setColor(Qt.red)
        focus_pen.setWidthF(1.5)
        painter.setBrush(focus_brush)
        painter.setPen(focus_pen)
        painter.drawRect(self.focus_rect)

    def set_position(self, pos):
        self.setPos(pos)

    def set_brush(self, brush):
        self.brush.setColor(brush)
        self.update()

    def add_wire(self, wire):
        self.wires.append(wire)

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemPositionChange:
            for wire in self.wires:
                wire.updatePosition()
        return value

    def mousePressEvent(self, event):
        QGraphicsItem.mousePressEvent(self, event)

    def mouseDoubleClickEvent(self, e):
        self.scene().itemDoubleClicked.emit(self)
Пример #27
0
    def createArrow(self):
        # add an arrow to destination line
        myLine = self.destinationLine.line()
        myLine.setLength(myLine.length() - TransitionGraphicsItem.ARROW_SIZE)
        rotatePoint = myLine.p2() - self.destinationLine.line().p2()

        rightPointX = rotatePoint.x() * math.cos(math.pi / 6) - rotatePoint.y() * math.sin(math.pi / 6)
        rightPointY = rotatePoint.x() * math.sin(math.pi / 6) + rotatePoint.y() * math.cos(math.pi / 6)
        rightPoint = QPointF(rightPointX + self.destinationLine.line().x2(),
                             rightPointY + self.destinationLine.line().y2())

        leftPointX = rotatePoint.x() * math.cos(-math.pi / 6) - rotatePoint.y() * math.sin(-math.pi / 6)
        leftPointY = rotatePoint.x() * math.sin(-math.pi / 6) + rotatePoint.y() * math.cos(-math.pi / 6)
        leftPoint = QPointF(leftPointX + self.destinationLine.line().x2(),
                            leftPointY + self.destinationLine.line().y2())

        polygon = QPolygonF()
        polygon << rightPoint << leftPoint << self.destinationLine.line().p2() << rightPoint

        if self.arrow == None:
            self.arrow = QGraphicsPolygonItem(polygon, self)
        else:
            self.arrow.setPolygon(polygon)

        brush = QBrush(Qt.SolidPattern)
        brush.setColor(Qt.black)
        self.arrow.setBrush(brush)
Пример #28
0
    def createArrow(self):
        # add an arrow to destination line
        myLine = self.destinationLine.line()
        myLine.setLength(myLine.length() - TransitionGraphicsItem.ARROW_SIZE)
        rotatePoint = myLine.p2() - self.destinationLine.line().p2()

        rightPointX = rotatePoint.x() * math.cos(
            math.pi / 6) - rotatePoint.y() * math.sin(math.pi / 6)
        rightPointY = rotatePoint.x() * math.sin(
            math.pi / 6) + rotatePoint.y() * math.cos(math.pi / 6)
        rightPoint = QPointF(rightPointX + self.destinationLine.line().x2(),
                             rightPointY + self.destinationLine.line().y2())

        leftPointX = rotatePoint.x() * math.cos(
            -math.pi / 6) - rotatePoint.y() * math.sin(-math.pi / 6)
        leftPointY = rotatePoint.x() * math.sin(
            -math.pi / 6) + rotatePoint.y() * math.cos(-math.pi / 6)
        leftPoint = QPointF(leftPointX + self.destinationLine.line().x2(),
                            leftPointY + self.destinationLine.line().y2())

        polygon = QPolygonF()
        polygon << rightPoint << leftPoint << self.destinationLine.line().p2(
        ) << rightPoint

        if self.arrow == None:
            self.arrow = QGraphicsPolygonItem(polygon, self)
        else:
            self.arrow.setPolygon(polygon)

        brush = QBrush(Qt.SolidPattern)
        brush.setColor(Qt.black)
        self.arrow.setBrush(brush)
Пример #29
0
    def drawObstacles(self, qp):

        for xpos in range(Board.TileCount):
            for ypos in range(Board.TileCount):

                tileVal = self.obstacleArray[xpos][ypos]

                if tileVal == Hazard.Wall:
                    brush = QBrush(Qt.Dense2Pattern)
                    brush.setColor(Qt.red)
                    qp.setBrush(brush)
                    qp.drawRect(xpos * TILE_SIZE, ypos * TILE_SIZE, TILE_SIZE,
                                TILE_SIZE)

                elif tileVal == Hazard.Border:
                    brush = QBrush(Qt.Dense2Pattern)
                    brush.setColor(Qt.blue)
                    qp.setBrush(brush)
                    qp.drawRect(xpos * TILE_SIZE, ypos * TILE_SIZE, TILE_SIZE,
                                TILE_SIZE)

                elif tileVal == Hazard.Hole:
                    qp.setBrush(Qt.black)
                    center = QPoint(xpos * TILE_SIZE + 0.5 * TILE_SIZE,
                                    ypos * TILE_SIZE + 0.5 * TILE_SIZE)
                    qp.drawEllipse(center, 0.5 * TILE_SIZE, 0.25 * TILE_SIZE)
Пример #30
0
 def fillSizesModel(self):
     # First we empty the old model. We might wanna use this function in the future to fill it with the brushmask of the selected brush, but there's currently no API for recognising changes in the current brush nor is there a way to get its brushmask.
     self.brushSizeModel.clear()
     for s in range(len(self.sizesList)):
         # we're gonna itterate over our list, and make a new item for each entry.
         # We need to disable a bunch of stuff to make sure people won't do funny things to our entries.
         item = QStandardItem()
         item.setCheckable(False)
         item.setEditable(False)
         item.setDragEnabled(False)
         item.setText(str(self.sizesList[s]) + " px")
         # And from here on we'll make an icon.
         brushImage = QPixmap(64, 64)
         img = QImage(64, 64, QImage.Format_RGBA8888)
         circlePainter = QPainter()
         img.fill(Qt.transparent)
         circlePainter.begin(img)
         brush = QBrush(Qt.SolidPattern)
         brush.setColor(self.brushSizeTableView.palette().color(
             QPalette.Text))
         circlePainter.setBrush(brush)
         circlePainter.setPen(QPen(QBrush(Qt.transparent), 0))
         brushSize = max(min(self.sizesList[s], 64), 1)
         brushSize = brushSize * 0.5
         circlePainter.drawEllipse(QPointF(32, 32), brushSize, brushSize)
         circlePainter.end()
         brushImage = QPixmap.fromImage(img)
         # now we're done with drawing the icon, so we set it on the item.
         item.setIcon(QIcon(brushImage))
         self.brushSizeModel.appendRow(item)
     self.brushSizeTableView.setModel(self.brushSizeModel)
Пример #31
0
class RoundedPushButton1(QPushButton):
    def __init__(self,parent, default_wide, default_high,text=''):
        QPushButton.__init__(self, parent)
        #self.resize(100,80)
        self.default_high=default_high
        self.default_wide=default_wide
        self.xrd=self.default_wide/10
        #self.yrd=self.default_high/10
        self.yrd=self.xrd
        #self.resize(self.default_wide,self.default_high)

        self.backgroundColor = QPalette().light().color()
        self.backgroundColor.setRgb(157,157,157) #(220,203,231)
        #self.backgroundColor.setAlpha(0)
        self.brush=QBrush(Qt.SolidPattern)

        self.textlabel=textQLabel(self,text)

    def paintEvent(self,event):
        #brush.setStyle(Qt.Dense1Pattern)
        self.brush.setColor(self.backgroundColor)
        self.painter=QPainter(self)
        self.painter.setRenderHint(QPainter.Antialiasing)
        
        self.painter.setPen(Qt.NoPen)
        self.painter.setBrush(self.brush)
        self.painter.drawRoundedRect(QRect(0,0,self.default_wide,self.default_high), self.xrd, self.yrd)
        #self.painter.drawPixmap(self.imgx, self.imgy, self.piximg)
        self.painter.end()
Пример #32
0
    def __init__(self, width, height):
        super(GraphicsView, self).__init__()

        # 创建图形容器

        self.setFixedSize(460, 560)

        # 将车库实体化为 宽度450 长度600 大小
        self.scene = QGraphicsScene()
        self.scene.setSceneRect(0, 0, 450, 550)

        # 创建车辆实例
        self.rect = RectItem()

        # 初始化位置为 30 30 车辆宽度 250 长度 400
        self.rect.setRect((450 - width) / 2, 0, width, height)

        # 创建颜色刷子
        brush1 = QBrush(Qt.SolidPattern)
        brush1.setColor(QColor(124, 214, 175))

        # 给车身上色
        self.rect.setBrush(brush1)

        # 将车身添加到容器中 即放到车库里
        self.scene.addItem(self.rect)

        # 设置当前场景
        self.setScene(self.scene)
Пример #33
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)
Пример #34
0
class QMarkablePicture(QLabel):
    def __init__(self, parent=None):
        QLabel.__init__(self, parent)
        self.initBrush()
        self.marks = []
        self.is_marks_count_limited = False
        self.marks_count_limit = 0

    def initBrush(self):
        self.brush = QBrush(Qt.SolidPattern)
        self.brush.setColor(QColor(constants.defaultBrushColor))

    def paintEvent(self, e):
        QLabel.paintEvent(self, e)
        painter = QPainter()
        painter.begin(self)
        painter.setBrush(self.brush)
        for mark in self.marks:
            painter.drawEllipse(mark, constants.ellipsWidth, constants.ellipsHeight)
        painter.end()

    def setBrushColor(self, color):
        self.brush.setColor(color)

    def drawMark(self, mark):
        if self.__isAbleDrawMark():
            self.marks.append(mark)
            self.update()

    def removeMark(self, mark):
        for painted_mark in self.marks:
            if self.__isApproximatelyEqual(mark, painted_mark, constants.epsilon):
                self.marks.remove(painted_mark)
                break
        self.update()

    def getMarks(self):
        return self.marks.copy()

    def setMarksCountLimit(self, limit):
        self.is_marks_count_limited = True
        self.marks_count_limit = limit

    def __isAbleDrawMark(self):
        limit_enabled_condition = self.is_marks_count_limited and (len(self.marks) < self.marks_count_limit)
        limit_disabled_condition = not self.is_marks_count_limited
        return limit_enabled_condition or limit_disabled_condition

    def __isApproximatelyEqual(self, firstMark, secondMark, epsilon):
        full_equality = firstMark == secondMark

        x_top_limit = (firstMark.x() + epsilon) >= secondMark.x()
        x_bottom_limit = (firstMark.x() - epsilon) <= secondMark.x()
        x_equality = x_top_limit and x_bottom_limit

        y_top_limit = (firstMark.y() + epsilon) >= secondMark.y()
        y_bottom_limit = (firstMark.y() - epsilon) <= secondMark.y()
        y_equality = y_top_limit and y_bottom_limit

        return full_equality or (x_equality and y_equality)
Пример #35
0
    def _drawMeasurements(self):
        if self._selNuc is None:
            return

        painter = QPainter()
        painter.begin(self.imagePixmap)
        painter.setRenderHint(QPainter.Antialiasing)

        rng_thick = 3
        rng_thick *= self.pix_per_um

        if self.activeCh == "dna":
            # get nuclei boundary as a polygon
            nucb_qpoints_e = [
                Qt.QPoint(x, y)
                for x, y in self._selNuc.buffer(rng_thick).exterior.coords
            ]
            nucb_qpoints_i = [
                Qt.QPoint(x, y) for x, y in self._selNuc.exterior.coords
            ]

            painter.setPen(QPen(QBrush(QColor('white')), 3))
            painter.drawPolygon(Qt.QPolygon(nucb_qpoints_i))
            painter.drawPolygon(Qt.QPolygon(nucb_qpoints_e))

            nucb_poly = Qt.QPolygon(nucb_qpoints_e).subtracted(
                Qt.QPolygon(nucb_qpoints_i))
            brush = QBrush(QtCore.Qt.BDiagPattern)
            brush.setColor(QColor('white'))
            painter.setBrush(brush)
            painter.setPen(QPen(QBrush(QColor('transparent')), 0))

            painter.drawPolygon(nucb_poly)

        elif self.activeCh == "act":
            nuc_pen = QPen(QBrush(QColor('red')), self.dwidth / 256)
            nuc_pen.setStyle(QtCore.Qt.DotLine)
            painter.setPen(nuc_pen)
            for i, e in self.nuclei.iterrows():
                n = shapely.wkt.loads(e["value"])
                if e["id"] == self.currNucleusId:
                    brush = QBrush(QtCore.Qt.BDiagPattern)
                    brush.setColor(QColor('yellow'))
                    painter.setBrush(brush)

                # get nuclei boundary as a polygon
                nucb_qpoints = [Qt.QPoint(x, y) for x, y in n.exterior.coords]
                painter.drawPolygon(Qt.QPolygon(nucb_qpoints))
                painter.setBrush(QBrush(QtCore.Qt.NoBrush))

        for ix, me in self.lines(self.currNucleusId).iterrows():
            thickness = self.pix_per_um
            thickness *= (2 if (self.selectedLine is not None
                                and self.selectedLine == me['li']) else 1)
            painter.setPen(QPen(QBrush(QColor(me['c'])), thickness))
            pts = [Qt.QPoint(x, y) for x, y in [me['ls0'], me['ls1']]]
            painter.drawLine(pts[0], pts[1])

        painter.end()
 def setStyle(self, painter, fillColor, penColor, stroke):
     brush = QBrush()
     pen = QPen(penColor, stroke)
     brush.setColor(fillColor)
     brush.setStyle(Qt.SolidPattern)
     painter.setBrush(brush)
     painter.setPen(pen)
     painter.setRenderHint(QPainter.Antialiasing)
Пример #37
0
 def setRequired(self, required):
     self.required = required
     brush = QBrush()
     if required:
         brush.setColor(QColor(255, 0, 0))
     else:
         brush.setColor(QColor(0, 0, 0))
     self.setForeground(0, brush)
Пример #38
0
class ModCloseButton(QPushButton):
    def __init__(self,parent,wide,high,ppath=None):
        QPushButton.__init__(self,parent)

        self.parent=parent
        self.wide=wide
        self.high=high
        self.resize(self.wide,self.high)
        self.xdis=self.wide/10

        #self.setAttribute(Qt.WA_TranslucentBackground, True)
        self.backgroundColor = QPalette().light().color()
        self.backgroundColor.setRgb(157,157,157) #(220,203,231)
        #self.backgroundColor.setAlpha(100)
        self.brush=QBrush(Qt.SolidPattern)

        if ppath :
            self.path=ppath
        else :
            self.path=QPainterPath()

            self.path.moveTo(self.wide/2, self.high/2-self.xdis)
            self.path.arcTo(0,0, self.wide-2*self.xdis, self.high-2*self.xdis,45,90)
            self.path.closeSubpath()

            self.path.moveTo(self.wide/2-self.xdis, self.high/2)
            self.path.arcTo(0,0,self.wide-2*self.xdis,self.high-2*self.xdis,135,90)
            self.path.closeSubpath()

            self.path.moveTo(self.wide/2, self.high/2+self.xdis)
            self.path.arcTo(0,0,self.wide-2*self.xdis, self.high-2*self.xdis,225,90)
            self.path.closeSubpath()

            self.path.moveTo(self.wide/2+self.xdis, self.high/2)
            self.path.arcTo(0,0,self.wide-2*self.xdis, self.high-2*self.xdis,315,90)
            self.path.closeSubpath()

    def paintEvent(self,event):
        self.brush.setColor(self.backgroundColor)
        self.painter=QPainter(self)
        self.painter.setRenderHint(QPainter.Antialiasing)

        self.painter.setPen(Qt.NoPen)
        self.painter.setBrush(self.brush)
        self.painter.drawPath(self.path)
        self.painter.end()

    def mousePressEvent(self,ev):
        self.parent.close()

    def enterEvent(self,ev):
        self.backgroundColor.setRgb(234,39,13) 
        self.update()
        
    def leaveEvent(self,ev):
        self.backgroundColor.setRgb(157,157,157)
        self.update()
    def valueChanged(self, property, value):
        if (not self.propertyToId.contains(property)):
            return

        if (not self.currentItem or self.currentItem.isNone()):
            return
        tp = type(value)
        id = self.propertyToId[property]
        if tp == float:
            if (id == "xpos"):
                self.currentItem.setX(value)
            elif (id == "ypos"):
                self.currentItem.setY(value)
            elif (id == "zpos"):
                self.currentItem.setZ(value)
        elif tp == str:
            if (id == "text"):
                if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                    i = self.currentItem
                    i.setText(value)
        elif tp == QColor:
            if (id == "color"):
                if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                    i = self.currentItem
                    i.setColor(value)
            elif (id == "brush"):
                if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
                    i = self.currentItem
                    b = QBrush(i.brush())
                    b.setColor(value)
                    i.setBrush(b)
            elif (id == "pen"):
                if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Line):
                    i = self.currentItem
                    p = QPen(i.pen())
                    p.setColor(value)
                    i.setPen(p)
        elif tp == QFont:
            if (id == "font"):
                if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                    i = self.currentItem
                    i.setFont(value)
        elif tp == QPoint:
            if (self.currentItem.rtti() == RttiValues.Rtti_Line):
                i = self.currentItem
                if (id == "endpoint"):
                    i.setPoints(i.startPoint().x(), i.startPoint().y(), value.x(), value.y())
        elif tp == QSize:
            if (id == "size"):
                if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle):
                    i = self.currentItem
                    i.setSize(value.width(), value.height())
                elif (self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
                    i = self.currentItem
                    i.setSize(value.width(), value.height())
        self.canvas.update()
Пример #40
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())
Пример #41
0
    def __init__(self,  dblock: DBlock):
        super(DBlockTreeItem, self).__init__(dblock, dblock.name)
        self.dblock = dblock
        self.setSelectable(False)
        self.setEditable(False)

        self.tool_tip = "DBlock: " + dblock.name

        if isinstance(dblock, DEvent):
            brush = QBrush()
            brush.setColor(Qt.magenta)
            self.tool_tip = "DEvent: " + dblock.name
            self.setForeground(brush)
            self.setSelectable(True)
Пример #42
0
class WLLineLabel(QPushButton):
    def __init__(self,parent):
        super(WLLineLabel,self).__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint )
        self.linelength=1000
        self.lineheight=5
        self.resize(self.linelength, self.lineheight)
        self.move(100,100)
        self.stats=None
        #self.setStyleSheet("{background-color:transparent;border:none;color:transparent;}")

        self.backgroundColor = QPalette().light().color()
        self.backgroundColor.setRgb(157,157,157)#(220,203,231)
        #self.backgroundColor.setAlpha(255)
        self.brush=QBrush(Qt.SolidPattern)
    def paintEvent(self,event):
        self.brush.setColor(self.backgroundColor)
        self.painter=QPainter(self)
        self.painter.setRenderHint(QPainter.Antialiasing)

        self.painter.setPen(Qt.NoPen)
        self.painter.setBrush(self.brush)
        #print(self.geometry())
        self.painter.drawRect(0, 0, 1000, 5)
        self.painter.end()

    
    def statsReset(self):
        self.stats=None
        self.backgroundColor.setAlpha(255)
        self.redraw()
    def mousePressEvent(self,ev):
        if self.stats == 'selected' :
            self.stats = None
            self.backgroundColor.setAlpha(255)
        else:
            self.stats = 'selected'
            self.backgroundColor.setRgb(157,157,157)
        self.update()

    def enterEvent(self,ev):
        #print('enter')
        if self.stats != 'selected' :
            self.backgroundColor.setAlpha(0)
            self.update()
        
    def leaveEvent(self,ev):
        if self.stats != 'selected' :
            self.backgroundColor.setAlpha(255)
            self.update()
Пример #43
0
    def setupMounts(self):
        adapter = app.adapterManager[0]
        if not adapter.useXwared:
            self.tab_mount.setEnabled(False)
            return
        self.table_mounts.setRowCount(0)
        self.table_mounts.clearContents()

        mountsMapping = app.adapterManager[0].mountsFaker.getMountsMapping()
        for i, mount in enumerate(app.adapterManager[0].mountsFaker.mounts):
            self.table_mounts.insertRow(i)
            # drive1: the drive letter it should map to, by alphabetical order
            drive1 = app.adapterManager[0].mountsFaker.driveIndexToLetter(i)
            self.table_mounts.setItem(i, 0, QTableWidgetItem(drive1 + "\\TDDOWNLOAD"))

            # mounts = ['/path/to/1', 'path/to/2', ...]
            self.table_mounts.setItem(i, 1, QTableWidgetItem(mount))

            # drive2: the drive letter it actually is assigned to
            drive2 = mountsMapping.get(mount, "无")

            errors = []

            # check: mapping
            if drive1 != drive2:
                errors.append(
                    "错误:盘符映射在'{actual}',而不是'{should}'。\n"
                    "如果这是个新挂载的文件夹,请尝试稍等,或重启后端,可能会修复此问题。"
                    .format(actual = drive2, should = drive1))

            brush = QBrush()
            if errors:
                brush.setColor(Qt.red)
                errString = "\n".join(errors)
            else:
                brush.setColor(Qt.darkGreen)
                errString = "正常"
            errWidget = QTableWidgetItem(errString)
            errWidget.setForeground(brush)

            self.table_mounts.setItem(i, 2, errWidget)
            del brush, errWidget

        self.table_mounts.resizeColumnsToContents()
Пример #44
0
    def setupMounts(self):
        self.table_mounts.setRowCount(0)
        self.table_mounts.clearContents()

        permissionCheckResult = app.mountsFaker.permissionCheck()
        permissionCheckFailed = ["无法获得检测权限。运行{}查看原因。".format(constants.PERMISSIONCHECK)]

        mountsMapping = app.mountsFaker.getMountsMapping()
        for i, mount in enumerate(app.mountsFaker.mounts):
            # mounts = ['/path/to/1', 'path/to/2', ...]
            self.table_mounts.insertRow(i)
            self.table_mounts.setItem(i, 0, QTableWidgetItem(mount))
            # drive1: the drive letter it should map to, by alphabetical order
            drive1 = chr(ord('C') + i) + ":"
            self.table_mounts.setItem(i, 1, QTableWidgetItem(drive1))
            # drive2: the drive letter it actually is assigned to
            drive2 = mountsMapping.get(mount, "无")

            # check 1: permission
            errors = permissionCheckResult.get(mount, permissionCheckFailed)

            # check 2: mapping
            if drive1 != drive2:
                errors.append(
                    "警告:盘符映射在'{actual}',而不是'{should}'。需要重启后端修复。".format(
                        actual = drive2,
                        should = drive1))

            brush = QBrush()
            if errors:
                brush.setColor(Qt.red)
                errString = "\n".join(errors)
            else:
                brush.setColor(Qt.darkGreen)
                errString = "正常"
            errWidget = QTableWidgetItem(errString)
            errWidget.setForeground(brush)

            self.table_mounts.setItem(i, 2, errWidget)
            del brush, errWidget

        self.table_mounts.resizeColumnsToContents()
    def init(self):
        current_path = os.path.dirname(os.path.abspath(__file__)).split(os.sep)
        current_path = os.path.join(*current_path[1:-2])

        default_image_path = "/" + current_path + "/test/fakeimg.jpg"
        image_path = self.getProperty("file_name", default_image_path)

        self.image = QPixmap(image_path)
        self.image_dimensions = (self.image.width(), self.image.height())
        self.painter = QPainter(self.image)

        custom_pen = QPen(Qt.SolidLine)
        custom_pen.setColor(Qt.black)
        custom_pen.setWidth(1)
        self.painter.setPen(custom_pen)

        custom_brush = QBrush(Qt.SolidPattern)
        custom_brush.setColor(Qt.lightGray)
        self.painter.setBrush(custom_brush)

        self.setIsReady(True)
        AbstractVideoDevice.init(self)
Пример #46
0
    def setupMounts(self):
        self.table_mounts.setRowCount(0)
        self.table_mounts.clearContents()

        PermissionError = self.permissionCheck()

        mountsMapping = self.mainWin.mountsFaker.getMountsMapping()
        for i, mount in enumerate(self.mainWin.mountsFaker.mounts):
            # mounts = ['/path/to/1', 'path/to/2', ...]
            self.table_mounts.insertRow(i)
            self.table_mounts.setItem(i, 0, QTableWidgetItem(mount))
            drive1 = chr(ord('C') + i) + ":" # the drive letter it should map to, by alphabetical order
            self.table_mounts.setItem(i, 1, QTableWidgetItem(drive1))
            drive2 = mountsMapping.get(mount, "无") # the drive letter it actually is assigned to

            # check 1: permission
            errors = PermissionError.get(mount, ["无法获得检测权限。运行/opt/xware_desktop/permissioncheck查看原因。"])

            # check 2: mapping
            if drive1 != drive2:
                errors.append("警告:盘符映射在'{actual}',而不是'{should}'。需要重启后端修复。".format(actual = drive2, should = drive1))

            from PyQt5.Qt import Qt
            from PyQt5.QtGui import QBrush

            brush = QBrush()
            if errors:
                brush.setColor(Qt.red)
                errString = "\n".join(errors)
            else:
                brush.setColor(Qt.darkGreen)
                errString = "正常"
            errWidget = QTableWidgetItem(errString)
            errWidget.setForeground(brush)

            self.table_mounts.setItem(i, 2, errWidget)
            del brush, errWidget

        self.table_mounts.resizeColumnsToContents()
Пример #47
0
class RoundedPushButton(QPushButton):
    def __init__(self,parent, text=''):
        QPushButton.__init__(self, parent)
        self.text=text
        self.backgroundColor = QPalette().light().color()
        self.backgroundColor.setRgb(157,157,157) #(220,203,231)
        #self.backgroundColor.setAlpha(0)
        self.brush=QBrush(Qt.SolidPattern)

    def paintEvent(self,event):
        self.brush.setColor(self.backgroundColor)
        self.painter=QPainter(self)
        self.painter.setRenderHint(QPainter.Antialiasing)
        
        self.painter.setPen(Qt.NoPen)
        self.painter.setBrush(self.brush)
        self.painter.drawRoundedRect(QRect(0,0,self.width(),self.height()), self.width()/10, self.height()/10)
        self.painter.end()

        self.painter3=QPainter(self)
        self.painter3.drawText(1,0,self.width()-2,self.height(),Qt.AlignCenter,self.text)
        self.painter3.end()
Пример #48
0
    def paintEdge(self, painter, lod):
        pen = QPen(Qt.black)
        pen.setWidth(1)
        pen.setCapStyle(Qt.RoundCap)
        brush = QBrush(self.edgeColor)

        if self.hover:
            #pen.setColor(self.edgeColorHover)
            brush.setColor(self.edgeColorHover)

        if QGraphicsItem.isSelected(self):
            #pen.setColor(self.edgeColorSelected)
            brush.setColor(self.edgeColorSelected)

        painter.setPen(pen)
        painter.setBrush(brush)

        edgePath = self.getEdgePath()       
        edgePath = edgePath.simplified()

        painter.drawPath(edgePath)

        if lod > 0.4:
            self.drawPCRates(painter)
Пример #49
0
class ColorPanel(QGraphicsItem):
    _scaf_colors = styles.SCAF_COLORS
    _stap_colors = styles.STAP_COLORS
    _PEN = Qt.NoPen

    def __init__(self, parent=None):
        super(ColorPanel, self).__init__(parent)
        self.rect = QRectF(0, 0, 30, 30)
        self.setFlag(QGraphicsItem.ItemIgnoresTransformations)
        self.colordialog = QColorDialog()
        # self.colordialog.setOption(QColorDialog.DontUseNativeDialog)
        self._scaf_color_index = -1  # init on -1, painttool will cycle to 0
        self._stap_color_index = -1  # init on -1, painttool will cycle to 0
        self._scaf_color = self._scaf_colors[self._scaf_color_index]
        self._stap_color = self._stap_colors[self._stap_color_index]
        self._scaf_brush = QBrush(self._scaf_color)
        self._stap_brush = QBrush(self._stap_color)
        self._initLabel()
        self.hide()

    def _initLabel(self):
        self._label = label = QGraphicsSimpleTextItem("scaf\nstap", parent=self)
        label.setPos(32, 0)
        label.setFont(_FONT)
        # label.setBrush(_labelbrush)
        # label.hide()

    def boundingRect(self):
        return self.rect

    def paint(self, painter, option, widget=None):
        painter.setPen(self._PEN)
        painter.setBrush(self._scaf_brush)
        painter.drawRect(0, 0, 30, 15)
        painter.setBrush(self._stap_brush)
        painter.drawRect(0, 15, 30, 15)

    def nextColor(self):
        self._stap_color_index += 1
        if self._stap_color_index == len(self._stap_colors):
            self._stap_color_index = 0
        self._stap_color = self._stap_colors[self._stap_color_index]
        self._stap_brush.setColor(self._stap_color)
        self.update()

    def prevColor(self):
        self._stap_color_index -= 1

    def color(self):
        return self._stap_color

    def scafColorName(self):
        return self._scaf_color.name()

    def stapColorName(self):
        return self._stap_color.name()

    def changeScafColor(self):
        self.update()

    def changeStapColor(self):
        self._stap_color = self.colordialog.currentColor()
        self._stap_brush = QBrush(self._stap_color)
        self.update()

    def mousePressEvent(self, event):
        if event.pos().y() < 10:
            new_color = self.colordialog.getColor(self._scaf_color)
            if new_color.isValid() and new_color.name() != self._scaf_color.name():
                self._scaf_color = new_color
                self._scaf_brush = QBrush(new_color)
                if not new_color in self._scaf_colors:
                    self._scaf_colors.insert(self._scaf_color_index, new_color)
                self.update()
        else:
            new_color = self.colordialog.getColor(self._stap_color)
            if new_color.isValid() and new_color.name() != self._stap_color.name():
                self._stap_color = new_color
                self._stap_brush = QBrush(new_color)
                if not new_color in self._stap_colors:
                    self._stap_colors.insert(self._stap_color_index, new_color)
                self.update()
Пример #50
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)
Пример #51
0
class ColorPanel(QGraphicsItem):
    """Summary

    Attributes:
        colordialog (TYPE): Description
        rect (TYPE): Description
    """
    _shift_colors = [getColorObj(x) for x in styles.SCAF_COLORS]
    _colors = [getColorObj(x) for x in styles.STAP_COLORS]
    _PEN = Qt.NoPen

    def __init__(self, parent=None):
        """Summary

        Args:
            parent (None, optional): Description
        """
        super(ColorPanel, self).__init__(parent)
        self.rect = QRectF(0, 0, 30, 30)
        self.setFlag(QGraphicsItem.ItemIgnoresTransformations)
        self.colordialog = QColorDialog()
        self._shift_color_index = -1  # init on -1, painttool will cycle to 0
        self._color_index = -1  # init on -1, painttool will cycle to 0
        self._shift_color = self._shift_colors[self._shift_color_index]
        self._color = self._colors[self._color_index]
        self._shift_brush = QBrush(self._shift_color)
        self._brush = QBrush(self._color)
        self._initLabel()
        self.hide()

    def _initLabel(self):
        """Summary

        Returns:
            TYPE: Description
        """
        self._label = label = QGraphicsTextItem("⇧", parent=self)
        label.setPos(28, -4)
        label.setFont(_FONT)

    def boundingRect(self):
        """Summary

        Returns:
            TYPE: Description
        """
        return self.rect

    def paint(self, painter, option, widget=None):
        """Summary

        Args:
            painter (TYPE): Description
            option (TYPE): Description
            widget (None, optional): Description

        Returns:
            TYPE: Description
        """
        painter.setPen(self._PEN)
        painter.setBrush(self._shift_brush)
        painter.drawRect(0, 0, 30, 15)
        painter.setBrush(self._brush)
        painter.drawRect(0, 15, 30, 15)

    def nextColor(self):
        """Summary

        Returns:
            TYPE: Description
        """
        self._color_index += 1
        if self._color_index == len(self._colors):
            self._color_index = 0
        self._color = self._colors[self._color_index]
        self._brush.setColor(self._color)
        self.update()

    def prevColor(self):
        """Summary

        Returns:
            TYPE: Description
        """
        self._color_index -= 1

    def color(self):
        """Summary

        Returns:
            TYPE: Description
        """
        return self._color

    def shiftColorName(self):
        """Summary

        Returns:
            TYPE: Description
        """
        return self._shift_color.name()

    def colorName(self):
        """Summary

        Returns:
            TYPE: Description
        """
        return self._color.name()

    def mousePressEvent(self, event):
        """Summary

        Args:
            event (QGraphicsSceneMouseEvent): Description

        Returns:
            TYPE: Description
        """
        if event.pos().y() < 10:
            new_color = self.colordialog.getColor(self._shift_color)
            if new_color.isValid() and new_color.name() != self._shift_color.name():
                self._shift_color = new_color
                self._shift_brush = QBrush(new_color)
                if new_color not in self._shift_colors:
                    self._shift_colors.insert(self._shift_color_index, new_color)
                self.update()
        else:
            new_color = self.colordialog.getColor(self._color)
            if new_color.isValid() and new_color.name() != self._color.name():
                self._color = new_color
                self._brush = QBrush(new_color)
                if new_color not in self._colors:
                    self._colors.insert(self._color_index, new_color)
                self.update()
Пример #52
0
class FigLabelWidget(QWidget):
    def __init__(self,parent=None,text='FigLabelWidget'):
        super(FigLabelWidget,self).__init__(parent)
        self.parent=parent
        self.lx=5
        self.text=text
        self.fid=0
        self.stats=None

        self.linecolor=QPalette().light().color()
        self.linecolor.setRgb(157,157,157)
        self.backgroundColor = QPalette().light().color()
        self.backgroundColor.setRgb(187,187,187)
        self.brush=QBrush(Qt.SolidPattern)
        self.brush2=QBrush(Qt.SolidPattern)

        self.activeLabel()

    def paintEvent(self,ev):

        self.brush.setColor(self.linecolor)
        self.painter=QPainter(self)
        self.painter.setRenderHint(QPainter.Antialiasing)
        self.painter.setPen(Qt.NoPen)
        self.painter.setBrush(self.brush)
        self.painter.drawRect(0, 0, self.width(), self.lx)
        self.painter.end()

        #print(1)

        self.painter2=QPainter(self)
        self.painter2.setRenderHint(QPainter.Antialiasing)
        self.painter2.setPen(Qt.NoPen)
        self.painter2.setBrush(self.brush2)
        self.brush2.setColor(self.backgroundColor)
        self.painter2.drawRect(0,self.lx,self.width(),self.height()-self.lx)
        self.painter2.end()

        #print(2)

        self.painter3=QPainter(self)
        self.painter3.drawText(1,self.lx,self.width()-2,self.height()-self.lx,Qt.AlignCenter,self.text)
        self.painter3.end()

        #print(3)
    def activeLabel(self):
        self.stats = 'selected'
        self.linecolor.setRgb(242,146,52)
        self.update()

    def statsReset(self):
        self.stats=None
        self.linecolor.setRgb(157,157,157)
        #print('child reset',self.stats)
        self.update()
    def mousePressEvent(self,ev):
        if self.stats == 'selected' :
            pass
        else:
            self.activeLabel()
            self.parent.activeFig(self.fid)# ##### ##################################            connect to parent

    def enterEvent(self,ev):
        #print('enter')
        if self.stats != 'selected' :
            self.linecolor.setRgb(242,146,52)
            #self.backgroundColor.setRgb(227,227,227)
            self.update()
        
    def leaveEvent(self,ev):
        if self.stats != 'selected' :
            self.linecolor.setRgb(157,157,157)
            #self.backgroundColor.setRgb(187,187,187)
            self.update()
Пример #53
0
class ColorPanel(QGraphicsItem):
    """
    Attributes:
        colordialog (QColorDialog): Description
        rect (QRectF): Description
    """
    _shift_colors = [getColorObj(x) for x in styles.SCAF_COLORS]
    _colors = [getColorObj(x) for x in styles.STAP_COLORS]
    _PEN = Qt.NoPen

    def __init__(self, parent: QGraphicsItem = None):
        """
        Args:
            parent: Default is ``None``
        """
        super(ColorPanel, self).__init__(parent)
        self.rect = QRectF(0, 0, 30, 30)
        self.setFlag(QGraphicsItem.ItemIgnoresTransformations)
        # print("A bug in Qt is about to cause a warning 'Layout still needs update after calling...'")
        # print("Please vote to fix here: https://bugreports.qt.io/browse/QTBUG-58699")
        self.colordialog = QColorDialog()
        self._shift_color_index = -1  # init on -1, painttool will cycle to 0
        self._color_index = -1  # init on -1, painttool will cycle to 0
        self._shift_color = self._shift_colors[self._shift_color_index]
        self._color = self._colors[self._color_index]
        self._shift_brush = QBrush(self._shift_color)
        self._brush = QBrush(self._color)
        self._initLabel()
        self.hide()

    def _initLabel(self):
        """
        """
        self._label = label = QGraphicsTextItem("⇧", parent=self)
        label.setPos(28, -4)
        label.setFont(_FONT)

    def boundingRect(self) -> QRectF:
        """
        Returns:
            :class:`QRectF`
        """
        return self.rect

    def paint(self, painter: QPainter,
                    option: QStyleOptionGraphicsItem,
                    widget: QWidget):
        """
        Args:
            painter: Description
            option: Description
            widget: Description
        """
        painter.setPen(self._PEN)
        painter.setBrush(self._shift_brush)
        painter.drawRect(0, 0, 30, 15)
        painter.setBrush(self._brush)
        painter.drawRect(0, 15, 30, 15)

    def nextColor(self):
        """Increment ``self._color_index``
        """
        self._color_index += 1
        if self._color_index == len(self._colors):
            self._color_index = 0
        self._color = self._colors[self._color_index]
        self._brush.setColor(self._color)
        self.update()

    def prevColor(self):
        """Decrement ``self._color_index``
        """
        self._color_index -= 1

    def color(self) -> QColor:
        """
        Returns:
            :class:`QColor`
        """
        return self._color

    def shiftColorName(self) -> str:
        """
        Returns:
            string name of the color
        """
        return self._shift_color.name()

    def colorName(self) -> str:
        """
        Returns:
            string name of the color
        """
        return self._color.name()

    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """
        Args:
            event: Description
        """
        if event.pos().y() < 10:
            new_color = self.colordialog.getColor(self._shift_color)
            if new_color.isValid() and new_color.name() != self._shift_color.name():
                self._shift_color = new_color
                self._shift_brush = QBrush(new_color)
                if new_color not in self._shift_colors:
                    self._shift_colors.insert(self._shift_color_index, new_color)
                self.update()
        else:
            new_color = self.colordialog.getColor(self._color)
            if new_color.isValid() and new_color.name() != self._color.name():
                self._color = new_color
                self._brush = QBrush(new_color)
                if new_color not in self._colors:
                    self._colors.insert(self._color_index, new_color)
                self.update()
Пример #54
0
    def set_work_traffic(self, id, update=False):
        if self.select_data is None or self.last_id != id or update \
                or self.calendarWidget.selectedDate().month() != self.select_data.month() or self.calendarWidget.selectedDate().year() != self.select_data.year():
            data = self.calendarWidget.selectedDate()
            query = """SELECT staff_worker_traffic.Id, staff_worker_traffic.Position, staff_worker_traffic.Data, staff_worker_traffic.Table_Data, staff_worker_traffic.Note
                          FROM staff_worker_traffic LEFT JOIN staff_worker_info ON staff_worker_traffic.Worker_Id = staff_worker_info.Id
                          WHERE staff_worker_traffic.Worker_Id = %s AND staff_worker_traffic.Data >= %s AND staff_worker_traffic.Data <= %s
                          ORDER BY staff_worker_traffic.Data"""
            sql_param = (id, data.toString("yyyy-MM-01-00-00-00"), data.toString("yyyy-MM-%s-23-59-59" % data.daysInMonth()))
            self.sql_traffic = my_sql.sql_select(query, sql_param)
            if "mysql.connector.errors" in str(type(self.sql_traffic)):
                QMessageBox.critical(self, "Ошибка sql получения записей", self.sql_traffic.msg, QMessageBox.Ok)
                return False

            # Очистим цветные метки
            if self.select_data:
                color = (255, 255, 255)
                color = QColor(color[0], color[1], color[2], 255)
                brush = QBrush()
                brush.setColor(color)
                fomat = QTextCharFormat()
                fomat.setBackground(brush)
                for day in range(1, self.select_data.daysInMonth() + 1):
                    d = QDate(self.select_data.year(), self.select_data.month(), day)
                    self.calendarWidget.setDateTextFormat(d, fomat)

            # Выставим цветные метки
            color_green = QColor(79, 255, 185, 200)
            color_yellow = QColor(230, 245, 95, 200)
            color_red = QColor(245, 110, 95, 200)

            for data in self.sql_traffic:
                if self.calendarWidget.dateTextFormat(data[2]).background().color() == color_yellow:
                    brush = QBrush()
                    brush.setColor(color_green)
                    fomat = QTextCharFormat()
                    fomat.setBackground(brush)
                elif self.calendarWidget.dateTextFormat(data[2]).background().color() == color_green:
                    brush = QBrush()
                    brush.setColor(color_red)
                    fomat = QTextCharFormat()
                    fomat.setBackground(brush)
                else:
                    brush = QBrush()
                    brush.setColor(color_yellow)
                    fomat = QTextCharFormat()
                    fomat.setBackground(brush)

                self.calendarWidget.setDateTextFormat(data[2], fomat)

        if self.calendarWidget.selectedDate() != self.select_data or self.last_id != id or update:

            self.last_id = id
            self.select_data = self.calendarWidget.selectedDate()
            self.tw_traffic.clearContents()
            self.tw_traffic.setRowCount(0)
            for data in self.sql_traffic:
                if data[2].strftime("%d.%m.%Y") == self.select_data.toString("dd.MM.yyyy"):
                    self.tw_traffic.insertRow(self.tw_traffic.rowCount())

                    new_table_item = QTableWidgetItem(str(data[1]))
                    new_table_item.setData(-2, data[0])
                    self.tw_traffic.setItem(self.tw_traffic.rowCount()-1, 0, new_table_item)

                    new_table_item = QTableWidgetItem(data[2].strftime("%d.%m.%Y %H:%M"))
                    new_table_item.setData(-2, data[0])
                    self.tw_traffic.setItem(self.tw_traffic.rowCount()-1, 1, new_table_item)

                    tab_date = data[3].strftime("%d.%m.%Y %H:%M") if data[3] else ""
                    new_table_item = QTableWidgetItem(tab_date)
                    new_table_item.setData(-2, data[0])
                    self.tw_traffic.setItem(self.tw_traffic.rowCount()-1, 2, new_table_item)

                    new_table_item = QTableWidgetItem(data[4])
                    new_table_item.setData(-2, data[0])
                    self.tw_traffic.setItem(self.tw_traffic.rowCount()-1, 3, new_table_item)