Exemplo n.º 1
0
    def init(self):
        mask_brush = QBrush()
        mask_brush.setColor(Qt.gray)
        mask_brush.setStyle(Qt.SolidPattern)
        mask_pen = QPen()
        mask_pen.setColor(Qt.gray)
        self.upper_mask.setBrush(mask_brush)
        self.lower_mask.setBrush(mask_brush)
        self.upper_mask.setPen(mask_pen)
        self.lower_mask.setPen(mask_pen)
        self.addItem(self.upper_mask)
        self.addItem(self.lower_mask)

        font = QFont()
        font.setPointSize(20)
        font.setBold(True)
        self.stage_text_item.setPlainText(self._stage_text % self.stage)
        self.stage_text_item.setFont(font)
        self.stage_text_item.setDefaultTextColor(Qt.black)
        self.stage_text_item.setX(content_width / 2 - int(self.stage_text_item.boundingRect().width() / 2))
        self.stage_text_item.setY(content_height / 2 - int(self.stage_text_item.boundingRect().height() / 2))

        self.animation_timer_1.setInterval(interval)
        self.animation_timer_1.timeout.connect(self.animation_in)

        self.animation_timer_2.setSingleShot(True)
        self.animation_timer_2.timeout.connect(self.animation_hold)
        self.animation_timer_2.setInterval(800)

        self.animation_timer_3.setInterval(interval)
        self.animation_timer_3.timeout.connect(self.animation_out)
    def paint_legend(self, painter, attribute_values, values):
        width = self.width()
        height = self.height()

        # Create Colorbar Legend
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)
        painter.setPen(QPen(Qt.white, 2, Qt.SolidLine))

        for j in range(7):
            text = str(values[6 - j])
            rgb_color = attribute_values.get(6 - j)
            fill_color = QColor(Qt.white)
            fill_color.setRgb(int(rgb_color[0]), int(rgb_color[1]),
                              int(rgb_color[2]))
            brush.setColor(fill_color)

            rect_width = 20
            rect_height = 15
            gap = 15

            # Counts Rectangle and Text Coordinates
            x_point = (4 * width) / 5
            y_point = (height) / 7 + (j + 1) * rect_height + j * gap
            text_x = x_point + rect_width + gap
            text_y = y_point + 10

            # Draw
            rect = QRect(x_point, y_point, rect_width, rect_height)
            painter.fillRect(rect, brush)
            painter.drawText(text_x, text_y, text)

        return
Exemplo n.º 3
0
    def init(self):
        brush = QBrush()
        brush.setColor(Qt.black)
        brush.setStyle(Qt.SolidPattern)
        self.setBackgroundBrush(brush)

        font = QFont()
        font.setPointSize(20)
        font.setBold(True)
        self.one_play_text_item.setPlainText('One Player')
        self.two_plays_text_item.setPlainText('Two Players')
        self.one_play_text_item.setDefaultTextColor(Qt.white)
        self.two_plays_text_item.setDefaultTextColor(Qt.white)
        self.one_play_text_item.setFont(font)
        self.two_plays_text_item.setFont(font)
        self.one_play_text_item.setX(300)
        self.two_plays_text_item.setX(300)
        self.one_play_text_item.setY(self.y_list[0])
        self.two_plays_text_item.setY(self.y_list[1])
        self.addItem(self.one_play_text_item)
        self.addItem(self.two_plays_text_item)

        png = QPixmap()
        png.load('../images/%s' % TankType.PLAYER_ONE.pic)
        png = png.scaled(25, 25)
        self.indicator_item = QGraphicsPixmapItem(png)
        self.indicator_item.setRotation(90)
        self.indicator_item.setX(260)
        self.indicator_item.setY(self.y_list[self.selected] + 8)
        self.addItem(self.indicator_item)
Exemplo n.º 4
0
        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
Exemplo n.º 5
0
    def _updateSignalColor(self, signalName, newColor):
        chIter = QTreeWidgetItemIterator(self.chSelector,
                                        QTreeWidgetItemIterator.Checked)
        while chIter.value():
            if chIter.value().text(0) == signalName:
                sColor = QColor(newColor)
                sColor.setAlpha(100)
                chIter.value().setBackgroundColor(0, sColor)
            chIter += 1

        sIter = QTreeWidgetItemIterator(self.sSelector)
        while sIter.value():
            if sIter.value().text(0) == signalName:
                sColor = QColor(newColor)
                sColor.setAlpha(100)
                sGradient = QLinearGradient(0, 0, 100, 10)
                sGradient.setColorAt(0, sColor)
                sGradient.setColorAt(1, Qt.white)
                sBrush = QBrush(sGradient)
                sBrush.setStyle(Qt.LinearGradientPattern)
                sBrush.setColor(sColor)
                sIter.value().setBackground(0, sBrush)
                if sIter.value() is self.curSelect:
                    self.prevBackGround = sIter.value().background(0)
            sIter += 1

        self.changeCurrentSelect(self.curSelect)
Exemplo n.º 6
0
        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
Exemplo n.º 7
0
 def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     brush = QBrush()
     brush.setColor(self.color)
     brush.setStyle(Qt.SolidPattern)
     rect = QRect(3, 3, -6 + self.width(), -6 + painter.device().height())
     painter.setBrush(brush)
     painter.fillRect(rect, brush)
Exemplo n.º 8
0
def _create_brush(r, g, b, a):
    brush = QBrush()
    brush.setStyle(Qt.SolidPattern)
    color = QColor()
    color.setRed(r)
    color.setGreen(g)
    color.setBlue(b)
    color.setAlpha(a)
    brush.setColor(color)
    return brush
Exemplo n.º 9
0
 def initScene(self):
     brush = QBrush()
     color = QColor()
     color.setGreen(255)
     color.setAlpha(255)
     brush.setColor(color)
     self._label_scene = QGraphicsScene()
     self._label_scene.setBackgroundBrush(grey)
     #self._label_scene.setForegroundBrush(color)
     self.setScene(self._label_scene)
Exemplo n.º 10
0
    def paint(self, painter, option, widget):
        rect = self.boundingRect()
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)
        brush.setColor(self.backColor)
        painter.setBrush(brush)
        painter.drawRect(QRectF(0, 0, self.width, self.height))

        painter.setPen(QPen(Qt.red, 2))
        # painter.drawLine(QPointF(self.width/2, 0), QPointF(self.width/2, self.height))

        painter.drawLine(QPointF(0, self.height / 2),
                         QPointF(self.width, self.height / 2))

        font = painter.font()
        font.setPixelSize(12)
        font.setWeight(QFont.Bold)
        fontMetrics = QFontMetrics(font)
        painter.setFont(font)
        textRect = fontMetrics.boundingRect(str(self.currTime))
        painter.drawText(QPointF(50 + 5, self.height / 2), str(self.currTime))
        painter.setPen(self.linePen)

        # one line after 5 pixels
        startValue = self.currTime
        # origin = (self.width / 2) - (startValue * self.lineSpacing)
        # min = int(startValue - (self.width * .5) / self.lineSpacing)
        # max = int(startValue + (self.width * .5) / self.lineSpacing)

        origin = (self.height / 2) - (startValue * self.lineSpacing)
        min = int(startValue - (self.height * .5) / self.lineSpacing)
        max = int(startValue + (self.height * .5) / self.lineSpacing)

        for i in range(min, max):
            # x1 = x2 = origin + (i * self.lineSpacing)
            # y1 = self.height

            x1 = 0
            y1 = y2 = origin + (i * self.lineSpacing)

            if i % 10 == 0:
                x2 = 40
                if i >= 0:
                    font.setWeight(QFont.Bold)
                    font.setPixelSize(10)
                    painter.setFont(font)
                    painter.drawText(self.width - 20, y1, f'{i}')
            elif i % 5 == 0:
                x2 = 25
            else:
                x2 = 13
            if i >= 0:
                painter.drawLine(x1, y1, x2, y2)
                print(x2, y2)
Exemplo n.º 11
0
 def addPoint(self, index, x, y):
     brush = QBrush()
     brush.setStyle(Qt.SolidPattern)  # 实心填充模式
     if index == 0:
         brush.setColor(self.point_color[0])
     else:
         i = (index - 1) // 4 + 1
         brush.setColor(self.point_color[i])
     lx, ly = self.center2LeftTop(x, y)
     self.current_point = self.addEllipse(lx, ly, self.wh, self.wh, self.pen, brush)
     self.points_list.append(self.current_point)
Exemplo n.º 12
0
 def resolveFillColor(self):
     brush = QBrush()
     if self.isCurrent == True:
         brush.setColor(self.currentStateFillQColor)
         brush.setStyle(Qt.SolidPattern)
         self.currentFill = self.currentStateFillQColor
     else:
         brush.setColor(self.fillQColor)
         brush.setStyle(Qt.SolidPattern)
         self.currentFill = self.fillQColor
     self.border.setBrush(brush)
     self.update()
Exemplo n.º 13
0
 def __init__(self, stage=1):
     super().__init__()
     self.stage = stage
     self.started = False
     self.tank1 = TankItem(TankType.PLAYER_ONE, Direction.UP)
     self.tank2 = TankItem(TankType.PLAYER_TWO, Direction.UP)
     self.enemies = []
     self.terrain_map = generate_random_map(columns, rows)
     self.draw_terrain(self.terrain_map)
     brush = QBrush()
     brush.setColor(Qt.black)
     brush.setStyle(Qt.SolidPattern)
     self.setBackgroundBrush(brush)
Exemplo n.º 14
0
    def backgroundRole(self, index, role):
        r = self.toolsInputs[index.row()].get(
            self.attributeNameKeys[index.column()], None)
        if r:
            # if r.GetAttrs('INPB_Connected'):
            b = QBrush()
            b.setStyle(Qt.SolidPattern)
            if r.attributes.get("INPID_InputControl", None) == "SplineControl":
                b.setColor(QColor(180, 64, 92, 64))
                return b
            if r.GetExpression():
                b.setColor(QColor(92, 64, 92, 180))
                return b
            if r.GetAttrs("INPB_Connected"):
                # keyFrames = r.GetKeyFrames()
                # b = QBrush()
                # b.setStyle(Qt.Dense4Pattern)
                # b.setStyle(Qt.SolidPattern)
                # print(keyFrames)
                # print(comp.CurrentTime, r.keyFrames.values())
                if comp.CurrentTime in list(r.keyFrames.values()):
                    b.setColor(QColor(62, 92, 62, 180))
                else:
                    b.setColor(QColor(64, 78, 120, 180))

                # return QColor('green')
                return b
        return None
Exemplo n.º 15
0
 def paint(self, painter: QPainter, styleOption: QStyleOptionGraphicsItem, widget: QWidget=None):
     pen = QPen()
     pen.setWidthF(0.05)
     pen.setColor(Qt.darkGray)
     painter.setPen(pen)
     brush = QBrush()
     brush.setColor(self.color)
     brush.setStyle(Qt.SolidPattern)
     painter.setBrush(brush)
     topLeft = QPointF(0, 0)
     bottomRight = QPointF(1, 1)
     rectangle = QRectF(topLeft, bottomRight)
     rectangle.translate(-0.5, -0.5)
     painter.drawRect(rectangle)
Exemplo n.º 16
0
 def dibujarPuntos(self):
     pen = QPen()
     brush = QBrush()
     pen.setWidth(3)
     self.obtenerPuntos()
     for particula in self.particulas:
         color = QColor(particula.color.r, particula.color.g,
                        particula.color.b)
         pen.setColor(color)
         brush.setColor(color)
         brush.setStyle(Qt.SolidPattern)
         self.scene.addEllipse(particula.origen.x, particula.origen.y, 6, 6,
                               pen, brush)
         self.scene.addEllipse(particula.destino.x, particula.destino.y, 6,
                               6, pen, brush)
Exemplo n.º 17
0
class FolderList(QListView):
    def __init__(self):
        super().__init__()
        # Objects
        self.brush          = QBrush()
        self.folderModel    = QStandardItemModel()

        # Styling
        self.setModel(self.folderModel)
        self.setFrameStyle(QFrame.NoFrame)
        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setItemDelegate(ListDelegate.ListDelegate())
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.brush.setColor(ThemeManager.BG_QC)
        self.brush.setStyle(Qt.SolidPattern)

        self.populate()

    def populate(self):
        for idx, folder in enumerate(self.getImageFolders()):
            item = QStandardItem(folder)
            item.setData(folder.replace('imgur', '').replace('reddit_sub', '').replace('_', ''), role=Qt.DisplayRole)
            item.setData(folder, role=Qt.DisplayRole)
            item.setData(os.path.join(ThemeManager.IMAGE_FOLDERS_PATH, folder), role=Qt.UserRole)
            item.setData(folder, role=Qt.UserRole+1)

            self.folderModel.appendRow(item)

    def getImageFolders(self):
        contents = map(lambda f: f.name, os.scandir(ThemeManager.IMAGE_FOLDERS_PATH))
        yield from filter(lambda f: os.path.isdir(os.path.join(ThemeManager.IMAGE_FOLDERS_PATH, f)), contents)

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            index = self.indexAt(event.pos())
            if index.isValid():
                self.selectedFolderChanged.emit(index)

    def paintEvent(self, event):
        painter = QPainter(self.viewport())
        painter.setBrush(self.brush)
        painter.setPen(Qt.NoPen)
        painter.drawRect(event.rect())
        super().paintEvent(event)

    selectedFolderChanged = Signal(object)
Exemplo n.º 18
0
 def paint(self,
           painter: QPainter,
           styleOption: QStyleOptionGraphicsItem,
           widget: QWidget = None):
     pen = QPen()
     pen.setWidthF(0.05)
     pen.setColor(Qt.darkGray)
     painter.setPen(pen)
     brush = QBrush()
     brush.setColor(self.color)
     brush.setStyle(Qt.SolidPattern)
     painter.setBrush(brush)
     topLeft = QPointF(0, 0)
     bottomRight = QPointF(1, 1)
     rectangle = QRectF(topLeft, bottomRight)
     rectangle.translate(-0.5, -0.5)
     painter.drawRect(rectangle)
Exemplo n.º 19
0
    def paint(self, painter, option, widget):
        rect = self.boundingRect()
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)
        brush.setColor(Qt.lightGray)
        painter.setBrush(brush)
        painter.drawRect(QRectF(0, 0, self.width, self.height))

        painter.setPen(QPen(Qt.red, 2))
        painter.drawLine(QPointF(self.width / 2, 0),
                         QPointF(self.width / 2, self.height))

        font = painter.font()
        font.setPixelSize(12)
        font.setWeight(QFont.Bold)
        fontMetrics = QFontMetrics(font)
        painter.setFont(font)
        textRect = fontMetrics.boundingRect(str(self.currTime))
        painter.drawText(self.width / 2 - (textRect.width() / 2), 65,
                         str(self.currTime))
        painter.setPen(QPen(Qt.black, 1))

        # one line after 5 pixels
        startValue = self.currTime
        origin = (self.width / 2) - (startValue * self.lineDistance)
        min = int(startValue - (self.width * .5) / self.lineDistance)
        max = int(startValue + (self.width * .5) / self.lineDistance)

        for i in range(min, max):
            x1 = x2 = origin + (i * self.lineDistance)
            y1 = self.height

            if i % 10 == 0:
                y2 = 10
                if i >= 0:
                    font.setWeight(QFont.Bold)
                    font.setPixelSize(10)
                    painter.setFont(font)
                    painter.drawText(x1, 10, f'{i}')
            elif i % 5 == 0:
                y2 = 25
            else:
                y2 = 37
            if i >= 0:
                painter.drawLine(x1, y1, x2, y2)
Exemplo n.º 20
0
    def paint(self, painter, option, index):
        # data is our status dict, containing progress, id, status
        job_id, data = index.model().data(index, Qt.DisplayRole)
        if data["progress"] > 0:
            color = QColor(STATUS_COLORS[data["status"]])

            brush = QBrush()
            brush.setColor(color)
            brush.setStyle(Qt.SolidPattern)

            width = option.rect.width() * data["progress"] / 100

            rect = QRect(option.rect)  #  Copy of the rect, so we can modify.
            rect.setWidth(width)

            painter.fillRect(rect, brush)

        pen = QPen()
        pen.setColor(Qt.black)
        painter.drawText(option.rect, Qt.AlignLeft, job_id)
Exemplo n.º 21
0
    def draw_square(self, painter=QPainter):
        brush = QBrush()
        # background
        brush.setStyle(Qt.SolidPattern)
        brush.setColor(self._model["bgColor"])
        painter.setBrush(brush)
        painter.drawRect(self.boundingRect())

        # Highlighted
        painter.setPen(Qt.NoPen)
        if self._highlight:
            brush.setStyle(Qt.SolidPattern)
            # brush.setColor(QColor(192,255,0))
            brush.setColor(QColor(255, 0, 0))
        else:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(224, 224, 224))
        boundry = self.boundingRect()
        boundry.setTopRight(boundry.topLeft() + QPointF(4.0, 0))
        boundry.setBottomRight(boundry.bottomLeft() + QPointF(4.0, 0))
        painter.setBrush(brush)
        painter.drawRect(boundry)

        boundry = self.boundingRect()
        boundry.setTopLeft(boundry.topRight() - QPointF(4.0, 0))
        boundry.setBottomLeft(boundry.bottomRight() - QPointF(4.0, 0))
        painter.setBrush(brush)
        painter.drawRect(boundry)
Exemplo n.º 22
0
    def paint(self, painter, option, widget):
        rect = self.boundingRect()

        # print(rect)
        # if self.pressed:
        #   pen = QPen(Qt.red, 3)
        #   painter.setPen(pen)
        #   painter.drawEllipse(rect)           
        # else:
        pen = QPen(Qt.black, 3)
        font = painter.font()
        font.setPixelSize(12)
        painter.setFont(font)
        painter.setPen(pen)
        painter.drawRect(rect)
        painter.drawText(self.startX+5, self.startY+20, f'Slot-{self.text}')
        # Draw a LED at right corner
        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)
        if self.slotId % 3 == 0:
            brush.setColor(Qt.red)
        elif self.slotId % 2 == 0:
            brush.setColor(Qt.green)
        else:
            brush.setColor(Qt.cyan)

        # brush.setColor(Qt.red)
        painter.setBrush(brush)
        pen = QPen()
        pen.setWidth(1)
        pen.setColor(Qt.blue)
        painter.setPen(pen)
        painter.drawEllipse(self.startX+5+80, self.startY+5, 10, 10)
Exemplo n.º 23
0
    def dibujar(self):
        pen = QPen()
        brush = QBrush()
        pen.setWidth(3)

        for i in self.organizador:
            color = QColor(i.red, i.green, i.blue)
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(color)
            pen.setColor(color)

            self.scene.addEllipse(i.or_x, i.or_y, 7, 7, pen, brush)
            self.scene.addEllipse(i.de_x, i.de_y, 7, 7, pen, brush)
            self.scene.addLine((i.or_x) + 3.5, (i.or_y) + 3.5, (i.de_x) + 3.5,
                               (i.de_y) + 3.5, pen)

        for keys in self.organizador.grafo_dic:
            text = QGraphicsTextItem(str(keys))
            text.setFlag(QGraphicsItem.ItemIsMovable)
            text.setFont(QFont("TimesNewRoman", 12, QFont.ExtraBold))
            self.scene.addItem(text)
            text.setPos(keys[0], keys[1])
Exemplo n.º 24
0
        def __init__(self, tetris: Tetris):
            super(QTetris.QScene, self).__init__()
            self.tetris = tetris

            pen = QPen()
            pen.setWidthF(0.05)
            pen.setColor(Qt.lightGray)
            brush = QBrush(Qt.NoBrush)
            rect = QRectF(0, 0, tetris.num_rows, tetris.num_columns)
            rect.translate(-0.5, -0.5)
            self.setSceneRect(rect)
            self.addRect(rect, pen, brush)
            self.setBackgroundBrush(self.palette().window())

            for column in range(0, tetris.num_columns, 2):
                pen = QPen(Qt.NoPen)
                brush = QBrush(Qt.SolidPattern)
                brush.setColor(Qt.lightGray)
                topLeft = QPointF(0, column)
                bottomRight = QPointF(tetris.num_rows, column + 1)
                rectangle = QRectF(topLeft, bottomRight)
                rectangle.translate(-0.5, -0.5)
                self.addRect(rectangle, pen, brush)
Exemplo n.º 25
0
        def __init__(self, tetris: Tetris):
            super(QTetris.QScene, self).__init__()
            self.tetris = tetris

            pen = QPen()
            pen.setWidthF(0.05)
            pen.setColor(Qt.lightGray)
            brush = QBrush(Qt.NoBrush)
            rect = QRectF(0, 0, tetris.num_rows, tetris.num_columns)
            rect.translate(-0.5, -0.5)
            self.setSceneRect(rect)
            self.addRect(rect, pen, brush)
            self.setBackgroundBrush(self.palette().window())

            for column in range(0, tetris.num_columns, 2):
                pen = QPen(Qt.NoPen)
                brush = QBrush(Qt.SolidPattern)
                brush.setColor(Qt.lightGray)
                topLeft = QPointF(0, column)
                bottomRight = QPointF(tetris.num_rows, column + 1)
                rectangle = QRectF(topLeft, bottomRight)
                rectangle.translate(-0.5, -0.5)
                self.addRect(rectangle, pen, brush)
Exemplo n.º 26
0
    def paintEvent(self, _):
        """
        Paints the widget contents
        """
        painter = QPainter(self)

        device = painter.device()

        optimal_vertical_tile_size = device.height() // self.model.height
        optimal_horizontal_tile_size = device.width() // self.model.width

        tile_size = min(optimal_vertical_tile_size,
                        optimal_horizontal_tile_size)

        brush = QBrush()
        brush.setStyle(Qt.SolidPattern)

        for pos in self.model.all_positions():
            block = self.model.state[pos]

            if block is Block.EMPTY:
                continue
            if not block.visible:
                continue

            r, g, b = block.color
            q_color = QColor(r, g, b)
            brush.setColor(q_color)

            x, y = pos
            canvas_x = self.START_X + tile_size * x
            canvas_y = self.START_Y + tile_size * y

            rect = QRect(canvas_x, canvas_y, tile_size, tile_size)
            painter.fillRect(rect, brush)

        painter.end()
Exemplo n.º 27
0
class ImageList(QListView):
    def __init__(self, model=None):
        super().__init__()
        # Objects
        self.brush = QBrush()

        # Styling
        if model: self.setModel(model)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setFrameStyle(QFrame.NoFrame)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setItemDelegate(Thumbnail())
        self.brush.setColor(ThemeManager.BG_QC)
        self.brush.setStyle(Qt.SolidPattern)

    def populate(self, folder):
        self.populateThread = Populate(folder)
        self.populateThread.modelFinished.connect(self.setModel)
        self.populateThread.start()

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            index = self.indexAt(event.pos())
            self.selectedImageChanged.emit(index)

    def paintEvent(self, event):
        painter = QPainter(self.viewport())
        painter.setBrush(self.brush)
        painter.setPen(Qt.NoPen)
        painter.drawRect(event.rect())
        super().paintEvent(event)

    selectedImageChanged = Signal(object)
Exemplo n.º 28
0
    def draw_plus(self, painter=QPainter):
        brush = QBrush()
        # Highlighted
        painter.setPen(Qt.NoPen)
        if self._highlight:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(255, 0, 0))
        else:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(224, 224, 224))
        boundry = self.boundingRect()
        painter.setBrush(brush)
        path = QPainterPath()
        widthSec = boundry.width() / 3
        heightSec = boundry.height() / 3
        path.moveTo(widthSec, 0)
        path.lineTo(widthSec * 2, 0)
        path.lineTo(widthSec * 2, heightSec)
        path.lineTo(widthSec * 3, heightSec)
        path.lineTo(widthSec * 3, heightSec * 2)
        path.lineTo(widthSec * 2, heightSec * 2)
        path.lineTo(widthSec * 2, heightSec * 3)
        path.lineTo(widthSec, heightSec * 3)
        path.lineTo(widthSec, heightSec * 2)
        path.lineTo(0, heightSec * 2)
        path.lineTo(0, heightSec)
        path.lineTo(widthSec, heightSec)
        path.lineTo(widthSec, 0)
        painter.drawPath(path)

        # background
        brush.setColor(self._model["bgColor"])
        painter.setBrush(brush)
        offset = 4
        path = QPainterPath()
        widthSec = boundry.width() / 3
        heightSec = boundry.height() / 3
        path.moveTo(widthSec + offset, 0 + offset)
        path.lineTo((widthSec * 2) - offset, 0 + offset)
        path.lineTo((widthSec * 2) - offset, heightSec + offset)
        path.lineTo((widthSec * 3) - offset, heightSec + offset)
        path.lineTo((widthSec * 3) - offset, (heightSec * 2) - offset)
        path.lineTo((widthSec * 2) - offset, (heightSec * 2) - offset)
        path.lineTo((widthSec * 2) - offset, (heightSec * 3) - offset)
        path.lineTo(widthSec + offset, (heightSec * 3) - offset)
        path.lineTo(widthSec + offset, (heightSec * 2) - offset)
        path.lineTo(0 + offset, (heightSec * 2) - offset)
        path.lineTo(0 + offset, heightSec + offset)
        path.lineTo(widthSec + offset, heightSec + offset)
        path.lineTo(widthSec + offset, 0 + offset)
        painter.drawPath(path)
Exemplo n.º 29
0
    def draw_circle(self, painter=QPainter):
        brush = QBrush()
        # Highlighted
        painter.setPen(Qt.NoPen)
        if self._highlight:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(255, 0, 0))
        else:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(224, 224, 224))
        boundry = self.boundingRect()
        painter.setBrush(brush)
        painter.drawEllipse(boundry)

        # background
        brush.setColor(self._model["bgColor"])
        painter.setBrush(brush)
        boundry = self.boundingRect()
        offset = 2
        painter.drawEllipse(boundry.x() + offset,
                            boundry.y() + offset,
                            boundry.width() - (offset * 2),
                            boundry.height() - (offset * 2))
Exemplo n.º 30
0
    def draw_triangle(self, painter=QPainter):
        brush = QBrush()
        # Highlighted
        painter.setPen(Qt.NoPen)
        if self._highlight:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(255, 0, 0))
        else:
            brush.setStyle(Qt.SolidPattern)
            brush.setColor(QColor(224, 224, 224))
        boundry = self.boundingRect()
        painter.setBrush(brush)
        path = QPainterPath()
        p1 = QPointF(boundry.center().x(), 0)
        p2 = QPointF(boundry.width(), boundry.height())
        p3 = QPointF(0, boundry.height())
        path.moveTo(p1)
        path.lineTo(p2)
        path.lineTo(p3)
        path.lineTo(p1)
        painter.drawPath(path)

        # background
        brush.setColor(self._model["bgColor"])
        painter.setBrush(brush)
        percentage = 8
        wOffset = (percentage * boundry.width()) / 100
        hOffset = (percentage * boundry.height()) / 100
        path = QPainterPath()
        p1 = QPointF(boundry.center().x(), hOffset)
        p2 = QPointF(boundry.width() - wOffset, boundry.height() - hOffset)
        p3 = QPointF(wOffset, boundry.height() - hOffset)
        path.moveTo(p1)
        path.lineTo(p2)
        path.lineTo(p3)
        path.lineTo(p1)
        painter.drawPath(path)
Exemplo n.º 31
0
 def paint(self, painter, styleoptions, parent=None):
     brush = QBrush()
     brush.setColor(self.color)
     painter.setBrush(self.color)
     painter.drawRect(self._bounding_rect)
Exemplo n.º 32
0
import PySide2
from PySide2.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsRectItem
from PySide2.QtCore import QRect, Qt
from PySide2.QtGui import QBrush, QPixmap
import matplotlib.pyplot as plt
from Globals import *

brushHead = QBrush()
brushHead.setStyle(Qt.SolidPattern)
brushHead.setColor(Qt.darkGreen)

brushBody = QBrush()
brushBody.setStyle(Qt.SolidPattern)
brushBody.setColor(Qt.green)

brushGoal = QBrush()
brushGoal.setStyle(Qt.SolidPattern)
brushGoal.setColor(Qt.red)


class GameWindow(QGraphicsView):
    def __init__(self, parent=None):
        super(GameWindow, self).__init__(parent=parent)
        self.screen = None
        self.scene = QGraphicsScene()
        self.scene.setSceneRect(
            QRect(left=0,
                  top=0,
                  width=PLAYGROUND_SIZEX * SCALE_FACTORX,
                  height=PLAYGROUND_SIZEY * SCALE_FACTORY))
        self.setFrameStyle(4)
Exemplo n.º 33
0
    def _updateAll(self, newGroup=None):
        try:
            self.chSelector.itemChanged.disconnect(self.itemChanged)
            self.sSelector.itemChanged.disconnect(self.itemChanged)
        except:
            pass
        if newGroup == '':
            return
        
        chStruct = self.chartData[newGroup]
        sStruct = self.chartData[newGroup].getColStructure()
        
        self.chSelector.clear()
        for ws in chStruct:
            gparent = QTreeWidgetItem(self.chSelector)
            gparent.setText(0, ws)
            gparent.setBackgroundColor(0, Qt.white)
            gparent.setFlags(Qt.ItemIsEnabled)
            for key in chStruct[ws]:
                parent = QTreeWidgetItem(gparent)
                parent.setText(0, key)
                if chStruct[ws][key][0] == True:
                    dataNames = chStruct[ws][key][3]
                    sColor = QColor(chStruct[ws][key][4])
                    sColor.setAlpha(100)
                    parent.setBackgroundColor(0, sColor)
                else:
                    dataNames = ','.join(chStruct[ws][key][2])
                    sColor = QColor(chStruct[ws][key][3])
                    sColor.setAlpha(100)
                    parent.setBackgroundColor(0, sColor)
                    
                parent.setText(1, dataNames)
                if chStruct[ws][key][1] == True:
                    parent.setCheckState(0, Qt.Checked)
                else:
                    parent.setCheckState(0, Qt.Unchecked)
                parent.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
        
        self.sSelector.clear()
        self.gSelector.clear()
        for ws in sStruct:
            firstChannel = sStruct[ws][0]
            isOneSignal = self.chartData[newGroup][firstChannel][ws][0]
            if isOneSignal:
                gparent = QTreeWidgetItem(self.sSelector)
                gparent.setText(0, ws)
                gparent.setFlags(Qt.ItemIsEnabled | Qt.ItemIsDragEnabled
                                 | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable)
                if True:
##                if chStruct['CH1'][ws][5] == True:
                    gparent.setCheckState(0, Qt.Checked) 
                else:
                    gparent.setCheckState(0, Qt.Unchecked)
                    
                for key in sStruct[ws]:
                    parent = QTreeWidgetItem(gparent)
                    parent.setText(0, key)
                    if chStruct[key][ws][2] == True:
                        parent.setCheckState(0, Qt.Checked)
                    else:
                        parent.setCheckState(0, Qt.Unchecked)
                    parent.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                    sColor = QColor(chStruct[key][ws][4])
                    sColor.setAlpha(100)
                    sGradient = QLinearGradient(0, 0, 100, 10)
                    sGradient.setColorAt(0, sColor)
                    sGradient.setColorAt(1, Qt.white)
                    sBrush = QBrush(sGradient)
                    sBrush.setStyle(Qt.LinearGradientPattern)
                    sBrush.setColor(sColor)
                    gparent.setBackground(0, sBrush)
                    
            else:
                gparent = QTreeWidgetItem(self.gSelector)
                gparent.setText(0, ws)
                gparent.setFlags(Qt.ItemIsEnabled | Qt.ItemIsDropEnabled
                                 | Qt.ItemIsUserCheckable)
                if chStruct['CH1'][ws][5] == True:
                    gparent.setCheckState(0, Qt.Checked)
                else:
                    gparent.setCheckState(0, Qt.Unchecked)
                
                signalNames = chStruct[key][ws][2]
                sColor = QColor(chStruct[key][ws][3])
                sColor.setAlpha(100)
                gparent.setBackgroundColor(0, sColor)
                for signal in signalNames:
                    parent = QTreeWidgetItem(gparent)
                    parent.setText(0, signal)
                    parent.setFlags(Qt.ItemIsEnabled)

                    for key in sStruct[signal]:
                        sColor = QColor(chStruct[key][signal][4])
                        sColor.setAlpha(100)
                        parent.setBackgroundColor(0, sColor)
                        break                   
            
        self.chSelector.itemChanged.connect(self.itemChanged)
        self.sSelector.itemChanged.connect(self.itemChanged)
        self.curSelect = None