Python PyQt5.QtGui.QBrush() Examples

The following are 30 code examples for showing how to use PyQt5.QtGui.QBrush(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtGui , or try the search function .

Example 1
Project: interSubs   Author: oltodosel   File: interSubs.py    License: MIT License 7 votes vote down vote up
def highligting(self, color, underline_width):
		color = QColor(color)
		color = QColor(color.red(), color.green(), color.blue(), 200)
		painter = QPainter(self)

		if config.hover_underline:
			font_metrics = QFontMetrics(self.font())
			text_width = font_metrics.width(self.word)
			text_height = font_metrics.height()

			brush = QBrush(color)
			pen = QPen(brush, underline_width, Qt.SolidLine, Qt.RoundCap)
			painter.setPen(pen)
			if not self.skip:
				painter.drawLine(0, text_height - underline_width, text_width, text_height - underline_width)

		if config.hover_hightlight:
			x = y = 0
			y += self.fontMetrics().ascent()

			painter.setPen(color)
			painter.drawText(x, y + config.outline_top_padding - config.outline_bottom_padding, self.word) 
Example 2
Project: pkmeter   Author: pkkid   File: pkcharts.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def paintEvent(self, event):
        QtWidgets.QFrame.paintEvent(self, event)
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)
        # Draw the Pie
        rwidth = int(min([self.width(), self.height()]) - 2)
        x = int((self.width() / 2) - (rwidth / 2))
        y = int((self.height() / 2) - (rwidth / 2))
        rect = QtCore.QRect(x, y, rwidth, rwidth)
        angle1 = 0
        for i in range(len(self.data)):
            angle2 = angle1 + (3.6 * self.data[i])
            painter.setBrush(QtGui.QBrush(self.colors[i % len(self.colors)]))
            painter.drawPie(rect, angle1*-16, (angle2-angle1)*-16)
            angle1 = angle2
        # Draw the remainer (background)
        angle2 = 360
        painter.setBrush(QtGui.QBrush(self.bgcolor))
        painter.drawPie(rect, angle1*-16, (angle2-angle1)*-16)
        painter.end() 
Example 3
Project: pkmeter   Author: pkkid   File: pkcharts.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def paintEvent(self, event):
        if not self.data: return
        QtWidgets.QFrame.paintEvent(self, event)
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        # Draw background
        painter.setBrush(QtGui.QBrush(self.bgcolor))
        painter.setPen(Qt.NoPen)
        painter.drawRoundedRect(self.contentsRect(), 2, 2)
        # Draw the bars
        barwidth = (self.width() - 4) / len(self.data)
        for i in range(len(self.data)):
            barheight = int(self.height() * (self.data[i] / 100))
            baroffset = i * barwidth + 2
            painter.setBrush(QtGui.QBrush(self.colors[i % len(self.colors)]))
            painter.drawRoundedRect(baroffset, self.height()-barheight, barwidth, barheight, 1, 1)
        painter.end() 
Example 4
Project: dcc   Author: amimo   File: Banners.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, themes, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode
        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(themes['background'])

        # text font
        self.font = themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine) 
Example 5
Project: dcc   Author: amimo   File: Banners.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, themes, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode
        self.backgroundBrush = QtGui.QBrush(themes['background'])

        self.qpix = self._getNewPixmap(self.width, self.height)

        # text font
        self.font = themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(themes['pen'], 0, QtCore.Qt.SolidLine) 
Example 6
Project: dcc   Author: amimo   File: Banners.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, themes, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode

        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(themes['background'])

        # text font
        self.font = themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(themes['pen'], 0, QtCore.Qt.SolidLine) 
Example 7
def updateDetailScreen(self):
        self.textBrowser.clear()
        self.currentTreeWidget = self.treeWidget.currentItem()
        try:
            scriptName = self.currentTreeWidget.text(0)
            scriptNo = scriptName.replace("script", "")
            indexSelectedScript = videoscriptcore.getScripts().index(int(scriptNo))
            selectedScript = videoscriptcore.video_scripts[indexSelectedScript]
            self.currentScriptSelected = selectedScript.scriptno
            self.textBrowser.append("Category: %s\n"%selectedScript.sub_reddit)
            self.textBrowser.append("Upvotes: %s"%selectedScript.upvotes)
            self.textBrowser.append("Author: %s"%selectedScript.author)
            self.textBrowser.append("Vid Number: %s"%selectedScript.vidNo)
            self.textBrowser.append("Status: %s"%selectedScript.status)
            self.textBrowser.append("Script ID: %s"%selectedScript.scriptno)
            self.textBrowser.append("Being Edited by: %s"%selectedScript.editedby)
            self.textBrowser.append("\nTitle: %s\n"%selectedScript.title)

            self.editedby.setText(selectedScript.editedby)
            self.currentTreeWidget.setForeground(0, QtGui.QBrush(QtGui.QColor("blue")))
        except AttributeError:
            pass
        self.updateColors() 
Example 8
def updateColors(self):
        try:
            children = self.count_tems()
            for i in range(len(children)):
                scriptName = children[i].text(0)
                scriptNo = scriptName.replace("script", "")
                indexSelectedScript = videoscriptcore.getScripts().index(int(scriptNo))
                status = videoscriptcore.video_scripts[indexSelectedScript].status
                if hasattr(self, "currentTreeWidget"):
                    if status == "RAW":
                        if settings.darkMode:
                            children[i].setForeground(0, QtGui.QBrush(QtGui.QColor("white")))
                        else:
                            children[i].setForeground(0, QtGui.QBrush(QtGui.QColor("black")))
                    elif status == "EDITING":
                        children[i].setForeground(0, QtGui.QBrush(QtGui.QColor("yellow")))
                    elif status == "COMPLETE":
                        children[i].setForeground(0, QtGui.QBrush(QtGui.QColor("green")))
                    elif status == "MANUALCOMPLETE":
                        children[i].setForeground(0, QtGui.QBrush(QtGui.QColor("darkgreen")))
                    elif status == "QUALITY":
                        children[i].setForeground(0, QtGui.QBrush(QtGui.QColor("red")))
        except:
            print("error occured recolouring scripts") 
Example 9
def addRawScriptsToTree(self):
        self.treeWidget.clear()
        for i, vid in enumerate(videoscriptcore.video_scripts):
            new_item = self.addChild(vid.sub_reddit, "script%s"%vid.vidNo)
            if vid.status == "EDITING":
                new_item.setForeground(0, QtGui.QBrush(QtGui.QColor("yellow")))
            elif vid.status == "RAW":
                if settings.darkMode:
                    new_item.setForeground(0, QtGui.QBrush(QtGui.QColor("white")))
                else:
                    new_item.setForeground(0, QtGui.QBrush(QtGui.QColor("black")))
            elif vid.status == "COMPLETE":
                new_item.setForeground(0, QtGui.QBrush(QtGui.QColor("green")))
            elif vid.status == "MANUALCOMPLETE":
                new_item.setForeground(0, QtGui.QBrush(QtGui.QColor("darkgreen")))

        self.treeWidget.expandToDepth(0) 
Example 10
Project: malss   Author: canard0328   File: waiting_animation.py    License: MIT License 6 votes vote down vote up
def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255, 200)))
        painter.setPen(QPen(Qt.NoPen))

        if self.lists is not None:
            path = os.path.abspath(os.path.dirname(__file__)) + '/static/'
            path += self.lists[self.list_index] + '.png'
            self.list_index += 1
            if self.list_index >= len(self.lists):
                self.list_index = 0
            image = QImage(path)
            rect_image = image.rect()
            rect_painter = event.rect()
            dx = (rect_painter.width() - rect_image.width()) / 2.0
            dy = (rect_painter.height() - rect_image.height()) / 2.0
            painter.drawImage(dx, dy, image)

        painter.end() 
Example 11
Project: FIRST-plugin-ida   Author: vrtadmin   File: first.py    License: GNU General Public License v2.0 6 votes vote down vote up
def set_colors(self, changed='66d9ef', unchanged='d2d2d2', default='ffffff', select='a9c5ff'):
                '''Sets the colors associated with the various properties.

                Args:
                    changed (:obj:`str`): Change color, default: '66d9ef'
                    unchanged (:obj:`str`): Unchanged color, default: 'd2d2d2'
                    default (:obj:`str`): Default color, default: 'ffffff'
                    select (:obj:`str`): Selected color, default: 'a9c5ff'
                '''
                colors = [changed, unchanged, default, select]

                if None in [re.match('^[a-fA-F0-9]{6}$', x) for x in colors]:
                    #   Invalid color provided
                    return

                self.colors = []
                for c in colors:
                    r, g, b = int(c[:2], 16), int(c[2:4], 16), int(c[-2:], 16)
                    self.colors.append(QtGui.QBrush(QtGui.QColor.fromRgb(r, g, b))) 
Example 12
Project: qiew   Author: mtivadar   File: DisasmViewMode.py    License: GNU General Public License v2.0 6 votes vote down vote up
def drawSelected(self, qp):
        qp.setFont(self.font)

        cursorX, cursorY = self.cursor.getPosition()

        if len(self.OPCODES) - 1 < cursorY:
            return

        asm = self.OPCODES[cursorY]
        cx, width, text = asm.getSelectedToken(cursorX)

        cemu = ConsoleEmulator(qp, self.ROWS, self.COLUMNS)

        for i, asm in enumerate(self.OPCODES):
            for idx, length, value in asm.tokens():
                # skip current cursor position
                if cursorY == i and cursorX == idx:
                    continue

                # check every line, if match, select it
                if value == text:
                    qp.setOpacity(0.4)
                    brush=QtGui.QBrush(QtGui.QColor(0, 255, 0))
                    qp.fillRect(idx*self.fontWidth, i*self.fontHeight + 2 , width*self.fontWidth, self.fontHeight, brush)
                    qp.setOpacity(1) 
Example 13
Project: qiew   Author: mtivadar   File: Banners.py    License: GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode
        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128))        
        

        # text font
        self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Light)

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth  = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine) 
Example 14
Project: qiew   Author: mtivadar   File: Banners.py    License: GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode

        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128))        
        

        # text font
        self.font = QtGui.QFont('Consolas', 11, QtGui.QFont.Light)

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth  = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(QtGui.QColor(255, 255, 0), 0, QtCore.Qt.SolidLine) 
Example 15
Project: qiew   Author: mtivadar   File: Banners.py    License: GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, dataModel, viewMode):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode

        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128))        
        

        # text font
        self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Bold)

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth  = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(QtGui.QColor(255, 255, 0), 0, QtCore.Qt.SolidLine) 
Example 16
Project: qiew   Author: mtivadar   File: elf.py    License: GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, dataModel, viewMode, elfplugin):
        self.width = 0
        self.height = 0
        self.dataModel = dataModel
        self.viewMode = viewMode
        self.qpix = self._getNewPixmap(self.width, self.height)
        self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128))

        self.elfplugin = elfplugin

        self.elf = self.elfplugin.elf        

        # text font
        self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Bold)

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self.fontWidth  = fm.width('a')
        self.fontHeight = fm.height()

        self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine) 
Example 17
Project: qiew   Author: mtivadar   File: bootsector.py    License: GNU General Public License v2.0 6 votes vote down vote up
def init(self, viewMode, parent):
        self.viewMode = viewMode

        self.MZbrush = QtGui.QBrush(QtGui.QColor(128, 0, 0))
        self.greenPen = QtGui.QPen(QtGui.QColor(255, 255, 0))


        self.textDecorator = TextDecorator(viewMode)
        self.textDecorator = HighlightASCII(self.textDecorator)
        self.textDecorator = HighlightPrefix(self.textDecorator, '\x55\xAA', brush=self.MZbrush, pen=self.greenPen)

        self.viewMode.setTransformationEngine(self.textDecorator)
        self.viewMode.selector.addSelection((446,      446+1*16, QtGui.QBrush(QtGui.QColor(125, 75, 150)), 0.8), type=TextSelection.SelectionType.PERMANENT)
        self.viewMode.selector.addSelection((446+16,   446+2*16, QtGui.QBrush(QtGui.QColor(55, 125, 50)), 0.8), type=TextSelection.SelectionType.PERMANENT)
        self.viewMode.selector.addSelection((446+2*16, 446+3*16, QtGui.QBrush(QtGui.QColor(125, 75, 150)), 0.8), type=TextSelection.SelectionType.PERMANENT)
        self.viewMode.selector.addSelection((446+3*16, 446+4*16, QtGui.QBrush(QtGui.QColor(55, 125, 50)), 0.8), type=TextSelection.SelectionType.PERMANENT)

        return True 
Example 18
Project: qiew   Author: mtivadar   File: binary.py    License: GNU General Public License v2.0 6 votes vote down vote up
def init(self, viewMode, parent):
        self._viewMode = viewMode

        self.MZbrush = QtGui.QBrush(QtGui.QColor(128, 0, 0))
        self.greenPen = QtGui.QPen(QtGui.QColor(255, 255, 0))
        self.grayBrush = QtGui.QBrush(QtGui.QColor(128, 128, 128))
        self.whitePen = QtGui.QPen(QtGui.QColor(255, 255, 255))        


        self.textDecorator = TextDecorator(viewMode)
        self.textDecorator = HighlightASCII(self.textDecorator)
        self.textDecorator = HighlightPrefix(self.textDecorator, 'MZ', brush=self.MZbrush, pen=self.greenPen)
        self.textDecorator = HighlightPrefix(self.textDecorator, 'PE\x00\x00', brush=self.MZbrush, pen=self.greenPen)
        self.textDecorator = HighlightPrefix(self.textDecorator, '\xFF\x15', additionalLength=4, brush=self.grayBrush, pen=self.whitePen)
        self.textDecorator = HighlightWideChar(self.textDecorator)

        self._viewMode.setTransformationEngine(self.textDecorator)
        return True 
Example 19
Project: 15-minute-apps   Author: learnpyqt   File: paint.py    License: MIT License 6 votes vote down vote up
def selectpoly_copy(self):
        """
        Copy a polygon region from the current image, returning it.

        Create a mask for the selected area, and use it to blank
        out non-selected regions. Then get the bounding rect of the
        selection and crop to produce the smallest possible image.

        :return: QPixmap of the copied region.
        """
        self.timer_cleanup()

        pixmap = self.pixmap().copy()
        bitmap = QBitmap(*CANVAS_DIMENSIONS)
        bitmap.clear()  # Starts with random data visible.

        p = QPainter(bitmap)
        # Construct a mask where the user selected area will be kept, 
        # the rest removed from the image is transparent.
        userpoly = QPolygon(self.history_pos + [self.current_pos])
        p.setPen(QPen(Qt.color1))
        p.setBrush(QBrush(Qt.color1))  # Solid color, Qt.color1 == bit on.
        p.drawPolygon(userpoly)
        p.end()

        # Set our created mask on the image.
        pixmap.setMask(bitmap)

        # Calculate the bounding rect and return a copy of that region.
        return pixmap.copy(userpoly.boundingRect())

    # Select rectangle events 
Example 20
Project: 15-minute-apps   Author: learnpyqt   File: paint.py    License: MIT License 6 votes vote down vote up
def generic_shape_mouseReleaseEvent(self, e):
        if self.last_pos:
            # Clear up indicator.
            self.timer_cleanup()

            p = QPainter(self.pixmap())
            p.setPen(QPen(self.primary_color, self.config['size'], Qt.SolidLine, Qt.SquareCap, Qt.MiterJoin))

            if self.config['fill']:
                p.setBrush(QBrush(self.secondary_color))
            getattr(p, self.active_shape_fn)(QRect(self.origin_pos, e.pos()), *self.active_shape_args)
            self.update()

        self.reset_mode()

    # Line events 
Example 21
Project: imperialism-remake   Author: Trilarion   File: editor.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, column, row):
        super().__init__()

        self.scene = QtWidgets.QGraphicsScene()
        self.setScene(self.scene)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        # TODO see EditorMap redraw
        brushes = {0: QtGui.QBrush(QtGui.QColor(64, 64, 255)), 1: QtGui.QBrush(QtGui.QColor(64, 255, 64)),
                   2: QtGui.QBrush(QtGui.QColor(64, 255, 64)), 3: QtGui.QBrush(QtGui.QColor(64, 255, 64)),
                   4: QtGui.QBrush(QtGui.QColor(222, 222, 222)), 5: QtGui.QBrush(QtGui.QColor(0, 128, 0)),
                   6: QtGui.QBrush(QtGui.QColor(222, 222, 0))}

        # TODO hardcore tile size somewhere else (and a bit less hard)
        self.TILE_SIZE = 80

        for i in range(0, 6):
            y = i // 4
            x = i % 4
            self.scene.addRect(x * self.TILE_SIZE, y * self.TILE_SIZE, self.TILE_SIZE, self.TILE_SIZE,
                               brush=brushes[i], pen=qt.TRANSPARENT_PEN) 
Example 22
Project: PyPipboyApp   Author: matzman666   File: playerconditionwidget.py    License: GNU General Public License v3.0 6 votes vote down vote up
def init(self, app, datamanager):
        super().init(app, datamanager)
        self.statsColor = QtGui.QColor.fromRgb(20,255,23)
        self.dataManager = datamanager
        self.dataManager.registerRootObjectListener(self._onPipRootObjectEvent)
        self.statsView = self.widget.graphicsView
        self.statsScene = QtWidgets.QGraphicsScene()
        self.statsScene.setBackgroundBrush(QtGui.QBrush(QtGui.QColor.fromRgb(0,0,0)))
        self.statsView.setScene(self.statsScene)
        self.bodyCondFilePath = os.path.join('res', 'body_condition_0.svg')
        self.headCondFilePath = os.path.join('res', 'head_condition_0.svg')
        self.headCondition = 0
        headPixmap = self.imageFactory.getPixmap(self.headCondFilePath, height=50, color=self.statsColor)
        self.statsHeadItem = self.statsScene.addPixmap(headPixmap)
        self.statsHeadItem.setPos(-headPixmap.width()/2, 0)
        self.bodyCondition = 0
        bodyPixmap = self.imageFactory.getPixmap(self.bodyCondFilePath, height=100, color=self.statsColor)
        self.statsBodyItem = self.statsScene.addPixmap(bodyPixmap)
        self.statsBodyItem.setPos(-bodyPixmap.width()/2, 42) 
Example 23
Project: pkmeter   Author: pkkid   File: pkwidgets.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paint_slider_on(self, painter):
        swidth = int((self.width() / 2) - 2)
        sheight = int(self.height() - 2)
        painter.setBrush(QtGui.QBrush(QtGui.QColor(60,90,150,200)))
        painter.drawRoundedRect(self.contentsRect(), 3, 3)
        painter.setBrush(QtGui.QBrush(self.bgcolor_slider))
        painter.drawRoundedRect(swidth+3, 1, swidth, sheight, 2, 2)
        painter.setPen(QtGui.QColor(255,255,255,220))
        painter.drawText(2, 1, swidth, sheight, Qt.AlignCenter | Qt.AlignVCenter, 'On') 
Example 24
Project: pkmeter   Author: pkkid   File: pkwidgets.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paint_slider_off(self, painter):
        swidth = int((self.width() / 2) - 2)
        sheight = int(self.height() - 2)
        painter.setBrush(QtGui.QBrush(QtGui.QColor(0,0,0,50)))
        painter.drawRoundedRect(self.contentsRect(), 3, 3)
        painter.setBrush(QtGui.QBrush(self.bgcolor_slider))
        painter.drawRoundedRect(3, 1, swidth, sheight, 2, 2)
        painter.setPen(QtGui.QColor(0,0,0,150))
        painter.drawText(swidth+3, 1, swidth, sheight, Qt.AlignCenter | Qt.AlignVCenter, 'Off') 
Example 25
Project: pkmeter   Author: pkkid   File: pkcharts.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paintEvent(self, event):
        if not self.data: return
        QtWidgets.QFrame.paintEvent(self, event)
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        # Draw background
        painter.setBrush(QtGui.QBrush(self.bgcolor))
        painter.setPen(Qt.NoPen)
        painter.drawRoundedRect(self.contentsRect(), 2, 2)
        # Draw the Lines
        for i in range(len(self.data[0])):
            path = None
            pen = QtGui.QPen(self.colors[i % len(self.colors)])
            for j in range(len(self.data)):
                value = self.data[j][i]
                prevvalue = self.data[j-1][i]
                if value == -1 or prevvalue == -1:
                    continue
                if not self.showzero and value <= 0 and prevvalue <= 0:
                    continue
                x1 = (self.pxperpt * (j - 0.5) + self.pxperpt / 4) - self.offset
                x2 = (self.pxperpt * j + self.pxperpt / 4) - self.offset
                y1 = self.height() - int((self.height() - 1) * (prevvalue / self.maxvalue))
                y2 = self.height() - int((self.height() - 1) * (value / self.maxvalue))
                path = path or QtGui.QPainterPath(QtCore.QPointF(x1,y1))
                path.cubicTo(x1, y1, x1, y2, x2, y2)
            if path:
                painter.strokePath(path, pen)
        painter.end() 
Example 26
Project: dcc   Author: amimo   File: DisasmViewMode.py    License: Apache License 2.0 5 votes vote down vote up
def drawSelected(self, qp):
        qp.setFont(self.font)

        cursorX, cursorY = self.cursor.getPosition()

        if len(self.OPCODES) - 1 < cursorY:
            return

        asm = self.OPCODES[cursorY]
        _, width, text = asm.getSelectedToken(cursorX)

        for i, asm in enumerate(self.OPCODES):
            for idx, length, value in asm.tokens():
                # skip current cursor position
                if cursorY == i and cursorX == idx:
                    continue

                # check every line, if match, select it
                if value == text:
                    qp.setOpacity(0.4)
                    brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
                    qp.fillRect(idx * self.fontWidth,
                                i * self.fontHeight + 2,
                                width * self.fontWidth,
                                self.fontHeight,
                                brush)
                    qp.setOpacity(1) 
Example 27
Project: dcc   Author: amimo   File: SourceViewMode.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, themes, width, height, data, cursor, widget=None):
        super(SourceViewMode, self).__init__()

        self.themes = themes

        self.dataModel = data
        self.addHandler(self.dataModel)

        self.width = width
        self.height = height

        self.cursor = cursor
        self.widget = widget

        self.refresh = True

        # background brush
        self.backgroundBrush = QtGui.QBrush(self.themes['background'])

        # text font
        self.font = self.themes['font']

        # font metrics. assume font is monospaced
        self.font.setKerning(False)
        self.font.setFixedPitch(True)
        fm = QtGui.QFontMetrics(self.font)
        self._fontWidth = fm.width('a')
        self._fontHeight = fm.height()

        self.textPen = QtGui.QPen(self.themes['pen'], 0, QtCore.Qt.SolidLine)
        self.resize(width, height)

        self.Paints = {}
        self.Ops = []
        self.newPix = None

        self.selector = TextSelection.DefaultSelection(themes, self)

        self.LINES = self.dataModel.current_class.get_source().split('\n') 
Example 28
Project: dcc   Author: amimo   File: TextSelection.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, themes, viewMode):
        self.themes = themes
        self.viewMode = viewMode
        self.selecting = False
        self.Selections = []
        self.PermanentSelections = []
        self.MAX_SELECTIONS = 1
        self.defaultBrush = QtGui.QBrush(self.themes['selection'])

        self.last = 0
        self.HighlightSelections = [] 
Example 29
Project: dcc   Author: amimo   File: TextSelection.py    License: Apache License 2.0 5 votes vote down vote up
def stopSelection(self):
        if self.selecting:
            u, v = self.getCurrentSelection()

            self.addSelection((u, v, QtGui.QBrush(self.themes['selection']), 0.4), type=SelectionType.NORMAL)
            self.last = u, v

            self.selecting = False
            self.selectionStartOffset = None 
Example 30
Project: dcc   Author: amimo   File: HexViewMode.py    License: Apache License 2.0 5 votes vote down vote up
def selectionChanged(self, selected, deselected):
        item = self.ann_w.treeWidget.currentItem()
        if item:
            offset = item.getOffset()
            size = item.getSize()
            u = offset
            v = offset + size
            self.selector.addSelection((u, v, QtGui.QBrush(QtGui.QColor(125, 255, 0)), 0.2),
                                       type=TextSelection.SelectionType.NORMAL)
            self.goTo(u)