Ejemplo n.º 1
0
class TestCaptureStream(object):
    """Allows the output of the tests to be displayed in a QTextEdit."""
    success_color = QtGui.QColor(92, 184, 92)
    fail_color = QtGui.QColor(240, 173, 78)
    error_color = QtGui.QColor(217, 83, 79)
    skip_color = QtGui.QColor(88, 165, 204)
    normal_color = QtGui.QColor(200, 200, 200)

    def __init__(self, text_edit):
        self.text_edit = text_edit

    def write(self, text):
        """Write text into the QTextEdit."""
        # Color the output
        if text.startswith('ok'):
            self.text_edit.setTextColor(TestCaptureStream.success_color)
        elif text.startswith('FAIL'):
            self.text_edit.setTextColor(TestCaptureStream.fail_color)
        elif text.startswith('ERROR'):
            self.text_edit.setTextColor(TestCaptureStream.error_color)
        elif text.startswith('skipped'):
            self.text_edit.setTextColor(TestCaptureStream.skip_color)

        self.text_edit.insertPlainText(text)
        self.text_edit.setTextColor(TestCaptureStream.normal_color)

    def flush(self):
        pass
Ejemplo n.º 2
0
 def set_color(self):
     """Open a dialog to set the override RGB color of the selected nodes."""
     nodes = cmds.ls(sl=True) or []
     if nodes:
         color = cmds.getAttr('{0}.overrideColorRGB'.format(nodes[0]))[0]
         color = QtGui.QColor(color[0] * 255, color[1] * 255,
                              color[2] * 255)
         color = QtWidgets.QColorDialog.getColor(color, self,
                                                 'Set Curve Color')
         if color.isValid():
             color = [color.redF(), color.greenF(), color.blueF()]
             for node in nodes:
                 cmds.setAttr('{0}.overrideEnabled'.format(node), True)
                 cmds.setAttr('{0}.overrideRGBColors'.format(node), True)
                 cmds.setAttr('{0}.overrideColorRGB'.format(node), *color)
Ejemplo n.º 3
0
 def paintEvent(self, event):
     painter = QtGui.QPainter(self)
     color = QtGui.QColor(72, 170, 181)
     painter.setPen(color)
     painter.drawRect(0, 0, self.width() - 1, self.height() - 1)
Ejemplo n.º 4
0
class ComponentWidget(QtWidgets.QFrame):
    """The widget used to display a Component in the ComponentQueue."""
    normal_color = QtGui.QColor(72, 170, 181)
    error_color = QtGui.QColor(217, 83, 79)
    break_point_disabled_icon = QtGui.QIcon(QtGui.QPixmap(':/stopClip.png'))
    break_point_enabled_icon = QtGui.QIcon(QtGui.QPixmap(':/timestop.png'))

    def __init__(self, comp, queue, parent=None):
        super(ComponentWidget, self).__init__(parent)
        self.setMouseTracking(True)
        self.queue_layout = parent.queue_layout
        self.queue = queue
        self.comp = comp
        vbox = QtWidgets.QVBoxLayout(self)
        self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
        self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                           QtWidgets.QSizePolicy.Maximum)
        self.over_grab_hotspot = False
        self.color = ComponentWidget.normal_color

        # Header
        hbox = QtWidgets.QHBoxLayout()
        self.header_layout = hbox
        hbox.setContentsMargins(16, 4, 4, 4)
        vbox.addLayout(hbox)

        # Expand toggle
        expand_action = QtWidgets.QAction('Toggle', self)
        expand_action.setCheckable(True)
        icon = QtGui.QIcon(QtGui.QPixmap(':/arrowDown.png'))
        expand_action.setIcon(icon)
        expand_action.setToolTip('Toggle details')
        expand_action.setStatusTip('Toggle details')
        button = QtWidgets.QToolButton()
        button.setDefaultAction(expand_action)
        hbox.addWidget(button)

        # Enable checkbox
        enabled = QtWidgets.QCheckBox()
        enabled.setToolTip('Enable/Disable Component')
        hbox.addWidget(enabled)

        # Breakpoint
        self.break_point_action = QtWidgets.QAction('Breakpoint', self)
        self.break_point_action.setCheckable(True)
        self.break_point_action.setIcon(self.break_point_disabled_icon)
        self.break_point_action.setToolTip('Set break point at component.')
        self.break_point_action.setStatusTip('Set break point at component.')
        self.break_point_action.toggled.connect(self.set_break_point)
        button = QtWidgets.QToolButton()
        button.setDefaultAction(self.break_point_action)
        hbox.addWidget(button)

        # Execute button
        action = QtWidgets.QAction('Execute', self)
        icon = QtGui.QIcon(QtGui.QPixmap(':/timeplay.png'))
        action.setIcon(icon)
        action.setToolTip('Execute the component')
        action.setStatusTip('Execute the component')
        action.triggered.connect(
            partial(self.execute_component,
                    on_error=parent.on_component_execution_error))
        button = QtWidgets.QToolButton()
        button.setDefaultAction(action)
        hbox.addWidget(button)

        # Image label
        label = QtWidgets.QLabel()
        label.setPixmap(comp.image(size=24))
        label.setToolTip(comp.__class__.__doc__)
        hbox.addWidget(label)

        # Name label
        label = QtWidgets.QLabel(comp.name().split('.')[-1])
        label.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                            QtWidgets.QSizePolicy.Fixed)
        label.setToolTip(comp.__class__.__doc__)
        font = QtGui.QFont()
        font.setPointSize(14)
        label.setFont(font)
        hbox.addWidget(label)
        hbox.addStretch()

        if comp.help_url():
            action = QtWidgets.QAction('Help', self)
            icon = QtGui.QIcon(QtGui.QPixmap(':/help.png'))
            action.setIcon(icon)
            action.setToolTip('Open help documentation.')
            action.setStatusTip('Open help documentation.')
            action.triggered.connect(partial(webbrowser.open, comp.help_url()))
            button = QtWidgets.QToolButton()
            button.setDefaultAction(action)
            hbox.addWidget(button)

        action = QtWidgets.QAction('Delete', self)
        icon = QtGui.QIcon(QtGui.QPixmap(':/smallTrash.png'))
        action.setIcon(icon)
        message = 'Delete Component'
        action.setToolTip(message)
        action.setStatusTip(message)
        action.triggered.connect(partial(self.remove, prompt=True))
        button = QtWidgets.QToolButton()
        button.setDefaultAction(action)
        hbox.addWidget(button)

        content_vbox = QtWidgets.QVBoxLayout()
        content_vbox.setContentsMargins(16, 0, 0, 0)
        vbox.addLayout(content_vbox)

        content_widget = comp.widget()
        content_vbox.addWidget(content_widget)
        enabled.toggled.connect(content_widget.setEnabled)
        enabled.setChecked(comp.enabled)
        enabled.toggled.connect(comp.set_enabled)
        expand_action.toggled.connect(content_widget.setVisible)
        content_widget.setVisible(False)

        # content_widget = QtWidgets.QWidget()
        # content_layout = QtWidgets.QVBoxLayout(content_widget)
        # content_layout.setContentsMargins(16, 8, 0, 0)
        # vbox.addWidget(content_widget)
        # comp.draw(content_layout)
        # enabled.toggled.connect(content_widget.setEnabled)
        # enabled.setChecked(comp.enabled)
        # enabled.toggled.connect(comp.set_enabled)
        # expand_action.toggled.connect(content_widget.setVisible)
        # content_widget.setVisible(False)
        # content_layout.addStretch()

    def execute_component(self, on_error):
        self.set_color(ComponentWidget.normal_color)
        self.comp.capture_execute(on_error=on_error)

    def set_break_point(self, value):
        self.comp.break_point = value
        icon = self.break_point_enabled_icon if value else self.break_point_disabled_icon
        self.break_point_action.setIcon(icon)

    def grab_rect(self):
        """Get the rectangle describing the grab hotspot."""
        return QtCore.QRect(0, 0, 16, self.height() - 1)

    def set_color(self, color):
        """Set the color of status bar on the widget.

        :param color: The new color.
        """
        self.color = color
        self.update()

    def paintEvent(self, event):
        """Override the paintEvent to draw the grab hotspot.

        :param event:
        """
        super(ComponentWidget, self).paintEvent(event)
        painter = QtGui.QPainter(self)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(self.color)
        painter.drawRect(self.grab_rect())

    def mouseMoveEvent(self, event):
        contains = self.grab_rect().contains(event.pos())
        if contains and not self.over_grab_hotspot:
            QtWidgets.qApp.setOverrideCursor(
                QtGui.QCursor(QtCore.Qt.OpenHandCursor))
            self.over_grab_hotspot = True
        elif not contains and self.over_grab_hotspot:
            restore_cursor()
            self.over_grab_hotspot = False

    def leaveEvent(self, event):
        if self.over_grab_hotspot:
            restore_cursor()
            self.over_grab_hotspot = False

    def move(self, new_index):
        """Move the component to the specified index in the queue.

        :param new_index: Index to move to.
        """
        index = self.index()
        # Reorder the Component in the Queue
        self.queue.remove(index)

        if new_index and new_index > self.queue.length():
            # When we are moving a component to the bottom, the index may get greater than the max allowed
            new_index = self.queue.length()

        self.queue.insert(new_index, self.comp)
        # Reorder the ComponentWidget in the layout
        self.queue_layout.takeAt(index)
        self.queue_layout.insertWidget(new_index, self)

    def index(self):
        """Get the index of the Component. """
        return self.queue.index(self.comp)

    def remove(self, prompt=False):
        """Remove this Component from the queue.

        :param prompt: True to display a message box confirming the removal of the Component.
        """
        if prompt:
            msg_box = QtWidgets.QMessageBox()
            msg_box.setIcon(QtWidgets.QMessageBox.Question)
            msg_box.setText('Are you sure you want to remove this component?')
            msg_box.setStandardButtons(QtWidgets.QMessageBox.Yes
                                       | QtWidgets.QMessageBox.Cancel)
            if msg_box.exec_() != QtWidgets.QMessageBox.Yes:
                return
        index = self.queue.index(self.comp)
        self.queue.remove(index)
        self.queue_layout.takeAt(index)
        self.deleteLater()