Python PyQt4.QtGui.QBrush() Examples

The following are 24 code examples of PyQt4.QtGui.QBrush(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt4.QtGui , or try the search function .
Example #1
Source File: cityscapesLabelTool.py    From fcn8s_tensorflow with GNU General Public License v3.0 6 votes vote down vote up
def drawPoint(self, qp, pt, isFirst, increaseRadius):
        # The first in green
        if isFirst:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(0,255,0),QtCore.Qt.SolidPattern))
        # Other in red
        else:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(255,0,0),QtCore.Qt.SolidPattern))

        # Standard radius
        r = 3.0
        # Increase maybe
        if increaseRadius:
            r *= 2.5
        # Draw
        qp.drawEllipse( pt, r, r )

    # Determine if the given candidate for a label path makes sense 
Example #2
Source File: pressure.py    From wacom-gui with GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.setRenderHints(QtGui.QPainter.Antialiasing)

        painter.fillRect(QtCore.QRectF(50, 50, 200, 200), QtGui.QBrush(QtGui.QColor(QtGui.QColor(110, 110, 110))))
        painter.fillRect(QtCore.QRectF(50, 50, 200, 200), QtGui.QBrush(QtCore.Qt.CrossPattern))

        painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.lightGray), 2, QtCore.Qt.SolidLine))
        path = QtGui.QPainterPath()
        path.moveTo(50, 250)
        path.cubicTo(self.points[0][0], self.points[0][1], self.points[1][0], self.points[1][1], 250, 50)
        painter.drawPath(path)

        painter.setBrush(QtGui.QBrush(QtGui.QColor(QtCore.Qt.darkCyan)))
        painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.lightGray), 1))


        #for x, y in pts:
        painter.drawEllipse(QtCore.QRectF(self.points[0][0] - 4, self.points[0][1] - 4, 8, 8))
        painter.drawEllipse(QtCore.QRectF(self.points[1][0] - 4, self.points[1][1] - 4, 8, 8))
        painter.setPen(QtGui.QPen(QtGui.QColor(QtCore.Qt.white), 1))
        label1 = "("+ str((self.points[0][0] - 50)/2) + "," + str(100 - ((self.points[0][1] -50)/2)) + ")"
        painter.drawText(self.points[0][0] -25, self.points[0][1] + 18, QtCore.QString(label1))
        label2 = "("+ str((self.points[1][0] - 50)/2) + "," + str(100 - ((self.points[1][1] -50)/2)) + ")"
        painter.drawText(self.points[1][0] -25, self.points[1][1] + 18, QtCore.QString(label2)) 
Example #3
Source File: cityscapesLabelTool.py    From Detectron-PYTORCH with Apache License 2.0 6 votes vote down vote up
def drawPoint(self, qp, pt, isFirst, increaseRadius):
        # The first in green
        if isFirst:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(0,255,0),QtCore.Qt.SolidPattern))
        # Other in red
        else:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(255,0,0),QtCore.Qt.SolidPattern))

        # Standard radius
        r = 3.0
        # Increase maybe
        if increaseRadius:
            r *= 2.5
        # Draw
        qp.drawEllipse( pt, r, r )

    # Determine if the given candidate for a label path makes sense 
Example #4
Source File: PlotWindow.py    From qkit with GNU General Public License v2.0 6 votes vote down vote up
def registerCmap(self):
        """ Add matplotlib cmaps to the GradientEditors context menu"""
        self.gradientEditorItem.menu.addSeparator()
        savedLength = self.gradientEditorItem.length
        self.gradientEditorItem.length = 100
        
        
        for name in self.mplColorMaps:
            px = QPixmap(100, 15)
            p = QPainter(px)
            self.gradientEditorItem.restoreState(self.mplColorMaps[name])
            grad = self.gradientEditorItem.getGradient()
            brush = QBrush(grad)
            p.fillRect(QtCore.QRect(0, 0, 100, 15), brush)
            p.end()
            label = QLabel()
            label.setPixmap(px)
            label.setContentsMargins(1, 1, 1, 1)
            act =QWidgetAction(self.gradientEditorItem)
            act.setDefaultWidget(label)
            act.triggered.connect(self.cmapClicked)
            act.name = name
            self.gradientEditorItem.menu.addAction(act)
        self.gradientEditorItem.length = savedLength 
Example #5
Source File: exploitsview.py    From rexploit with GNU General Public License v3.0 6 votes vote down vote up
def pushButtonAutoCheckClicked(self):
        root = self.treeWidget.invisibleRootItem()
        success = 0
        fail = 0
        for i in range(root.childCount()):
            item = root.child(i)
            exploit = self.__exploits[str(item.text(0))]
            if exploit.check():
                exploit.vulnerable = True
                w = self.__stackedWidgetController.getWidgetWithExploit(exploit)
                w.setCheckBoxVulnerableChecked(True)
                self.addExploitSuccess(exploit)
                success += 1
                item.setForeground(0, QBrush(QColor(Qt.green)))
            else:
                fail += 1
                item.setForeground(0, QBrush(QColor(Qt.red)))

        self.labelCheck.setText("Result: {0} OK - {1} Fail".format(success, fail)) 
Example #6
Source File: cityscapesLabelTool.py    From TFSegmentation with Apache License 2.0 6 votes vote down vote up
def drawPoint(self, qp, pt, isFirst, increaseRadius):
        # The first in green
        if isFirst:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(0,255,0),QtCore.Qt.SolidPattern))
        # Other in red
        else:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(255,0,0),QtCore.Qt.SolidPattern))

        # Standard radius
        r = 3.0
        # Increase maybe
        if increaseRadius:
            r *= 2.5
        # Draw
        qp.drawEllipse( pt, r, r )

    # Determine if the given candidate for a label path makes sense 
Example #7
Source File: cityscapesLabelTool.py    From LightNet with MIT License 6 votes vote down vote up
def drawPoint(self, qp, pt, isFirst, increaseRadius):
        # The first in green
        if isFirst:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(0,255,0),QtCore.Qt.SolidPattern))
        # Other in red
        else:
            qp.setBrush(QtGui.QBrush(QtGui.QColor(255,0,0),QtCore.Qt.SolidPattern))

        # Standard radius
        r = 3.0
        # Increase maybe
        if increaseRadius:
            r *= 2.5
        # Draw
        qp.drawEllipse( pt, r, r )

    # Determine if the given candidate for a label path makes sense 
Example #8
Source File: pressure.py    From wacom-gui with GNU General Public License v3.0 5 votes vote down vote up
def tabletEvent(self, event):
        senId = ""
        if self.sensor == "stylus" :
            senId = QtGui.QTabletEvent.Pen
        elif self.sensor == "eraser":
            senId = QtGui.QTabletEvent.Eraser
        elif self.sensor == "cursor":
            senId = QtGui.QTabletEvent.Cursor
        if event.pointerType() == senId:
            curpressure = event.pressure()
            if curpressure < 0:
                curpressure += 1
            amp = int(curpressure * 50)
            color = (1 - amp/50.0) * 255
            pen = QtGui.QPen(QtGui.QColor(color,color,color,0))

            radial = QtGui.QRadialGradient(QtCore.QPointF(event.x(),event.y()),amp,QtCore.QPointF(event.xTilt() * amp/50 ,event.yTilt() * amp))
            radial.setColorAt(0,QtGui.QColor(color,color,color,255))
            radial.setColorAt(1,QtGui.QColor(color,color,color,0))
            brush = QtGui.QBrush(radial)
            if(amp >= 1):
                if len(self.scene.items()) >= 50:
                    render = QtGui.QPixmap(250,250)
                    painter = QtGui.QPainter(render)
                    rect = QtCore.QRectF(0,0,250,250)
                    self.scene.render(painter,rect,rect,QtCore.Qt.KeepAspectRatio)
                    self.scene.clear()
                    self.scene.addPixmap(render)
                    painter.end()
                self.scene.addEllipse(event.x() - amp, event.y() -amp, amp, amp, pen, brush)
            self.info.updateInfo(event.xTilt(),event.yTilt(),amp) 
Example #9
Source File: test_active_contour.py    From CrisisMappingToolkit with Apache License 2.0 5 votes vote down vote up
def paintEvent(self, event):
        imageqt = ImageQt.ImageQt(self.display_image)
        p = QtGui.QPainter()
        p.begin(self)
        p.setRenderHint(QtGui.QPainter.Antialiasing, True);
        scale = self.height() / float(imageqt.height() + 10)
        p.scale(scale, scale)
        p.translate((self.width() / 2 / scale - imageqt.width()  / 2),
                    (self.height() / 2 / scale - imageqt.height() / 2))
        p.fillRect(0, 0, imageqt.width(), imageqt.height(), QtGui.QColor(0, 0, 0))
        p.drawImage(0, 0, imageqt)
        NODE_RADIUS = 4
        # draw nodes
        for loop in self.snake.loops:
            for i in range(len(loop.nodes)):
                p.setPen(QtGui.QColor(255, 0, 0))
                p.setBrush(QtGui.QBrush(QtGui.QColor(255, 0, 0)))
                p.drawEllipse(loop.nodes[i][1] - NODE_RADIUS / 2.0,
                        loop.nodes[i][0] - NODE_RADIUS / 2.0, NODE_RADIUS, NODE_RADIUS)
        # draw lines between nodes
        for loop in self.snake.loops:
            for i in range(len(loop.nodes)):
                if len(loop.nodes) > 1:
                    n = i+1
                    if n == len(loop.nodes):
                        n = 0
                    p.setPen(QtGui.QColor(0, 255, 0))
                    p.drawLine(loop.nodes[i][1], loop.nodes[i][0], loop.nodes[n][1], loop.nodes[n][0])
        p.end() 
Example #10
Source File: show_submission.py    From TPN with MIT License 5 votes vote down vote up
def draw_predictions(file_path, predictions, class_index,
                     score_low, score_high):
    img = QtGui.QImage(file_path)
    painter = QtGui.QPainter(img)
    for i, pred in enumerate(predictions):
        if class_index > 0 and pred.class_index != class_index: continue
        if pred.score < score_low or pred.score > score_high: continue
        class_name = CLASS_NAMES[pred.class_index]
        x1, y1, x2, y2 = map(int, pred.bbox)
        # bbox
        painter.setPen(QtGui.QPen(PRESET_COLORS[pred.class_index], 10.0))
        # painter.setPen(QtGui.QPen(QtGui.QColor(0, 116, 217), 10.0))
        painter.setBrush(QtGui.QBrush())
        painter.drawRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
        # label background rect
        painter.setPen(QtGui.QPen(PRESET_COLORS[pred.class_index], 2.0))
        painter.setBrush(QtGui.QBrush(PRESET_COLORS[pred.class_index]))
        # painter.setPen(QtGui.QPen(QtGui.QColor(0, 116, 217), 2.0))
        # painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 116, 217)))
        if class_index > 0:
            painter.drawRect(x1, y1, min(x2 - x1 + 1, 100), 30)
        else:
            painter.drawRect(x1, y1, min(x2 - x1 + 1, 200), 30)
        # label text
        painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255)))
        painter.setBrush(QtGui.QBrush())
        painter.setFont(QtGui.QFont('Arial', 20, QtGui.QFont.Bold))
        if class_index > 0:
            painter.drawText(x1 + 4, y1 + 24, '{:.2f}'.format(pred.score))
        else:
            painter.drawText(x1 + 4, y1 + 24,
                             '{} {:.2f}'.format(class_name, pred.score))
    return img 
Example #11
Source File: exploitsview.py    From rexploit with GNU General Public License v3.0 5 votes vote down vote up
def setItemsLoaded(self, names):
        self.setEnabledItems(True)
        if names:
            root = self.treeWidget.invisibleRootItem()
            for name in names:
                for i in range(root.childCount()):
                    item = root.child(i)
                    if item.text(0) == name:
                        widget = self.__stackedWidgetController.getWidgetWithExploit(name)
                        widget.setCheckBoxVulnerableChecked()
                        item.setForeground(0, QBrush(QColor(Qt.green))) 
Example #12
Source File: exploitsview.py    From rexploit with GNU General Public License v3.0 5 votes vote down vote up
def removeExploitSuccess(self, exploit):
        self.__exploitsSuccess.remove(exploit)
        root = self.treeWidget.invisibleRootItem()
        for i in range(root.childCount()):
            item = root.child(i)
            if item.text(0) == exploit.name:
                item.setForeground(0, QBrush(QColor(Qt.black))) 
Example #13
Source File: exploitsview.py    From rexploit with GNU General Public License v3.0 5 votes vote down vote up
def addExploitSuccess(self, exploit):
        if exploit not in self.__exploitsSuccess:
            self.__exploitsSuccess.append(exploit)
            root = self.treeWidget.invisibleRootItem()
            for i in range(root.childCount()):
                item = root.child(i)
                if item.text(0) == exploit.name:
                    item.setForeground(0, QBrush(QColor(Qt.green))) 
Example #14
Source File: playermodel.py    From pyqtggpo with GNU General Public License v2.0 5 votes vote down vote up
def data(self, modelIndex, role=None):
        if not modelIndex.isValid():
            return None

        row = modelIndex.row()
        col = modelIndex.column()

        if role == Qt.DisplayRole:
            if col in [PlayerModel.PLAYER, PlayerModel.PING, PlayerModel.OPPONENT]:
                return self.players[row][col]
        elif role == Qt.ToolTipRole and col in [PlayerModel.PLAYER, PlayerModel.OPPONENT]:
            name = self.players[row][col]
            if name in self.controller.players:
                if self.controller.players[name].city:
                    return self.controller.players[name].country + ', ' + self.controller.players[name].city
                else:
                    return self.controller.players[name].country
        elif role == Qt.CheckStateRole and col == PlayerModel.IGNORE:
            return self.players[row][col]
        elif role == Qt.DecorationRole:
            return self.dataIcon(row, col)
        elif role == Qt.TextAlignmentRole:
            if col == PlayerModel.PING:
                return Qt.AlignRight | Qt.AlignVCenter
        elif role == Qt.TextColorRole:
            if col in [PlayerModel.PLAYER, PlayerModel.OPPONENT]:
                name = self.players[row][col]
                if name == 'ponder':
                    return QtGui.QBrush(QtGui.QColor(Qt.red)) 
Example #15
Source File: cityscapesLabelTool.py    From LightNet with MIT License 4 votes vote down vote up
def drawDrawRect(self, qp):

        qp.save()
        qp.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
        qp.setFont(QtGui.QFont('QFont::AnyStyle', 14))
        thickPen = QtGui.QPen()
        qp.setPen(thickPen)

        for c in self.corrections:
            rect = copy.deepcopy(c.bbox)

            width = rect.width()
            height = rect.height()
            rect.setX(c.bbox.x() * self.scale + self.xoff)
            rect.setY(c.bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            if c.selected:
                thickPen.setColor(QtGui.QColor(0,0,0))
                if c.type == CorrectionBox.types.QUESTION:
                    descr = "QUESTION"
                elif c.type == CorrectionBox.types.RESOLVED:
                    descr = "FIXED"
                else:
                    descr = "ERROR"
                qp.setPen(thickPen)
                qp.drawText(QtCore.QPoint( self.xoff, self.yoff + self.h + 20 ),
                                           "(%s: %s)" % (descr, c.annotation))
                pen_width = 6
            else:
                pen_width = 3

            colour = c.get_colour()
            thickPen.setColor(colour)
            thickPen.setWidth(pen_width)
            qp.setPen(thickPen)
            qp.drawRect(rect)

        if self.in_progress_bbox is not None:
            rect = copy.deepcopy(self.in_progress_bbox)
            width = rect.width()
            height = rect.height()
            rect.setX(self.in_progress_bbox.x() * self.scale + self.xoff)
            rect.setY(self.in_progress_bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            thickPen.setColor(QtGui.QColor(255,0,0))
            thickPen.setWidth(3)
            qp.setPen(thickPen)
            qp.drawRect(rect)


        qp.restore()

    # Draw the polygon that is drawn and edited by the user
    # Usually the polygon must be rescaled properly. However when drawing
    # The polygon within the zoom, this is not needed. Therefore the option transform. 
Example #16
Source File: cityscapesLabelTool.py    From LightNet with MIT License 4 votes vote down vote up
def blurLicensePlates(self,qp):
        # license plate name
        searchedNames = [ 'license plate' ]

        # the image
        img = self.image

        # Draw all objects
        for obj in self.annotation.objects:
            # Some are flagged to not be drawn. Skip them
            if not obj.draw:
                continue

            # The label of the object
            name      = obj.label
            # If we do not know a color for this label, skip
            if not name2label.has_key( name ):
                continue
            # If we do not blur this label, skip
            if not name in searchedNames:
                continue

            # Scale the polygon properly
            polyToDraw = self.getPolygon(obj) * QtGui.QTransform.fromScale(self.scale,self.scale)
            bb = polyToDraw.boundingRect()

            # Get the mean color within the polygon
            meanR = 0
            meanG = 0
            meanB = 0
            num   = 0
            for y in range( max(int(bb.top()),0) , min(int(bb.bottom()+1.5),img.height()) ):
                for x in range( max(int(bb.left()),0) , min(int(bb.right()+1.5),img.width()) ):
                    col = img.pixel(x,y)
                    meanR += QtGui.QColor(col).red()
                    meanG += QtGui.QColor(col).green()
                    meanB += QtGui.QColor(col).blue()
                    num   += 1
            meanR /= float(num)
            meanG /= float(num)
            meanB /= float(num)
            col = QtGui.QColor( meanR , meanG , meanB )
            qp.setPen(col)
            brush = QtGui.QBrush( col, QtCore.Qt.SolidPattern )
            qp.setBrush(brush)

            # Default drawing
            qp.drawPolygon( polyToDraw )


    # Update the object that is selected by the current mouse curser 
Example #17
Source File: cityscapesLabelTool.py    From TFSegmentation with Apache License 2.0 4 votes vote down vote up
def drawDrawRect(self, qp):

        qp.save()
        qp.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
        qp.setFont(QtGui.QFont('QFont::AnyStyle', 14))
        thickPen = QtGui.QPen()
        qp.setPen(thickPen)

        for c in self.corrections:
            rect = copy.deepcopy(c.bbox)

            width = rect.width()
            height = rect.height()
            rect.setX(c.bbox.x() * self.scale + self.xoff)
            rect.setY(c.bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            if c.selected:
                thickPen.setColor(QtGui.QColor(0,0,0))
                if c.type == CorrectionBox.types.QUESTION:
                    descr = "QUESTION"
                elif c.type == CorrectionBox.types.RESOLVED:
                    descr = "FIXED"
                else:
                    descr = "ERROR"
                qp.setPen(thickPen)
                qp.drawText(QtCore.QPoint( self.xoff, self.yoff + self.h + 20 ),
                                           "(%s: %s)" % (descr, c.annotation))
                pen_width = 6
            else:
                pen_width = 3

            colour = c.get_colour()
            thickPen.setColor(colour)
            thickPen.setWidth(pen_width)
            qp.setPen(thickPen)
            qp.drawRect(rect)

        if self.in_progress_bbox is not None:
            rect = copy.deepcopy(self.in_progress_bbox)
            width = rect.width()
            height = rect.height()
            rect.setX(self.in_progress_bbox.x() * self.scale + self.xoff)
            rect.setY(self.in_progress_bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            thickPen.setColor(QtGui.QColor(255,0,0))
            thickPen.setWidth(3)
            qp.setPen(thickPen)
            qp.drawRect(rect)


        qp.restore()

    # Draw the polygon that is drawn and edited by the user
    # Usually the polygon must be rescaled properly. However when drawing
    # The polygon within the zoom, this is not needed. Therefore the option transform. 
Example #18
Source File: cityscapesLabelTool.py    From TFSegmentation with Apache License 2.0 4 votes vote down vote up
def blurLicensePlates(self,qp):
        # license plate name
        searchedNames = [ 'license plate' ]

        # the image
        img = self.image

        # Draw all objects
        for obj in self.annotation.objects:
            # Some are flagged to not be drawn. Skip them
            if not obj.draw:
                continue

            # The label of the object
            name      = obj.label
            # If we do not know a color for this label, skip
            if not name2label.has_key( name ):
                continue
            # If we do not blur this label, skip
            if not name in searchedNames:
                continue

            # Scale the polygon properly
            polyToDraw = self.getPolygon(obj) * QtGui.QTransform.fromScale(self.scale,self.scale)
            bb = polyToDraw.boundingRect()

            # Get the mean color within the polygon
            meanR = 0
            meanG = 0
            meanB = 0
            num   = 0
            for y in range( max(int(bb.top()),0) , min(int(bb.bottom()+1.5),img.height()) ):
                for x in range( max(int(bb.left()),0) , min(int(bb.right()+1.5),img.width()) ):
                    col = img.pixel(x,y)
                    meanR += QtGui.QColor(col).red()
                    meanG += QtGui.QColor(col).green()
                    meanB += QtGui.QColor(col).blue()
                    num   += 1
            meanR /= float(num)
            meanG /= float(num)
            meanB /= float(num)
            col = QtGui.QColor( meanR , meanG , meanB )
            qp.setPen(col)
            brush = QtGui.QBrush( col, QtCore.Qt.SolidPattern )
            qp.setBrush(brush)

            # Default drawing
            qp.drawPolygon( polyToDraw )


    # Update the object that is selected by the current mouse curser 
Example #19
Source File: ai.py    From crazyflieROS with GNU General Public License v2.0 4 votes vote down vote up
def drawMotors(self, qp):
        # TODO Check if motor update is recent
        if (self.motors[0]<0):
            return

        defaultCol = QColor(0,255,0, 200)

        #qp = QtGui.QPainter()
        qp.resetTransform()
        w = self.width()
        h = self.height()


        maxSize = min(w,h)*0.175
        minSize = maxSize/10.
        qp.translate(w- maxSize, h-maxSize)
        qp.translate(-12,-12)
        qp.rotate(45)



        lighter = defaultCol
        lighter.setAlphaF(0.1)
        qp.setBrush(lighter.dark())
        qp.setPen(lighter)

        # Draw background circle
        qp.drawEllipse(QPointF(0,0),maxSize,maxSize)

        # Draw Thrust Average
        spread = 2
        avg = sum(self.motors)/len(self.motors) /100. * (maxSize-minSize) + minSize
        lighter.setAlphaF(0.5)
        qp.setPen(lighter.lighter())
        qp.setBrush(QColor(0,0,0,0))
        qp.drawEllipse(QPointF(0,0),avg, avg)

        qp.setBrush(lighter.dark())
        lighter.setAlphaF(0.2)
        qp.setPen(lighter)

        qp.setPen(QPen(defaultCol))
        qp.setBrush(QBrush(defaultCol.dark()))

        for i in range(4):
            m = self.motors[i]*2/100. * (maxSize-minSize) + minSize
            qp.drawPie(QRectF(spread-m/2., spread-m/2., m, m), 0, -90*16)
            qp.rotate(-90) 
Example #20
Source File: cityscapesLabelTool.py    From Detectron-PYTORCH with Apache License 2.0 4 votes vote down vote up
def drawDrawRect(self, qp):

        qp.save()
        qp.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
        qp.setFont(QtGui.QFont('QFont::AnyStyle', 14))
        thickPen = QtGui.QPen()
        qp.setPen(thickPen)

        for c in self.corrections:
            rect = copy.deepcopy(c.bbox)

            width = rect.width()
            height = rect.height()
            rect.setX(c.bbox.x() * self.scale + self.xoff)
            rect.setY(c.bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            if c.selected:
                thickPen.setColor(QtGui.QColor(0,0,0))
                if c.type == CorrectionBox.types.QUESTION:
                    descr = "QUESTION"
                elif c.type == CorrectionBox.types.RESOLVED:
                    descr = "FIXED"
                else:
                    descr = "ERROR"
                qp.setPen(thickPen)
                qp.drawText(QtCore.QPoint( self.xoff, self.yoff + self.h + 20 ),
                                           "(%s: %s)" % (descr, c.annotation))
                pen_width = 6
            else:
                pen_width = 3

            colour = c.get_colour()
            thickPen.setColor(colour)
            thickPen.setWidth(pen_width)
            qp.setPen(thickPen)
            qp.drawRect(rect)

        if self.in_progress_bbox is not None:
            rect = copy.deepcopy(self.in_progress_bbox)
            width = rect.width()
            height = rect.height()
            rect.setX(self.in_progress_bbox.x() * self.scale + self.xoff)
            rect.setY(self.in_progress_bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            thickPen.setColor(QtGui.QColor(255,0,0))
            thickPen.setWidth(3)
            qp.setPen(thickPen)
            qp.drawRect(rect)


        qp.restore()

    # Draw the polygon that is drawn and edited by the user
    # Usually the polygon must be rescaled properly. However when drawing
    # The polygon within the zoom, this is not needed. Therefore the option transform. 
Example #21
Source File: PyQtPiClock.py    From PiClock with MIT License 4 votes vote down vote up
def basefinished(self):
        if self.basereply.error() != QNetworkReply.NoError:
            return
        self.basepixmap = QPixmap()
        self.basepixmap.loadFromData(self.basereply.readAll())
        if self.basepixmap.size() != self.rect.size():
            self.basepixmap = self.basepixmap.scaled(self.rect.size(),
                                                     Qt.KeepAspectRatio,
                                                     Qt.SmoothTransformation)
        self.setPixmap(self.basepixmap)

        # make marker pixmap
        self.mkpixmap = QPixmap(self.basepixmap.size())
        self.mkpixmap.fill(Qt.transparent)
        br = QBrush(QColor(Config.dimcolor))
        painter = QPainter()
        painter.begin(self.mkpixmap)
        painter.fillRect(0, 0, self.mkpixmap.width(),
                         self.mkpixmap.height(), br)
        for marker in self.radar['markers']:
            if 'visible' not in marker or marker['visible'] == 1:
                pt = getPoint(marker["location"], self.point, self.zoom,
                              self.rect.width(), self.rect.height())
                mk2 = QImage()
                mkfile = 'teardrop'
                if 'image' in marker:
                    mkfile = marker['image']
                if os.path.dirname(mkfile) == '':
                    mkfile = os.path.join('markers', mkfile)
                if os.path.splitext(mkfile)[1] == '':
                    mkfile += '.png'
                mk2.load(mkfile)
                if mk2.format != QImage.Format_ARGB32:
                    mk2 = mk2.convertToFormat(QImage.Format_ARGB32)
                mkh = 80  # self.rect.height() / 5
                if 'size' in marker:
                    if marker['size'] == 'small':
                        mkh = 64
                    if marker['size'] == 'mid':
                        mkh = 70
                    if marker['size'] == 'tiny':
                        mkh = 40
                if 'color' in marker:
                    c = QColor(marker['color'])
                    (cr, cg, cb, ca) = c.getRgbF()
                    for x in range(0, mk2.width()):
                        for y in range(0, mk2.height()):
                            (r, g, b, a) = QColor.fromRgba(
                                           mk2.pixel(x, y)).getRgbF()
                            r = r * cr
                            g = g * cg
                            b = b * cb
                            mk2.setPixel(x, y, QColor.fromRgbF(r, g, b, a)
                                         .rgba())
                mk2 = mk2.scaledToHeight(mkh, 1)
                painter.drawImage(pt.x-mkh/2, pt.y-mkh/2, mk2)

        painter.end()

        self.wmk.setPixmap(self.mkpixmap) 
Example #22
Source File: cityscapesLabelTool.py    From Detectron-PYTORCH with Apache License 2.0 4 votes vote down vote up
def blurLicensePlates(self,qp):
        # license plate name
        searchedNames = [ 'license plate' ]

        # the image
        img = self.image

        # Draw all objects
        for obj in self.annotation.objects:
            # Some are flagged to not be drawn. Skip them
            if not obj.draw:
                continue

            # The label of the object
            name      = obj.label
            # If we do not know a color for this label, skip
            if not name2label.has_key( name ):
                continue
            # If we do not blur this label, skip
            if not name in searchedNames:
                continue

            # Scale the polygon properly
            polyToDraw = self.getPolygon(obj) * QtGui.QTransform.fromScale(self.scale,self.scale)
            bb = polyToDraw.boundingRect()

            # Get the mean color within the polygon
            meanR = 0
            meanG = 0
            meanB = 0
            num   = 0
            for y in range( max(int(bb.top()),0) , min(int(bb.bottom()+1.5),img.height()) ):
                for x in range( max(int(bb.left()),0) , min(int(bb.right()+1.5),img.width()) ):
                    col = img.pixel(x,y)
                    meanR += QtGui.QColor(col).red()
                    meanG += QtGui.QColor(col).green()
                    meanB += QtGui.QColor(col).blue()
                    num   += 1
            meanR /= float(num)
            meanG /= float(num)
            meanB /= float(num)
            col = QtGui.QColor( meanR , meanG , meanB )
            qp.setPen(col)
            brush = QtGui.QBrush( col, QtCore.Qt.SolidPattern )
            qp.setBrush(brush)

            # Default drawing
            qp.drawPolygon( polyToDraw )


    # Update the object that is selected by the current mouse curser 
Example #23
Source File: cityscapesLabelTool.py    From fcn8s_tensorflow with GNU General Public License v3.0 4 votes vote down vote up
def blurLicensePlates(self,qp):
        # license plate name
        searchedNames = [ 'license plate' ]

        # the image
        img = self.image

        # Draw all objects
        for obj in self.annotation.objects:
            # Some are flagged to not be drawn. Skip them
            if not obj.draw:
                continue

            # The label of the object
            name      = obj.label
            # If we do not know a color for this label, skip
            if not name2label.has_key( name ):
                continue
            # If we do not blur this label, skip
            if not name in searchedNames:
                continue

            # Scale the polygon properly
            polyToDraw = self.getPolygon(obj) * QtGui.QTransform.fromScale(self.scale,self.scale)
            bb = polyToDraw.boundingRect()

            # Get the mean color within the polygon
            meanR = 0
            meanG = 0
            meanB = 0
            num   = 0
            for y in range( max(int(bb.top()),0) , min(int(bb.bottom()+1.5),img.height()) ):
                for x in range( max(int(bb.left()),0) , min(int(bb.right()+1.5),img.width()) ):
                    col = img.pixel(x,y)
                    meanR += QtGui.QColor(col).red()
                    meanG += QtGui.QColor(col).green()
                    meanB += QtGui.QColor(col).blue()
                    num   += 1
            meanR /= float(num)
            meanG /= float(num)
            meanB /= float(num)
            col = QtGui.QColor( meanR , meanG , meanB )
            qp.setPen(col)
            brush = QtGui.QBrush( col, QtCore.Qt.SolidPattern )
            qp.setBrush(brush)

            # Default drawing
            qp.drawPolygon( polyToDraw )


    # Update the object that is selected by the current mouse curser 
Example #24
Source File: cityscapesLabelTool.py    From fcn8s_tensorflow with GNU General Public License v3.0 4 votes vote down vote up
def drawDrawRect(self, qp):

        qp.save()
        qp.setBrush(QtGui.QBrush(QtCore.Qt.NoBrush))
        qp.setFont(QtGui.QFont('QFont::AnyStyle', 14))
        thickPen = QtGui.QPen()
        qp.setPen(thickPen)

        for c in self.corrections:
            rect = copy.deepcopy(c.bbox)

            width = rect.width()
            height = rect.height()
            rect.setX(c.bbox.x() * self.scale + self.xoff)
            rect.setY(c.bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            if c.selected:
                thickPen.setColor(QtGui.QColor(0,0,0))
                if c.type == CorrectionBox.types.QUESTION:
                    descr = "QUESTION"
                elif c.type == CorrectionBox.types.RESOLVED:
                    descr = "FIXED"
                else:
                    descr = "ERROR"
                qp.setPen(thickPen)
                qp.drawText(QtCore.QPoint( self.xoff, self.yoff + self.h + 20 ),
                                           "(%s: %s)" % (descr, c.annotation))
                pen_width = 6
            else:
                pen_width = 3

            colour = c.get_colour()
            thickPen.setColor(colour)
            thickPen.setWidth(pen_width)
            qp.setPen(thickPen)
            qp.drawRect(rect)

        if self.in_progress_bbox is not None:
            rect = copy.deepcopy(self.in_progress_bbox)
            width = rect.width()
            height = rect.height()
            rect.setX(self.in_progress_bbox.x() * self.scale + self.xoff)
            rect.setY(self.in_progress_bbox.y() * self.scale + self.yoff)

            rect.setWidth(width * self.scale)
            rect.setHeight(height * self.scale)

            thickPen.setColor(QtGui.QColor(255,0,0))
            thickPen.setWidth(3)
            qp.setPen(thickPen)
            qp.drawRect(rect)


        qp.restore()

    # Draw the polygon that is drawn and edited by the user
    # Usually the polygon must be rescaled properly. However when drawing
    # The polygon within the zoom, this is not needed. Therefore the option transform.