Exemplo n.º 1
0
    def test_DisplayGamma(self):
        # Check that the display gamma functions work too
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec3f(.5, .5, .5), 2.2) ==
            Gf.ConvertDisplayToLinear(Gf.Vec3f(.5, .5, .5)))
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec3d(.5, .5, .5), 2.2) ==
            Gf.ConvertDisplayToLinear(Gf.Vec3d(.5, .5, .5)))
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec4f(.5, .5, .5, .8), 2.2) ==
            Gf.ConvertDisplayToLinear(Gf.Vec4f(.5, .5, .5, .8)))
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec4d(.5, .5, .5, .8), 2.2) ==
            Gf.ConvertDisplayToLinear(Gf.Vec4d(.5, .5, .5, .8)))

        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec3f(.5, .5, .5), 1.0 / 2.2) ==
            Gf.ConvertLinearToDisplay(Gf.Vec3f(.5, .5, .5)))
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec3d(.5, .5, .5), 1.0 / 2.2) ==
            Gf.ConvertLinearToDisplay(Gf.Vec3d(.5, .5, .5)))
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec4f(.5, .5, .5, .8), 1.0 / 2.2) ==
            Gf.ConvertLinearToDisplay(Gf.Vec4f(.5, .5, .5, .8)))
        self.assertTrue(
            Gf.ApplyGamma(Gf.Vec4d(.5, .5, .5, .8), 1.0 / 2.2) ==
            Gf.ConvertLinearToDisplay(Gf.Vec4d(.5, .5, .5, .8)))
 def _OnPushed(self):
     if self.valueType.dimension in (3, 4):
         options = QtWidgets.QColorDialog.ColorDialogOptions()
         displayColor = QtGui.QColor(
             *[255 * v for v in Gf.ConvertLinearToDisplay(self.value)])
         if self.valueType.dimension == 4:
             options = QtWidgets.QColorDialog.ShowAlphaChannel
         newColor = QtWidgets.QColorDialog.getColor(displayColor, self,
                                                    unicode(self.valueType),
                                                    options)
         if newColor.isValid():
             if self.valueType.dimension == 3:
                 value = (newColor.red(), newColor.green(), newColor.blue())
             elif self.valueType.dimension == 4:
                 value = (newColor.red(), newColor.green(), newColor.blue(),
                          newColor.alpha())
             value = self.valueType(*(v / 255.0 for v in value))
             value = Gf.ConvertDisplayToLinear(value)
             self.value = self.valueType(*(round(v, 2) for v in value))
             self._changed = True
Exemplo n.º 3
0
    def PaintColor(self, painter, option, index):
        # type: (QtGui.QPainter, QtWidgets.QStyleOptionViewItem, QtCore.QModelIndex) -> None
        """
        Parameters
        ----------
        painter : QtGui.QPainter
        option : QtWidgets.QStyleOptionViewItem
        index : QtCore.QModelIndex
        """
        super(ValueDelegate, self).paint(painter, option, QtCore.QModelIndex())

        vecData = index.data(QtCore.Qt.EditRole)
        if not vecData:
            return
        if len(vecData) not in (3, 4):
            raise Exception("Paint color only supports color3f and color4f.")

        vecOption = QtWidgets.QStyleOptionViewItem(option)
        self.initStyleOption(vecOption, index)
        style = QtWidgets.QApplication.style()
        left = vecOption.rect.left()
        top = vecOption.rect.top()
        width = vecOption.rect.width()
        height = vecOption.rect.height()
        colorWidth = 20
        pad = 5
        columns = vecData.dimension
        cellWidth = (width - colorWidth) / columns

        displayVecData = Gf.ConvertLinearToDisplay(vecData)
        painter.save()
        painter.setBrush(QtGui.QColor(*[c * 255 for c in displayVecData]))
        painter.setPen(QtCore.Qt.NoPen)
        painter.drawRect(left, top, colorWidth, height)
        painter.restore()

        for i in xrange(columns):
            cellRect = QtCore.QRect(colorWidth + pad + left + cellWidth * i,
                                    top, cellWidth, height)
            style.drawItemText(painter, cellRect, vecOption.displayAlignment,
                               vecOption.palette, True, str(vecData[i]))
 def _SetButtonColor(self):
     assert (self.valueType.dimension in (3, 4))
     value = Gf.ConvertLinearToDisplay(self.value)
     self._colorButton.displayColor = QtGui.QColor(
         *[255 * v for v in value])