예제 #1
0
    def headerData(self, section, orientation, role):

        if role == QtCore.Qt.DisplayRole:
            if section == self.Columns.index(SIDE_A):
                return "Name"

            if section == self.Columns.index(SIDE_B):
                return "Name"

            if section == self.Columns.index("diff"):
                return "Diff"

        if role == QtCore.Qt.ForegroundRole:
            if section == self.Columns.index(SIDE_A):
                return QtGui.QColor(SIDE_COLOR[SIDE_A])

            if section == self.Columns.index(SIDE_B):
                return QtGui.QColor(SIDE_COLOR[SIDE_B])

        if role == QtCore.Qt.TextAlignmentRole:
            return QtCore.Qt.AlignCenter

        if role == QtCore.Qt.FontRole:
            font = QtGui.QFont()
            font.setBold(True)
            return font

        return super(ComparerModel, self).headerData(section,
                                                     orientation,
                                                     role)
예제 #2
0
    def data(self, index, role):

        if not index.isValid():
            return

        item = index.internalPointer()
        if role == QtCore.Qt.DecorationRole:  # icon

            column = index.column()
            if column == self.Name:

                # Allow a custom icon and custom icon color to be defined
                data = item.get("_document", {}).get("data", {})
                icon = data.get("icon", None)
                if icon is None and item.get("type") == "silo":
                    icon = "database"
                color = data.get("color", style.colors.default)

                if icon is None:
                    # Use default icons if no custom one is specified.
                    # If it has children show a full folder, otherwise
                    # show an open folder
                    has_children = self.rowCount(index) > 0
                    icon = "folder" if has_children else "folder-o"

                # Make the color darker when the asset is deprecated
                if item.get("deprecated", False):
                    color = QtGui.QColor(color).darker(250)

                try:
                    key = "fa.{0}".format(icon)  # font-awesome key
                    icon = qtawesome.icon(key, color=color)
                    return icon
                except Exception as exception:
                    # Log an error message instead of erroring out completely
                    # when the icon couldn't be created (e.g. invalid name)
                    log.error(exception)

                return

        if role == QtCore.Qt.ForegroundRole:  # font color
            if "deprecated" in item.get("tags", []):
                return QtGui.QColor(style.colors.light).darker(250)

        if role == self.ObjectIdRole:
            return item.get("_id", None)

        if role == self.DocumentRole:
            return item.get("_document", None)

        return super(AssetModel, self).data(index, role)
예제 #3
0
    def process(self, containers):
        """Color all selected tools the selected colors"""

        result = []
        comp = avalon.fusion.get_current_comp()

        # Get tool color
        first = containers[0]
        tool = first["_tool"]
        color = tool.TileColor

        if color is not None:
            qcolor = QtGui.QColor().fromRgbF(color["R"], color["G"],
                                             color["B"])
        else:
            qcolor = self._fallback_color

        # Launch pick color
        picked_color = self.get_color_picker(qcolor)
        if not picked_color:
            return

        with avalon.fusion.comp_lock_and_undo_chunk(comp):
            for container in containers:
                # Convert color to RGB 0-1 floats
                rgb_f = picked_color.getRgbF()
                rgb_f_table = {"R": rgb_f[0], "G": rgb_f[1], "B": rgb_f[2]}

                # Update tool
                tool = container["_tool"]
                tool.TileColor = rgb_f_table

                result.append(container)

        return result
예제 #4
0
 def paintEvent(self, event):
     painter = QtGui.QPainter()
     painter.begin(self)
     color = QtGui.QColor(self.colors[self.previous])
     painter.setPen(color)
     painter.setBrush(QtGui.QBrush(color))
     painter.drawEllipse(0, 1, 4, 4)
     painter.drawPixmap(3, 0, self.icons[self.level])
     painter.end()
예제 #5
0
    def data(self, index, role):

        if not index.isValid():
            return

        if role == QtCore.Qt.FontRole:

            if index.column() in (
                    self.Columns.index("namespace"),
                    self.Columns.index("name"),
            ):
                node = index.internalPointer()
                font = QtGui.QFont("Monospace")
                font.setStyleHint(QtGui.QFont.TypeWriter)
                font.setBold(node["isLatest"])
                font.setItalic(not node["isLatest"])
                return font

        if role == QtCore.Qt.ForegroundRole:

            if index.column() in (
                    self.Columns.index("namespace"),
                    self.Columns.index("name"),
            ):
                node = index.internalPointer()
                if not node["isLatest"]:
                    return QtGui.QColor(120, 120, 120)

        if role == QtCore.Qt.DecorationRole:

            if index.column() == self.Columns.index("name"):
                node = index.internalPointer()
                if "isLocked" in node:
                    is_locked = node["isLocked"]
                    set_locked = node["setLocked"]
                    if set_locked is None or set_locked == is_locked:
                        return self.status_icon[is_locked]
                    else:
                        return self.status_icon[set_locked + 2]

        return super(SelectionModel, self).data(index, role)
예제 #6
0
파일: lib.py 프로젝트: 81819152/pype
def get_additional_data(container):
    """Get Nuke's related data for the container

    Args:
        container(dict): the container found by the ls() function

    Returns:
        dict
    """

    node = container["_tool"]
    tile_color = node['tile_color'].value()
    if tile_color is None:
        return {}

    hex = '%08x' % tile_color
    rgba = [
        float(int(hex[0:2], 16)) / 255.0,
        float(int(hex[2:4], 16)) / 255.0,
        float(int(hex[4:6], 16)) / 255.0
    ]

    return {"color": QtGui.QColor().fromRgbF(rgba[0], rgba[1], rgba[2])}
예제 #7
0
    def data(self, index, role):

        if not index.isValid():
            return

        if role == QtCore.Qt.DisplayRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return ""
                return item[SIDE_A_DATA]["shortName"]

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return ""
                return item[SIDE_B_DATA]["shortName"]

        if role == QtCore.Qt.DecorationRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                if index == self._focused_indexes[SIDE_A]:
                    return self._focused_icons[0]

            elif self.Columns[column] == SIDE_B:
                if index == self._focused_indexes[SIDE_B]:
                    return self._focused_icons[1]

        if role == QtCore.Qt.ForegroundRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if not item[SIDE_A_DATA]["fromHost"]:
                    return QtGui.QColor("gray")

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if not item[SIDE_B_DATA]["fromHost"]:
                    return QtGui.QColor("gray")

        if role == QtCore.Qt.TextAlignmentRole:
            return QtCore.Qt.AlignCenter

        if role == QtCore.Qt.FontRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if item[SIDE_A_DATA]["fromHost"]:
                    bold = QtGui.QFont()
                    bold.setBold(True)
                    return bold
                else:
                    return

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if item[SIDE_B_DATA]["fromHost"]:
                    bold = QtGui.QFont()
                    bold.setBold(True)
                    return bold
                else:
                    return

        if role == self.HostSelectRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if item[SIDE_A_DATA]["fromHost"]:
                    return item[SIDE_A_DATA]["fullPath"]
                else:
                    return

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if item[SIDE_B_DATA]["fromHost"]:
                    return item[SIDE_B_DATA]["fullPath"]
                else:
                    return

        if role == self.DiffStateRole:
            column = index.column()

            if self.Columns[column] == "diff":
                item = index.internalPointer()

                name_state = item["matchMethod"]
                points_state = item["points"]
                uvmap_state = item["uvmap"]

                if not item.get(SIDE_A_DATA) or item[SIDE_A_DATA]["fromHost"]:
                    protected_A = -1
                else:
                    protected_A = item[SIDE_A_DATA]["protected"]
                if not item.get(SIDE_B_DATA) or item[SIDE_B_DATA]["fromHost"]:
                    protected_B = -1
                else:
                    protected_B = item[SIDE_B_DATA]["protected"]
                protected = (protected_A, protected_B)

                return name_state, points_state, uvmap_state, protected

        return super(ComparerModel, self).data(index, role)
예제 #8
0
class FusionSetToolColor(api.InventoryAction):
    """Update the color of the selected tools"""

    label = "Set Tool Color"
    icon = "plus"
    color = "#d8d8d8"
    _fallback_color = QtGui.QColor(1.0, 1.0, 1.0)

    def process(self, containers):
        """Color all selected tools the selected colors"""

        result = []
        comp = avalon.fusion.get_current_comp()

        # Get tool color
        first = containers[0]
        tool = first["_tool"]
        color = tool.TileColor

        if color is not None:
            qcolor = QtGui.QColor().fromRgbF(color["R"], color["G"],
                                             color["B"])
        else:
            qcolor = self._fallback_color

        # Launch pick color
        picked_color = self.get_color_picker(qcolor)
        if not picked_color:
            return

        with avalon.fusion.comp_lock_and_undo_chunk(comp):
            for container in containers:
                # Convert color to RGB 0-1 floats
                rgb_f = picked_color.getRgbF()
                rgb_f_table = {"R": rgb_f[0], "G": rgb_f[1], "B": rgb_f[2]}

                # Update tool
                tool = container["_tool"]
                tool.TileColor = rgb_f_table

                result.append(container)

        return result

    def get_color_picker(self, color):
        """Launch color picker and return chosen color

        Args:
            color(QtGui.QColor): Start color to display

        Returns:
            QtGui.QColor

        """

        color_dialog = QtWidgets.QColorDialog(color)
        color_dialog.setStyleSheet(style.load_stylesheet())

        accepted = color_dialog.exec_()
        if not accepted:
            return

        return color_dialog.selectedColor()
예제 #9
0
    def data(self, index, role):

        if not index.isValid():
            return

        if role == QtCore.Qt.DisplayRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if self._use_long_name:
                    return item[SIDE_A_DATA]["longName"]
                else:
                    return item[SIDE_A_DATA]["shortName"]

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if self._use_long_name:
                    return item[SIDE_B_DATA]["longName"]
                else:
                    return item[SIDE_B_DATA]["shortName"]

        if role == QtCore.Qt.ForegroundRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if not item[SIDE_A_DATA]["fromHost"]:
                    return QtGui.QColor("gray")

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if not item[SIDE_B_DATA]["fromHost"]:
                    return QtGui.QColor("gray")

        if role == QtCore.Qt.FontRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if item[SIDE_A_DATA]["fromHost"]:
                    bold = QtGui.QFont()
                    bold.setBold(True)
                    return bold
                else:
                    return

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if item[SIDE_B_DATA]["fromHost"]:
                    bold = QtGui.QFont()
                    bold.setBold(True)
                    return bold
                else:
                    return

        if role == self.HostSelectRole:
            column = index.column()

            if self.Columns[column] == SIDE_A:
                item = index.internalPointer()
                if not item.get(SIDE_A_DATA):
                    return
                if item[SIDE_A_DATA]["fromHost"]:
                    return item[SIDE_A_DATA]["longName"]
                else:
                    return

            if self.Columns[column] == SIDE_B:
                item = index.internalPointer()
                if not item.get(SIDE_B_DATA):
                    return
                if item[SIDE_B_DATA]["fromHost"]:
                    return item[SIDE_B_DATA]["longName"]
                else:
                    return

        if role == self.DiffStateRole:
            column = index.column()

            if self.Columns[column] == "diff":
                item = index.internalPointer()

                name_state = item["matchMethod"]
                points_state = item["points"]
                uvmap_state = item["uvmap"]

                return name_state, points_state, uvmap_state

        return super(ComparerModel, self).data(index, role)