Exemple #1
0
    def __processUpdateColors(self):
        """Updates the list of colors to display
        calls __updateBackgroundPixmap to build pixmap
        calls update to redraw"""
        items = self.__sourceTree.findItems("",
                                            QtCore.Qt.MatchContains |
                                            QtCore.Qt.MatchRecursive,
                                            0)

        colors = []
        for item in items:
            color = QtGui.QBrush(item.data(0, QtCore.Qt.BackgroundRole))
            if color.color() == self.__baseColor:
                colors.append(None)
            else:
                colors.append(color)

        self.__colorsLock.lockForWrite()
        try:
            self.__colors = colors
        finally:
            self.__colorsLock.unlock()

        self.__updateBackgroundPixmap(colors)

        self.update()
    def __paintSelection(self, painter):
        if self.__selectionRange == None: return
        selection = (min(self.__selectionRange[0], self.__selectionRange[1]), max(self.__selectionRange[0], self.__selectionRange[1]))

        leftExtent = self.__getTickArea(selection[0])
        rightExtent = self.__getTickArea(selection[1] - 1)
        selectionExtent = QtCore.QRect(leftExtent.left(), leftExtent.top(), rightExtent.right() - leftExtent.left() + 2, leftExtent.height()/2)
        painter.fillRect(selectionExtent, QtGui.QBrush(QtGui.QColor(75, 75, 75)))
Exemple #3
0
 def _drawBackground(self, painter, option, index):
     # Draw the background color
     painter.setPen(NO_PEN)
     role = index.data(QtCore.Qt.BackgroundRole)
     if role is not None:
         painter.setBrush(QtGui.QBrush(role))
     else:
         painter.setBrush(NO_BRUSH)
     painter.drawRect(option.rect)
Exemple #4
0
 def _GenerateMissingSplash(self, app_name):
     image = QtGui.QImage(self.WIDTH, self.HEIGHT, QtGui.QImage.Format_RGB32)
     painter = QtGui.QPainter(image)
     painter.fillRect(image.rect(), QtGui.QBrush(QtGui.QColor(50, 50, 50)))
     font = QtGui.QFont("serif",
                        min((self.WIDTH / len(app_name))*1.4, 250), 75, True)
     painter.setFont(font)
     painter.setPen(QtGui.QColor(80, 80, 80))
     painter.drawText(30, image.height() - 60, app_name)
     return image
Exemple #5
0
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self, parent)

        self.__color = QtGui.QColor(55, 200, 55)
        self.__brush = QtGui.QBrush()
        self.__brush.setColor(self.__color)
        self.__brush.setStyle(QtCore.Qt.SolidPattern)

        self.__show = opencue.api.findShow("clo")
        self.__history = [0] * 100
        self.__line = 575
        self.__max = max(self.__line * 1.2, 80)

        self.__timer = QtCore.QTimer(self)
        self.__timer.timeout.connect(self.addNumber)

        self.__timer.start(10000)
Exemple #6
0
class AbstractDelegate(QtWidgets.QItemDelegate):
    """Handles drawing of items for the TreeWidget. Provides special handling
    for selected jobs in order to still display background color."""
    __colorInvalid = QtGui.QColor()
    __brushSelected = QtGui.QBrush(QtCore.Qt.Dense4Pattern)
    __colorUsed = QtGui.QColor(255, 0, 0)
    __colorFree = QtGui.QColor(0, 255, 0)

    def __init__(self, parent, jobProgressBarColumn=None, *args):
        QtWidgets.QItemDelegate.__init__(self, parent, *args)

    def paint(self, painter, option, index):
        if option.state & QtWidgets.QStyle.State_Selected:
            # If selected cell
            self._paintSelected(painter, option, index)
        else:
            # Everything else
            QtWidgets.QItemDelegate.paint(self, painter, option, index)

    def _paintDifferenceBar(self, painter, option, index, used, total):
        if not total:
            return
        painter.save()
        try:
            self._drawBackground(painter, option, index)

            rect = option.rect.adjusted(2, 6, -2, -6)
            ratio = rect.width() / float(total)
            length = int(ceil(ratio * (used)))
            painter.fillRect(rect, self.__colorUsed)
            painter.fillRect(rect.adjusted(length, 0, 0, 0), self.__colorFree)

            if option.state & QtWidgets.QStyle.State_Selected:
                self._drawSelectionOverlay(painter, option)
        finally:
            painter.restore()
            del painter

    def _drawProgressBar(self, painter, rect, frameStateTotals):
        """Returns the list that defines the column.
        @type  painter: QPainter
        @param painter: The painter to draw with
        @type  rect: QRect
        @param rect: The area to draw in
        @type  frameStateTotals: dict
        @param frameStateTotals: Dictionary of frame states and their amount"""
        ratio = rect.width() / float(
            sum([list(values)[1] for values in frameStateTotals]))
        for frameState in FRAME_STATES:
            length = int(ceil(ratio * list(frameStateTotals)[frameState][1]))
            if length > 0:
                rect.setWidth(length)
                painter.fillRect(rect, RGB_FRAME_STATE[frameState])
                rect.setX(rect.x() + length)

    def _paintSelected(self, painter, option, index):
        painter.save()
        try:
            self._drawBackground(painter, option, index)

            # Draw the selection overlay
            self._drawSelectionOverlay(painter, option)

            # Draw the icon, if any
            value = index.data(QtCore.Qt.DecorationRole)
            if value is not None:
                icon = QtGui.QIcon(value)
                icon.paint(painter, option.rect.adjusted(3, 1, -1, -1),
                           QtCore.Qt.AlignLeft)
                option.rect.adjust(22, 0, 0, 0)

            # Draw the text
            painter.setPen(QtGui.QColor(index.data(QtCore.Qt.ForegroundRole)))
            painter.setFont(QtGui.QFont(index.data(QtCore.Qt.FontRole)))
            painter.drawText(
                option.rect.adjusted(3, -1, -3, 0),
                QtCore.Qt.TextAlignmentRole | QtCore.Qt.AlignVCenter,
                str(index.data(QtCore.Qt.DisplayRole)))
        finally:
            painter.restore()
            del painter

    def _drawBackground(self, painter, option, index):
        # Draw the background color
        painter.setPen(NO_PEN)
        role = index.data(QtCore.Qt.BackgroundRole)
        if role is not None:
            painter.setBrush(QtGui.QBrush(role))
        else:
            painter.setBrush(NO_BRUSH)
        painter.drawRect(option.rect)

    def _drawSelectionOverlay(self, painter, option):
        # Draw the selection
        if option.rect.width() > 0:
            selectionPen = QtGui.QPen(self.__colorInvalid)
            selectionPen.setWidth(0)
            painter.setPen(selectionPen)
            painter.setBrush(self.__brushSelected)
            painter.drawRect(option.rect)
Exemple #7
0
 def __init__(self, parent, *args):
     AbstractDelegate.__init__(self, parent, *args)
     self.__color = QtGui.QColor(55, 200, 55)
     self.__brush = QtGui.QBrush()
     self.__brush.setColor(self.__color)
     self.__brush.setStyle(QtCore.Qt.SolidPattern)
Exemple #8
0
RGB_FRAME_STATE = {
    opencue.api.job_pb2.SUCCEEDED: QtGui.QColor(55, 200, 55),
    opencue.api.job_pb2.RUNNING: QtGui.QColor(200, 200, 55),
    opencue.api.job_pb2.WAITING: QtGui.QColor(135, 207, 235),
    opencue.api.job_pb2.DEPEND: QtGui.QColor(160, 32, 240),
    opencue.api.job_pb2.DEAD: QtGui.QColor(255, 0, 0),
    opencue.api.job_pb2.EATEN: QtGui.QColor(150, 0, 0)
}

# This controls display order
FRAME_STATES = (opencue.api.job_pb2.SUCCEEDED, opencue.api.job_pb2.RUNNING,
                opencue.api.job_pb2.WAITING, opencue.api.job_pb2.DEPEND,
                opencue.api.job_pb2.DEAD, opencue.api.job_pb2.EATEN)

NO_PEN = QtGui.QPen(QtCore.Qt.NoPen)
NO_BRUSH = QtGui.QBrush(QtCore.Qt.NoBrush)


class AbstractDelegate(QtWidgets.QItemDelegate):
    """Handles drawing of items for the TreeWidget. Provides special handling
    for selected jobs in order to still display background color."""
    __colorInvalid = QtGui.QColor()
    __brushSelected = QtGui.QBrush(QtCore.Qt.Dense4Pattern)
    __colorUsed = QtGui.QColor(255, 0, 0)
    __colorFree = QtGui.QColor(0, 255, 0)

    def __init__(self, parent, jobProgressBarColumn=None, *args):
        QtWidgets.QItemDelegate.__init__(self, parent, *args)

    def paint(self, painter, option, index):
        if option.state & QtWidgets.QStyle.State_Selected:
 def __paintBackground(self, painter):
     bgBrush = self.palette().window()
     painter.fillRect(0, 0, self.width() - self.__right_margin, self.height(), bgBrush)
     highlightBrush = QtGui.QBrush(QtGui.QColor(75, 75, 75))
     painter.fillRect(0, self.height()/2, self.width() - self.__right_margin+5, self.height()/2,  highlightBrush)
Exemple #10
0
class CueStateBarWidget(QtWidgets.QWidget):
    """Creates a bar that graphically displays the state of all jobs displayed"""
    __colorInvalid = QtGui.QColor()
    __brushPattern = QtGui.QBrush(QtCore.Qt.Dense4Pattern)
    def __init__(self, sourceTree, parent = None):
        """CueStateBar init
        @type  sourceTree: QTreeWidget
        @param sourceTree: The tree to get the jobs from
        @type  parent: QWidget
        @param parent: The parent widget"""
        QtWidgets.QWidget.__init__(self, parent)
        self.setContentsMargins(8, 1, 1, 1)
        self.setFixedWidth(22)

        self.__sourceTree = weakref.proxy(sourceTree)
        self.__colors = []
        self.__baseColor = QtGui.qApp.palette().color(QtGui.QPalette.Base)
        self.__colorsLock = QtCore.QReadWriteLock()
        self.__timer = QtCore.QTimer(self)
        self.__lastUpdate = 0

        self.__timer.timeout.connect(self.updateColors)
        self.__sourceTree.verticalScrollBar().valueChanged.connect(self.update)
        self.__sourceTree.verticalScrollBar().rangeChanged.connect(self.__updateColors)

        self.__timer.start(10000)

    def mousePressEvent(self, mouseEvent):
        """Sets the position on the scroll bar based on the click position
        @type  mouseEvent: QEvent
        @param mouseEvent: The mouse click event"""
        self.__movePosition(mouseEvent.y())

    def mouseMoveEvent(self, mouseEvent):
        """Sets the position on the scroll bar based on the mouse position
        @type  mouseEvent: QEvent
        @param mouseEvent: The mouse click event"""
        self.__movePosition(mouseEvent.y())

    def __movePosition(self, yPos):
        """Sets the position on the scroll bar based on the given position
        @type  yPos: int
        @param yPos: Vertical position on the widget"""
        scrollBar = self.__sourceTree.verticalScrollBar()
        docLength = scrollBar.maximum() + scrollBar.pageStep()
        pos = yPos * docLength/float(self.height())

        scrollBar.setValue(int(pos - scrollBar.pageStep()/2))

    def paintEvent(self, event):
        """Called when the widget is being redrawn
        @type  event: QEvent
        @param event: The draw event"""
        assert threading.currentThread().getName() == "MainThread"
        self.__colorsLock.lockForWrite()
        try:
            if not self.__colors:
                return
            colors = self.__colors
        finally:
            self.__colorsLock.unlock()

        painter = QtGui.QPainter(self)
        painter.save()
        try:
            rect = self.contentsRect()

            # Number of pixels per job
            ratio = float(rect.height())/len(colors)
            # How far down the slider is
            shift = self.__sourceTree.verticalScrollBar().value() * ratio
            # Length not covered by the slider
            offPage = self.__sourceTree.verticalScrollBar().maximum() * ratio

            painter.drawPixmap(self.contentsRect(),
                               self.__background,
                               self.__background.rect())

            # Draw the slider
            pen = QtGui.QPen(self.__colorInvalid)
            pen.setWidth(0)
            painter.setPen(pen)
            painter.setBrush(self.__brushPattern)
            painter.drawRect(rect.adjusted(2, shift, -2, -offPage + shift))
        finally:
            painter.restore()
            painter.end()
            del painter

    def __updateBackgroundPixmap(self, colors):
        """Updates the background image buffer based on the given colors
        @type  colors: list<QBrush>
        @param colors: List of job background colors"""
        # Could draw it the max size and allow the resize on drawPixmap
        # that way the same buffer is always used
        assert threading.currentThread().getName() == "MainThread"
        buffer = QtGui.QPixmap(self.contentsRect().size())
        buffer.fill(self.__baseColor)

        if colors:
            painter = QtGui.QPainter()
            painter.begin(buffer)
            try:
                rect = buffer.rect()

                # Number of jobs
                amount = len(colors)
                # Number of pixels per job
                ratio = float(rect.height())/amount

                for index, color in enumerate(colors):
                    if color:
                        painter.fillRect(rect.adjusted(0,
                                                       ratio * index,
                                                       0,
                                                       -(ratio * (amount - index - 1))),
                                         color)
            finally:
                painter.end()
                del painter

        self.__background = buffer

    def updateColors(self):
        """Calls __updateColors if it has been sufficient time since the last
        update"""
        if time.time() - self.__lastUpdate > 10:
            self.__updateColors()

    def __updateColors(self):
        """Calls __processUpdateColors in 1 second"""
        self.__lastUpdate = time.time()
        QtCore.QTimer.singleShot(1000, self.__processUpdateColors)

    def __processUpdateColors(self):
        """Updates the list of colors to display
        calls __updateBackgroundPixmap to build pixmap
        calls update to redraw"""
        items = self.__sourceTree.findItems("",
                                            QtCore.Qt.MatchContains |
                                            QtCore.Qt.MatchRecursive,
                                            0)

        colors = []
        for item in items:
            color = QtGui.QBrush(item.data(0, QtCore.Qt.BackgroundRole))
            if color.color() == self.__baseColor:
                colors.append(None)
            else:
                colors.append(color)

        self.__colorsLock.lockForWrite()
        try:
            self.__colors = colors
        finally:
            self.__colorsLock.unlock()

        self.__updateBackgroundPixmap(colors)

        self.update()