Python PyQt5.QtGui.QBrush() Examples

The following are code examples for showing how to use PyQt5.QtGui.QBrush(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: dcc   Author: amimo   File: Banners.py    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 2
Project: dcc   Author: amimo   File: Banners.py    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 3
Project: dcc   Author: amimo   File: Banners.py    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 4
Project: Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader   Author: HA6Bots   File: rawscriptsmenu.py    MIT License 6 votes vote down vote up
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("Title: %s\n"%selectedScript.title)
            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.editedby.setText(selectedScript.editedby)
            self.currentTreeWidget.setForeground(0, QtGui.QBrush(QtGui.QColor("blue")))
        except AttributeError:
            pass
        self.updateColors() 
Example 5
Project: Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader   Author: HA6Bots   File: rawscriptsmenu.py    MIT License 6 votes vote down vote up
def updateColors(self):
        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":
                    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"))) 
Example 6
Project: cct   Author: awacha   File: outliers.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def data(self, index: QtCore.QModelIndex, role: int = QtCore.Qt.DisplayRole) -> typing.Any:
        if role == QtCore.Qt.DisplayRole:
            if index.column() == 0:
                return '{}'.format(self._data[index.row()].fsn)
            elif index.column() == 1:
                return '{:%Y-%m-%d %H:%M:%S}'.format(self._data[index.row()].date)
            elif index.column() == 2:
                return '{:.6f}'.format(self._data[index.row()].score) if np.isfinite(self._data[index.row()].score) else '--'
            elif index.column() == 3:
                return '{:.3f}'.format(self._data[index.row()].stdscore) if np.isfinite(self._data[index.row()].stdscore) else '--'
            elif index.column() == 4:
                return self._data[index.row()].verdict
        elif role == QtCore.Qt.BackgroundRole:
            if self._data[index.row()].isBad():
                return QtGui.QBrush(QtGui.QColor('red'))
        return None 
Example 7
Project: musaic   Author: al165   File: sliders.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(self._forground_color)
        brush.setStyle(Qt.SolidPattern)

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

        percent = (self.value - self.minimum) / (self.maximum - self.minimum)

        rect = QtCore.QRect(0, 0, width*percent, height)
        painter.fillRect(rect, brush)

        if self._text_color:
            painter.setPen(self._text_color)

        if self._show_text:
            rect = QtCore.QRect(0, 0, width, height)
            painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, str(f'{self.value}'))

        painter.end() 
Example 8
Project: musaic   Author: al165   File: sliders.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, e):
        painter = QtGui.QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(self._forground_color)
        brush.setStyle(Qt.SolidPattern)

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

        left_percent = (self.left - self.minimum) / (self.maximum - self.minimum)
        right_percent = (self.right - self.minimum) / (self.maximum - self.minimum)

        rect = QtCore.QRect(width*left_percent, 0, width*(right_percent - left_percent), height)
        painter.fillRect(rect, brush)

        if self._text_color:
            painter.setPen(self._text_color)

        if self._show_text:
            rect = QtCore.QRect(0, 0, width, height)
            painter.drawText(rect, Qt.AlignVCenter | Qt.AlignHCenter, str(f'{self.left}, {self.right}'))

        painter.end() 
Example 9
Project: PyQt-multifunctional-uart-helper   Author: IronSublimate   File: widgetpainter.py    MIT License 6 votes vote down vote up
def paintEvent(self, a0: QPaintEvent):
        # print("paint")
        painter = QPainter(self)

        # painter.begin(self)
        painter.drawPixmap(0, 0, self.width(), self.height(), self.qpix)
        if self.enable_extra_14_bytes and self.extra_data:
            pix_width = self.width() / self.imgWidth
            pix_height = self.height() / self.imgHeight
            # painter.setPen(QPen(Qt.red, -14))
            painter.setBrush(QBrush(Qt.red))
            painter.drawEllipse(self.extra_data[1] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[2] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[3] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)
            painter.drawEllipse(self.extra_data[4] * pix_width, self.extra_data[0] * pix_height, pix_width, pix_height)

        if self.enable_grid:
            painter.setPen(Qt.darkBlue)
            painter.drawLines(self.grid_points)
        # painter.end() 
Example 10
Project: eddy   Author: obdasystems   File: view.py    GNU General Public License v3.0 6 votes vote down vote up
def setGridSize(self, size):
        """
        Sets the grid size.
        """
        action = self.session.action('toggle_grid')
        size = clamp(size, 0)
        if size <= 0 or not action.isChecked():
            brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        else:
            image = QtGui.QImage(size, size, QtGui.QImage.Format_RGB32)
            image.fill(QtCore.Qt.white)
            painter = QtGui.QPainter(image)
            painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(80, 80, 80, 255)), 1, QtCore.Qt.SolidLine))
            painter.drawPoint(QtCore.QPointF(0, 0))
            painter.end()
            brush = QtGui.QBrush(image)
        self.setBackgroundBrush(brush) 
Example 11
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 6 votes vote down vote up
def importConceptNode(self, e):
        """
        Build a Concept node using the given QDomElement.
        :type e: QDomElement
        :rtype: ConceptNode
        """

        label = self.getLabelFromElement(e)
        node = self.importGenericNode(Item.ConceptNode, e)
        node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        node.setText(label.text())
        node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y')))))

        if label.text() == 'TOP':
            new_rc = 'Thing'
        elif label.text() == 'BOTTOM':
            new_rc = 'Nothing'
        else:
            new_rc = label.text()

        node.remaining_characters = e.attribute('remaining_characters', new_rc)

        return node 
Example 12
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 6 votes vote down vote up
def importIndividualNode(self, e):
        """
        Build an Individual node using the given QDomElement.
        :type e: QDomElement
        :rtype: IndividualNode
        """
        label = self.getLabelFromElement(e)
        node = self.importGenericNode(Item.IndividualNode, e)
        node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        node.setText(label.text())
        node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y')))))

        datatype = node.datatype
        if datatype is not None:
            #print('datatype.value', datatype.value)
            index = datatype.value.index(':')
            #print('index',index)
            new_rc = datatype.value[(index+1):len(label.text())]
            #print('new_rc',new_rc)
        else:
            new_rc = label.text()

        node.remaining_characters = e.attribute('remaining_characters', new_rc)

        return node 
Example 13
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 6 votes vote down vote up
def importRoleNode(self, e):
        """
        Build a Role node using the given QDomElement.
        :type e: QDomElement
        :rtype: RoleNode
        """
        label = self.getLabelFromElement(e)
        node = self.importGenericNode(Item.RoleNode, e)
        node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        node.setText(label.text())
        node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y')))))

        if label.text() == 'TOP':
            new_rc = 'TopObjectProperty'
        elif label.text() == 'BOTTOM':
            new_rc = 'BottomObjectProperty'
        else:
            new_rc = label.text()

        node.remaining_characters = e.attribute('remaining_characters', new_rc)

        return node 
Example 14
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 6 votes vote down vote up
def importAttributeNode(self, d, e):
        """
        Build an Attribute node using the given QDomElement.
        :type d: Diagram
        :type e: QDomElement
        :rtype: AttributeNode
        """
        x = e.firstChildElement('label')
        n = self.importGenericNode(d, Item.AttributeNode, e)
        n.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        n.setText(x.text())
        n.setTextPos(n.mapFromScene(QtCore.QPointF(int(x.attribute('x')), int(x.attribute('y')))))

        if x.text() == 'TOP':
            new_rc = 'TopDataProperty'
        elif x.text() == 'BOTTOM':
            new_rc = 'BottomDataProperty'
        else:
            new_rc = x.text()

        n.remaining_characters = e.attribute('remaining_characters', new_rc)

        return n 
Example 15
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 6 votes vote down vote up
def importRoleNode(self, d, e):
        """
        Build a Role node using the given QDomElement.
        :type d: Diagram
        :type e: QDomElement
        :rtype: RoleNode
        """
        x = e.firstChildElement('label')
        n = self.importGenericNode(d, Item.RoleNode, e)
        n.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        n.setText(x.text())
        n.setTextPos(n.mapFromScene(QtCore.QPointF(int(x.attribute('x')), int(x.attribute('y')))))

        if x.text() == 'TOP':
            new_rc = 'TopObjectProperty'
        elif x.text() == 'BOTTOM':
            new_rc = 'BottomObjectProperty'
        else:
            new_rc = x.text()

        n.remaining_characters = e.attribute('remaining_characters', new_rc)

        return n 
Example 16
Project: eddy   Author: obdasystems   File: qt.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width, height, color, border=None):
        """
        Initialize the icon.
        :type width: T <= int | float
        :type height: T <= int | float
        :type color: str
        :type border: str
        """
        pixmap = QtGui.QPixmap(width, height)
        painter = QtGui.QPainter(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
        painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
        if border:
            painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
            painter.drawPath(path)
        painter.end()
        super().__init__(pixmap) 
Example 17
Project: eddy   Author: obdasystems   File: attribute.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=20, height=20, brush=None, remaining_characters='attribute', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        brush = brush or AttributeNode.DefaultBrush
        pen = AttributeNode.DefaultPen
        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.selection = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.polygon = Polygon(QtCore.QRectF(-10, -10, 20, 20), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='attribute', pos=lambda: self.center() - QtCore.QPointF(0, 22), parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)



    #############################################
    #   INTERFACE
    ################################# 
Example 18
Project: eddy   Author: obdasystems   File: value_domain.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=90, height=40, brush=None, remaining_characters='valuedomain', **kwargs):
        """
        Initialize the ValueDomain node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        brush = brush or ValueDomainNode.DefaultBrush
        pen = ValueDomainNode.DefaultPen
        self.background = Polygon(QtCore.QRectF(-49, -24, 98, 48))
        self.selection = Polygon(QtCore.QRectF(-49, -24, 98, 48))
        self.polygon = Polygon(QtCore.QRectF(-45, -20, 90, 40), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(Datatype.string.value, pos=self.center, editable=False, movable=False, parent=self)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   PROPERTIES
    ################################# 
Example 19
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=80, height=40, brush=None, remaining_characters='facet', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        self.background = Polygon(self.createPolygon(88, 48))
        self.selection = Polygon(self.createPolygon(88, 48))
        self.polygon = Polygon(self.createPolygon(80, 40))
        self.polygonA = Polygon(self.createPolygonA(80, 40), FacetNode.DefaultBrushA, FacetNode.DefaultPenA)
        self.polygonB = Polygon(self.createPolygonA(80, 40), FacetNode.DefaultBrushB, FacetNode.DefaultPenB)

        self.remaining_characters = remaining_characters

        self.labelA = NodeLabel(Facet.length.value, pos=self.centerA, editable=False, movable=False, parent=self)
        self.labelB = FacetQuotedLabel(template='"32"', movable=False, pos=self.centerB, parent=self)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   PROPERTIES
    ################################# 
Example 20
Project: eddy   Author: obdasystems   File: restriction.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width=20, height=20, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        brush = brush or RestrictionNode.DefaultBrush
        pen = RestrictionNode.DefaultPen
        self.background = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.selection = Polygon(QtCore.QRectF(-14, -14, 28, 28))
        self.polygon = Polygon(QtCore.QRectF(-10, -10, 20, 20), brush, pen)
        self.label = NodeLabel(Restriction.Exists.toString(),
           pos=lambda: self.center() - QtCore.QPointF(0, 22),
           editable=False, parent=self)

    #############################################
    #   INTERFACE
    ################################# 
Example 21
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 22
Project: eddy   Author: obdasystems   File: palette.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, paintEvent):
        """
        Perform the painting of the button in the palette.
        :type paintEvent: QPaintEvent
        """
        icon = self.icon()
        painter = QtGui.QPainter(self)
        if self.isChecked():
            painter.setBrush(QtGui.QBrush(QtGui.QColor(66, 165, 245)))
            painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(66, 165, 245)), 1.0))
            painter.drawRect(0, 0, 60, 44)
        painter.setOpacity(1.0 if self.isEnabled() else 0.33)
        painter.drawPixmap(0, 0, icon.pixmap(QtCore.QSize(60, 44)))

    #############################################
    #   INTERFACE
    ################################# 
Example 23
Project: BBoxEE   Author: persts   File: annotation_graphicsview.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent=None):
        """Class init function."""
        QtWidgets.QGraphicsView.__init__(self, parent)
        self.mode = Mode.PAN
        self.points = []
        self.point_graphics_items = []
        self.bbox = QtCore.QRectF()
        self.selected_bbox = None
        self.quad = Quad.TL
        self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
        self.brushes = [QtGui.QBrush(QtCore.Qt.blue, QtCore.Qt.SolidPattern),
                        QtGui.QBrush(QtCore.Qt.green, QtCore.Qt.SolidPattern),
                        QtGui.QBrush(QtCore.Qt.yellow, QtCore.Qt.SolidPattern),
                        QtGui.QBrush(QtCore.Qt.red, QtCore.Qt.SolidPattern)]
        self.pens = [QtGui.QPen(self.brushes[0], 2),
                     QtGui.QPen(self.brushes[1], 2),
                     QtGui.QPen(self.brushes[2], 2),
                     QtGui.QPen(self.brushes[3], 2)] 
Example 24
Project: libView   Author: liyanqing1987   File: libView.py    GNU General Public License v2.0 5 votes vote down vote up
def updateCellListTree(self):
        """
        Update liberty-cell information on left sideBar.
        """
        self.cellListTree.clear()

        for libraryFileName in self.libDic.keys():
            libItem = QTreeWidgetItem(self.cellListTree)
            libItem.setText(0, libraryFileName)
            libItem.setForeground(0, QBrush(Qt.blue))
            cellList = list(self.libDic[libraryFileName]['cellList'])

            # Sort cell name with cell size (***D\d+***). 
            sortedCellList = self.sortCellWithSize(cellList)

            # Show cells on left sideBar. 
            for cellName in sortedCellList:
                cellItem = QTreeWidgetItem(libItem)
                cellItem.setText(0, cellName)
                cellItem.setForeground(0, QBrush(Qt.green))
                if (libraryFileName in self.specifiedLibDic) and (cellName in self.specifiedLibDic[libraryFileName]):
                    cellItem.setCheckState(0, Qt.Checked)
                else:
                    cellItem.setCheckState(0, Qt.Unchecked)

        self.cellListTree.expandAll() 
Example 25
Project: ILTIS   Author: grg2rsr   File: Data_Selector_Widget.py    GNU General Public License v2.0 5 votes vote down vote up
def init_data(self):
                
        self.Main.Data.Metadata.paths = self.Main.Data.Metadata.paths
        self.setRowCount(len(self.Main.Data.Metadata.paths))
        
        # table entries
        for n, path in enumerate(self.Main.Data.Metadata.paths):
            self.setItem(n, 0, QtWidgets.QTableWidgetItem(self.Main.Data.Metadata.trial_labels[n]))
            
            color = self.Main.Options.view['colors'][n]
            QColor = QtGui.QColor(*color)
            QColor.setAlpha(100)
            self.item(n, 0).setBackground(QtGui.QBrush(QColor))  # FIXME find color solution

            verticalHeader = QtWidgets.QTableWidgetItem(str(n))
            verticalHeader.setBackground(QtGui.QBrush(QColor))
            
            QColor.setAlpha(255)
            verticalHeader.setForeground(QColor)
            
            self.setVerticalHeaderItem(n, verticalHeader)

        # connect
        self.itemSelectionChanged.connect(self.selection_changed)
        self.itemChanged.connect(self.labels_changed)
        
        # select all on startup
        selection = QtWidgets.QTableWidgetSelectionRange(0,0,len(self.Main.Data.Metadata.paths) - 1, 0)
        self.setRangeSelected(selection, True)
        
        self.verticalHeader().setStyle(QtWidgets.QStyleFactory.create('Cleanlooks')) # check on windows machines
        pass 
Example 26
Project: dcc   Author: amimo   File: DisasmViewMode.py    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    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    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    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    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) 
Example 31
Project: dcc   Author: amimo   File: BinViewMode.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, themes, width, height, data, cursor, widget=None):
        super(BinViewMode, self).__init__()

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

        self.width = width
        self.height = height

        self.cursor = cursor
        self.widget = widget

        self.refresh = True

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

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

        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.newPix = None
        self.Ops = [] 
Example 32
Project: Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader   Author: HA6Bots   File: rawscriptsmenu.py    MIT License 5 votes vote down vote up
def changeSelected(self):
        try:
            if not self.treeWidget.currentItem().text(0) in videoscriptcore.getCategories():
                scriptName = self.treeWidget.currentItem().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":
                        self.currentTreeWidget.setForeground(0, QtGui.QBrush(QtGui.QColor("black")))
                        self.startEditing.setEnabled(True)
                        self.flagComplete.setEnabled(True)
                        self.flagscriptquality.setEnabled(True)
                    elif status == "EDITING":
                        self.currentTreeWidget.setForeground(0, QtGui.QBrush(QtGui.QColor("yellow")))
                        self.startEditing.setEnabled(False)
                        self.flagComplete.setEnabled(False)
                        self.flagscriptquality.setEnabled(False)
                    elif status == "COMPLETE":
                        self.currentTreeWidget.setForeground(0, QtGui.QBrush(QtGui.QColor("green")))
                        self.startEditing.setEnabled(False)
                        self.flagComplete.setEnabled(False)
                        self.flagscriptquality.setEnabled(False)
                    elif status == "MANUALCOMPLETE":
                        self.currentTreeWidget.setForeground(0, QtGui.QBrush(QtGui.QColor("darkgreen")))
                        self.startEditing.setEnabled(False)
                        self.flagComplete.setEnabled(False)
                        self.flagscriptquality.setEnabled(False)
                    if self.isEditing:
                        self.startEditing.setEnabled(False)

                self.updateDetailScreen()
        except AttributeError:
            self.updateDetailScreen() 
Example 33
Project: Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader   Author: HA6Bots   File: rawscriptsmenu.py    MIT License 5 votes vote down vote up
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":
                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 34
Project: Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader   Author: HA6Bots   File: rawscriptsmenu.py    MIT License 5 votes vote down vote up
def resetColor(self):
        for i in range(self.treeWidget.topLevelItemCount()):
            #for y in range(self.treeWidget.)
            self.treeWidget.topLevelItem(i).setForeground(i, QtGui.QBrush(QtGui.QColor("black"))) 
Example 35
Project: cct   Author: awacha   File: logviewer.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def data(self, modelindex, role=None):
        if role is None:
            role = QtCore.Qt.DisplayRole
        if role == QtCore.Qt.DisplayRole:
            rec = self.records()[modelindex.row()]
            return str(getattr(rec, self.columnConfig[modelindex.column()][0]))
        elif role == QtCore.Qt.BackgroundRole:
            rec = self.records()[modelindex.row()]
            assert isinstance(rec, logging.LogRecord)
            if rec.levelno >= logging.CRITICAL:
                return QtGui.QBrush(Qt.red)
            else:
                return None
        elif role == QtCore.Qt.ForegroundRole:
            rec = self.records()[modelindex.row()]
            assert isinstance(rec, logging.LogRecord)
            if rec.levelno >= logging.CRITICAL:
                return QtGui.QBrush(Qt.black)
            elif rec.levelno >= logging.ERROR:
                return QtGui.QBrush(Qt.red)
            elif rec.levelno >= logging.WARNING:
                return QtGui.QBrush(Qt.darkYellow)
            elif rec.levelno >= logging.INFO:
                return QtGui.QBrush(Qt.black)
            else:
                return QtGui.QBrush(Qt.gray)
        elif role == QtCore.Qt.TextAlignmentRole:
            return Qt.AlignTop | Qt.AlignLeft
        return None 
Example 36
Project: cct   Author: awacha   File: scripteditor.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def onCommandStarted(self, linenumber: int):
        logger.debug('Command started on line {:d}'.format(linenumber))
        es = QtWidgets.QTextEdit.ExtraSelection()
        fmt = QtGui.QTextCharFormat()
        fmt.setBackground(QtGui.QBrush(QtCore.Qt.green))
        es.format = fmt
        cursor = QtGui.QTextCursor(self.document)
        cursor.movePosition(QtGui.QTextCursor.Start)
        cursor.movePosition(QtGui.QTextCursor.Down, QtGui.QTextCursor.MoveAnchor, linenumber)
        cursor.movePosition(QtGui.QTextCursor.StartOfLine, QtGui.QTextCursor.MoveAnchor)
        cursor.movePosition(QtGui.QTextCursor.EndOfLine, QtGui.QTextCursor.KeepAnchor)
        cursor.select(QtGui.QTextCursor.LineUnderCursor)
        es.cursor = cursor
        self.scriptEdit.setExtraSelections([es]) 
Example 37
Project: cct   Author: awacha   File: backgroundrunner.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def data(self, index: QtCore.QModelIndex, role: int = ...) -> Any:
        if index.column() == 0 and role == QtCore.Qt.CheckStateRole:
            return [QtCore.Qt.Unchecked, QtCore.Qt.Checked][self._jobs[index.row()].enabled]
        elif role == QtCore.Qt.BackgroundRole:
            if self._jobs[index.row()].errormessage is not None:
                return QtGui.QBrush(QtGui.QColor('red'))
            else:
                return None
        elif role == QtCore.Qt.ToolTipRole:
            return self._jobs[index.row()].errormessage
        elif role == QtCore.Qt.UserRole:
            return self._jobs[index.row()]
        return None 
Example 38
Project: MeiTingTrunk   Author: Xunius   File: _MainFrameLibTreeSlots.py    GNU General Public License v3.0 5 votes vote down vote up
def removeFolderHighlights(self):

        ori_color=QBrush(QColor(255,255,255))
        root=self.libtree.invisibleRootItem()
        for item in iterTreeWidgetItems(self.libtree, root):
            item.setBackground(0, ori_color)

        return 
Example 39
Project: eddy   Author: obdasystems   File: session.py    GNU General Public License v3.0 5 votes vote down vote up
def doRefactorBrush(self):
        """
        Change the node brush for all the predicate nodes matching the selected predicate.
        """
        diagram = self.mdi.activeDiagram()
        if diagram:
            diagram.setMode(DiagramMode.Idle)
            fn = lambda x: x.type() in {Item.ConceptNode, Item.RoleNode, Item.AttributeNode, Item.IndividualNode}
            node = first(diagram.selectedNodes(filter_on_nodes=fn))
            if node:
                action = self.sender()
                color = action.data()
                nodes = self.project.predicates(node.type(), node.text())
                self.undostack.push(CommandNodeSetBrush(diagram, nodes, QtGui.QBrush(QtGui.QColor(color.value)))) 
Example 40
Project: eddy   Author: obdasystems   File: session.py    GNU General Public License v3.0 5 votes vote down vote up
def doSetNodeBrush(self):
        """
        Set the brush of selected nodes.
        """
        diagram = self.mdi.activeDiagram()
        if diagram:
            diagram.setMode(DiagramMode.Idle)
            action = self.sender()
            color = action.data()
            brush = QtGui.QBrush(QtGui.QColor(color.value))
            supported = {Item.ConceptNode, Item.RoleNode, Item.AttributeNode, Item.IndividualNode}
            fn = lambda x: x.type() in supported and x.brush() != brush
            selected = diagram.selectedNodes(filter_on_nodes=fn)
            if selected:
                self.undostack.push(CommandNodeSetBrush(diagram, selected, brush)) 
Example 41
Project: eddy   Author: obdasystems   File: session.py    GNU General Public License v3.0 5 votes vote down vote up
def BackgrounddeColourNodesAndEdges(self,**kwargs):

        call_update_node = kwargs.get('call_updateNode',True)
        call_ClearInconsistentEntitiesAndDiagItemsData = kwargs.get('call_ClearInconsistentEntitiesAndDiagItemsData',True)

        brush = QtGui.QBrush(QtCore.Qt.NoBrush)

        all_nodes = list(self.project.nodes())
        all_edges = list(self.project.edges())

        for node in all_nodes:

            node.selection.setBrush(brush)
            node.setCacheMode(AbstractItem.NoCache)
            node.setCacheMode(AbstractItem.DeviceCoordinateCache)
            node.update(node.boundingRect())

            if call_update_node is True:
                node.updateNode()

        for edge in all_edges:

            edge.selection.setBrush(brush)
            edge.setCacheMode(AbstractItem.NoCache)
            edge.setCacheMode(AbstractItem.DeviceCoordinateCache)
            edge.update(edge.boundingRect())

        if call_ClearInconsistentEntitiesAndDiagItemsData:
            self.ClearInconsistentEntitiesAndDiagItemsData()

        diags = self.project.diagrams()

        for d in diags:
            d.sgnUpdated.emit() 
Example 42
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 5 votes vote down vote up
def importValueDomainNode(self, e):
        """
        Build a Value-Domain node using the given QDomElement.
        :type e: QDomElement
        :rtype: ValueDomainNode
        """
        label = self.getLabelFromElement(e)
        node = self.importGenericNode(Item.ValueDomainNode, e)
        node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        node.setText(label.text())
        node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y')))))
        return node 
Example 43
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 5 votes vote down vote up
def importIndividualNode(self, d, e):
        """
        Build an Individual node using the given QDomElement.
        :type d: Diagram
        :type e: QDomElement
        :rtype: IndividualNode
        """
        x = e.firstChildElement('label')
        n = self.importGenericNode(d, Item.IndividualNode, e)
        n.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        n.setText(x.text())
        n.setTextPos(n.mapFromScene(QtCore.QPointF(int(x.attribute('x')), int(x.attribute('y')))))

        datatype = n.datatype
        if datatype is not None:
            #print('datatype.value', datatype.value)
            index = datatype.value.index(':')
            #print('index',index)
            new_rc = datatype.value[(index+1):len(x.text())]
            #print('new_rc',new_rc)
        else:
            new_rc = x.text()

        n.remaining_characters = e.attribute('remaining_characters', new_rc)

        return n 
Example 44
Project: eddy   Author: obdasystems   File: graphol.py    GNU General Public License v3.0 5 votes vote down vote up
def importValueDomainNode(self, d, e):
        """
        Build a Value-Domain node using the given QDomElement.
        :type d: Diagram
        :type e: QDomElement
        :rtype: ValueDomainNode
        """
        x = e.firstChildElement('label')
        n = self.importGenericNode(d, Item.ValueDomainNode, e)
        n.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc'))))
        n.setText(x.text())
        n.setTextPos(n.mapFromScene(QtCore.QPointF(int(x.attribute('x')), int(x.attribute('y')))))
        return n 
Example 45
Project: eddy   Author: obdasystems   File: domain_restriction.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, brush=None, **kwargs):
        """
        Initialize the node.
        :type brush: QBrush
        """
        super().__init__(brush=QtGui.QBrush(QtGui.QColor(252, 252, 252, 255)), **kwargs)

    #############################################
    #   INTERFACE
    ################################# 
Example 46
Project: eddy   Author: obdasystems   File: range_restriction.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, brush=None, **kwargs):
        """
        Initialize the node.
        :type brush: QBrush
        """
        super().__init__(brush=QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), **kwargs)

    #############################################
    #   INTERFACE
    ################################# 
Example 47
Project: eddy   Author: obdasystems   File: attribute.py    GNU General Public License v3.0 5 votes vote down vote up
def updateNode(self, functional=None, **kwargs):
        """
        Update the current node.
        :type functional: bool
        """
        if functional is None:
            functional = self.isFunctional()

        # FUNCTIONAL POLYGON (SHAPE)
        path1 = QtGui.QPainterPath()
        path1.addEllipse(self.polygon.geometry())
        path2 = QtGui.QPainterPath()
        path2.addEllipse(QtCore.QRectF(-7, -7, 14, 14))
        self.fpolygon.setGeometry(path1.subtracted(path2))

        # FUNCTIONAL POLYGON (PEN & BRUSH)
        pen = QtGui.QPen(QtCore.Qt.NoPen)
        brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        if functional:
            pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
            brush = QtGui.QBrush(QtGui.QColor(252, 252, 252, 255))
        self.fpolygon.setPen(pen)
        self.fpolygon.setBrush(brush)

        # SELECTION + BACKGROUND + CACHE REFRESH
        super().updateNode(**kwargs) 
Example 48
Project: eddy   Author: obdasystems   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=60, height=60, brush=None, remaining_characters='individual', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        w = max(width, 60)
        h = max(height, 60)
        brush = brush or IndividualNode.DefaultBrush
        pen = IndividualNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
        ])

        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='individual', pos=self.center, parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos() 
Example 49
Project: eddy   Author: obdasystems   File: role_chain.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, brush=None, inputs=None, **kwargs):
        """
        Initialize the node.
        :type brush: QBrush
        :type inputs: DistinctList
        """
        super().__init__(brush=QtGui.QBrush(QtGui.QColor(252, 252, 252, 255)), **kwargs)
        self.inputs = inputs or DistinctList()
        self.label = NodeLabel('chain', pos=self.center, editable=False, movable=False, parent=self)

    #############################################
    #   INTERFACE
    ################################# 
Example 50
Project: eddy   Author: obdasystems   File: role_inverse.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, brush=None, **kwargs):
        """
        Initialize the node.
        :type brush: QBrush
        """
        super().__init__(brush=QtGui.QBrush(QtGui.QColor(252, 252, 252, 255)), **kwargs)
        self.label = NodeLabel('inv', pos=self.center, editable=False, movable=False, parent=self)

    #############################################
    #   INTERFACE
    #################################