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
Ejemplo n.º 2
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
Ejemplo 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)
Ejemplo n.º 4
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
Ejemplo 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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def main(argv):
    app = QApplication(argv)

    scene = QGraphicsScene(0, 0, 500, 500)
    scene.setItemIndexMethod(QGraphicsScene.NoIndex)

    brush = QBrush(Qt.red)

    brush_brics = QBrush(QPixmap('brick_texture.jpg'))
    brush_brics.setStyle(Qt.TexturePattern)

    pen = QPen()
    pen.setWidth(5)
    pen.setStyle(Qt.DashLine)

    rectItem = RectItem('r1', 20, 10, 200, 100)
    rectItem.setBrush(brush)

    rectItem2 = RectItem('r2', 20, 10, 150, 250)
    rectItem2.setPen(pen)
    rectItem2.setBrush(brush_brics)
    rectItem2.setOpacity(70)
    arrowItem = ArrowItem(QLine(50, 200, 300, 400))
    scene.addItem(arrowItem)
    scene.addItem(rectItem)
    scene.addItem(rectItem2)

    view = QGraphicsView(scene)
    view.show()

    return app.exec_()
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def getBrushFromCmnd(self, brushinfo):
        '''
        Returns a QBrush based on the information in the dictionary
        brushinfo.  A ValueError is raised if the value for the
        "style" key, if given, is not recognized.

        Recognized keys in the fill dictionary are:
            "color": color name or 24-bit RGB integer value
                         (eg, 0xFF0088)
            "alpha": alpha value from 0 (transparent) to 255 (opaque)
            "style": brush style name ("solid", "dense1" to "dense7",
                         "none", "hor", "ver", "cross",
                         "bdiag", "fdiag", "diagcross")
        '''
        try:
            mycolor = self.getColorFromCmnd(brushinfo)
            mybrush = QBrush(mycolor)
        except KeyError:
            mybrush = QBrush()
        try:
            mystyle = brushinfo["style"]
            if mystyle == "solid":
                mystyle = Qt.SolidPattern
            elif mystyle == "dense1":
                mystyle = Qt.Dense1Pattern
            elif mystyle == "dense2":
                mystyle = Qt.Dense2Pattern
            elif mystyle == "dense3":
                mystyle = Qt.Dense3Pattern
            elif mystyle == "dense4":
                mystyle = Qt.Dense4Pattern
            elif mystyle == "dense5":
                mystyle = Qt.Dense5Pattern
            elif mystyle == "dense6":
                mystyle = Qt.Dense6Pattern
            elif mystyle == "dense7":
                mystyle = Qt.Dense7Pattern
            elif mystyle == "none":
                mystyle = Qt.NoBrush
            elif mystyle == "hor":
                mystyle = Qt.HorPattern
            elif mystyle == "ver":
                mystyle = Qt.VerPattern
            elif mystyle == "cross":
                mystyle = Qt.CrossPattern
            elif mystyle == "bdiag":
                mystyle = Qt.BDiagPattern
            elif mystyle == "fdiag":
                mystyle = Qt.FDiagPattern
            elif mystyle == "diagcross":
                mystyle = Qt.DiagCrossPattern
            else:
                raise ValueError("Unknown brush style '%s'" % str(mystyle))
            mybrush.setStyle(mystyle)
        except KeyError:
            pass
        return mybrush
Ejemplo n.º 11
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)
Ejemplo n.º 12
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
Ejemplo n.º 13
0
    def test_no_brush(self, p, opd):
        brush = QBrush()
        brush.setStyle(Qt.BrushStyle.NoBrush)
        pen = QPen()
        pen.setBrush(brush)
        p.setPen(pen)

        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(10, 20)
        p.drawPath(path)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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)
Ejemplo n.º 16
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()
Ejemplo n.º 17
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)
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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)
Ejemplo n.º 21
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)
Ejemplo n.º 22
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)
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
    def test_colours(self, p, opd):
        p.setPen(QColor(255, 0, 0))
        path = QPainterPath()
        path.moveTo(0, 0)
        path.lineTo(10, 0)
        p.drawPath(path)

        p.setPen(QColor(0, 255, 0))
        path = QPainterPath()
        path.moveTo(0, 10)
        path.lineTo(10, 10)
        p.drawPath(path)

        p.setPen(QColor(0, 0, 255))
        path = QPainterPath()
        path.moveTo(0, 20)
        path.lineTo(10, 20)
        p.drawPath(path)

        p.setPen(QColor(0, 0, 0, 128))
        path = QPainterPath()
        path.moveTo(0, 30)
        path.lineTo(10, 30)
        p.drawPath(path)

        # Non-solid brush (colour should be nullified)
        brush = QBrush()
        brush.setStyle(Qt.BrushStyle.CrossPattern)
        pen = QPen()
        pen.setBrush(brush)
        p.setPen(pen)
        path = QPainterPath()
        path.moveTo(0, 40)
        path.lineTo(10, 40)
        p.drawPath(path)

        assert opd.getOutlines() == [
            ((1.0, 0.0, 0.0, 1.0), 0.1, [(0.0, 0.0), (1.0, 0.0)]),
            ((0.0, 1.0, 0.0, 1.0), 0.1, [(0.0, 1.0), (1.0, 1.0)]),
            ((0.0, 0.0, 1.0, 1.0), 0.1, [(0.0, 2.0), (1.0, 2.0)]),
            ((0.0, 0.0, 0.0, 128 / 255.), 0.1, [(0.0, 3.0), (1.0, 3.0)]),
            (None, 0.1, [(0.0, 4.0), (1.0, 4.0)]),
        ]
Ejemplo n.º 25
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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
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])
Ejemplo n.º 28
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))
Ejemplo n.º 29
0
    def set_palette(self):
        # Brush
        gray_text = QBrush(QColor(171, 171, 171, 255))
        gray_text.setStyle(Qt.SolidPattern)
        black_background = QBrush(QColor(0, 0, 0, 255))
        black_background.setStyle(Qt.SolidPattern)

        self.orientation_label_palette = QPalette()
        self.orientation_label_palette.setBrush(QPalette.Active,
                                                QPalette.WindowText, gray_text)
        self.orientation_label_palette.setBrush(QPalette.Inactive,
                                                QPalette.WindowText, gray_text)
        self.orientation_label_palette.setBrush(QPalette.Disabled,
                                                QPalette.WindowText, gray_text)
        self.ortho_viewer_palette = QPalette()
        self.ortho_viewer_palette.setBrush(QPalette.Active, QPalette.Base,
                                           black_background)
        self.ortho_viewer_palette.setBrush(QPalette.Inactive, QPalette.Base,
                                           black_background)
        self.ortho_viewer_palette.setBrush(QPalette.Disabled, QPalette.Base,
                                           black_background)

        self.axialA_label.setPalette(self.orientation_label_palette)
        self.axialL_label.setPalette(self.orientation_label_palette)
        self.axialR_label.setPalette(self.orientation_label_palette)
        self.axialP_label.setPalette(self.orientation_label_palette)
        self.axial_view.setPalette(self.ortho_viewer_palette)
        self.sagittalS_label.setPalette(self.orientation_label_palette)
        self.sagittalA_label.setPalette(self.orientation_label_palette)
        self.sagittalI_label.setPalette(self.orientation_label_palette)
        self.sagittalP_label.setPalette(self.orientation_label_palette)
        self.sagittal_view.setPalette(self.ortho_viewer_palette)
        self.coronalL_label.setPalette(self.orientation_label_palette)
        self.coronalS_label.setPalette(self.orientation_label_palette)
        self.coronalR_label.setPalette(self.orientation_label_palette)
        self.coronalI_label.setPalette(self.orientation_label_palette)
        self.coronal_view.setPalette(self.ortho_viewer_palette)
Ejemplo 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)
Ejemplo n.º 31
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()
Ejemplo n.º 32
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)