Exemplo n.º 1
0
    def testIntToFloatConversion(self):

        s = Gaffer.Spreadsheet()
        s["rows"].addColumn(Gaffer.FloatPlug(defaultValue=1.0))
        s["rows"].addColumn(Gaffer.IntPlug(defaultValue=2))
        row = s["rows"].addRow()

        self.assertEqual(s["rows"][1]["cells"][0]["value"].getValue(), 1.0)
        self.assertEqual(s["rows"][1]["cells"][1]["value"].getValue(), 2)

        data = _ClipboardAlgo.valueMatrix([[row["cells"][1]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][0]]], 0)

        self.assertEqual(s["rows"][1]["cells"][0]["value"].getValue(), 2.0)
        self.assertEqual(s["rows"][1]["cells"][1]["value"].getValue(), 2)
Exemplo n.º 2
0
    def testPasteBasicValues(self):

        s = Gaffer.Spreadsheet()
        s["rows"].addColumn(Gaffer.IntPlug(defaultValue=1))
        s["rows"].addColumn(
            Gaffer.NameValuePlug("i", Gaffer.IntPlug(defaultValue=2)))
        row = s["rows"].addRow()

        data = IECore.IntData(3)

        plugMatrix = [s["rows"][1]["cells"].children()]
        self.assertTrue(_ClipboardAlgo.canPasteCells(data, plugMatrix))

        _ClipboardAlgo.pasteCells(data, plugMatrix, 0)

        self.assertEqual(row["cells"][0]["value"].getValue(), 3)
        self.assertEqual(row["cells"][1]["value"]["value"].getValue(), 3)
Exemplo n.º 3
0
    def testPasteCellsSetsKeyframe(self):

        s = self.__createSpreadsheet()
        script = Gaffer.ScriptNode()
        script["s"] = s

        targetPlug = s["rows"][2]["cells"][1]["value"]
        curve = Gaffer.Animation.acquire(targetPlug)
        curve.addKey(Gaffer.Animation.Key(0, 1001))
        self.assertFalse(curve.hasKey(1002))

        data = _ClipboardAlgo.valueMatrix([[s["rows"][5]["cells"][1]["value"]]
                                           ])
        _ClipboardAlgo.pasteCells(data, [[targetPlug]], 1002)

        self.assertTrue(curve.hasKey(1002))
        key = curve.getKey(1002)
        self.assertEqual(key.getValue(), 5)
Exemplo n.º 4
0
    def testStringConversion(self):

        s = Gaffer.Spreadsheet()
        s["rows"].addColumn(Gaffer.StringPlug())
        s["rows"].addColumn(
            Gaffer.StringVectorDataPlug(
                "v", defaultValue=IECore.StringVectorData()))
        row = s["rows"].addRow()

        bothColumns = [s["rows"][1]["cells"].children()]

        data = IECore.StringData("string")
        self.assertTrue(_ClipboardAlgo.canPasteCells(data, bothColumns))
        _ClipboardAlgo.pasteCells(data, bothColumns, 0)
        self.assertEqual(s["rows"][1]["cells"][0]["value"].getValue(),
                         "string")
        self.assertEqual(s["rows"][1]["cells"][1]["value"].getValue(),
                         IECore.StringVectorData(["string"]))

        for data in (IECore.StringVectorData([]),
                     IECore.StringVectorData(["one"])):
            self.assertTrue(_ClipboardAlgo.canPasteCells(data, bothColumns))
            _ClipboardAlgo.pasteCells(data, bothColumns, 0)
            self.assertEqual(s["rows"][1]["cells"][0]["value"].getValue(),
                             data[0] if data else "")
            self.assertEqual(s["rows"][1]["cells"][1]["value"].getValue(),
                             data)

        data = IECore.StringVectorData(["one", "two"])
        self.assertFalse(_ClipboardAlgo.canPasteCells(data, bothColumns))
        self.assertTrue(
            _ClipboardAlgo.canPasteCells(data, [[s["rows"][1]["cells"][1]]]))
        _ClipboardAlgo.pasteCells(data, [[s["rows"][1]["cells"][1]]], 0)
        self.assertEqual(s["rows"][1]["cells"][1]["value"].getValue(), data)
Exemplo n.º 5
0
    def testCellEnabled(self):

        # Test that cell enabled states are correctly remapped when
        # cross-pasting between simple, adopted and unadopted columns.

        s = Gaffer.Spreadsheet()
        s["rows"].addColumn(Gaffer.IntPlug(), "valueOnly")
        s["rows"].addColumn(Gaffer.NameValuePlug(
            "a", Gaffer.IntPlug(defaultValue=1), True),
                            "adopted",
                            adoptEnabledPlug=True)
        s["rows"].addColumn(Gaffer.NameValuePlug(
            "u", Gaffer.IntPlug(defaultValue=2), True),
                            "unadopted",
                            adoptEnabledPlug=False)
        row = s["rows"].addRow()

        def resetEnabledState():
            for cell in row["cells"].children():
                cell.enabledPlug().setValue(True)
            row["cells"]["unadopted"]["value"]["enabled"].setValue(True)

        def assertPostCondition(valueOnly, adopted, unadopted,
                                unadoptedEnabled):
            self.assertEqual(
                row["cells"]["valueOnly"].enabledPlug().getValue(), valueOnly)
            self.assertEqual(row["cells"]["adopted"].enabledPlug().getValue(),
                             adopted)
            self.assertEqual(
                row["cells"]["unadopted"].enabledPlug().getValue(), unadopted)
            self.assertEqual(
                row["cells"]["unadopted"]["value"]["enabled"].getValue(),
                unadoptedEnabled)

        self.assertEqual(row["cells"]["valueOnly"].enabledPlug(),
                         row["cells"]["valueOnly"]["enabled"])
        self.assertEqual(row["cells"]["adopted"].enabledPlug(),
                         row["cells"]["adopted"]["value"]["enabled"])
        self.assertEqual(row["cells"]["unadopted"].enabledPlug(),
                         row["cells"]["unadopted"]["enabled"])
        self.assertEqual(
            row["cells"]["unadopted"]["value"]["enabled"].getValue(), True)

        for source, targets, expected in (("valueOnly", ("adopted",
                                                         "unadopted"),
                                           (False, False, False, True)),
                                          ("adopted", ("valueOnly",
                                                       "unadopted"),
                                           (False, False, False, False)),
                                          ("unadopted", ("valueOnly",
                                                         "adopted"),
                                           (False, False, False, True))):

            resetEnabledState()
            row["cells"][source].enabledPlug().setValue(False)

            data = _ClipboardAlgo.valueMatrix([[row["cells"][source]]])
            _ClipboardAlgo.pasteCells(data,
                                      [[row["cells"][t] for t in targets]], 0)

            assertPostCondition(*expected)
Exemplo n.º 6
0
    def testNameValuePlugs(self):

        s = Gaffer.Spreadsheet()
        s["rows"].addColumn(
            Gaffer.NameValuePlug("a", Gaffer.IntPlug(defaultValue=1)))
        s["rows"].addColumn(
            Gaffer.NameValuePlug("b", Gaffer.IntPlug(defaultValue=2)))
        row = s["rows"].addRow()

        def assertNVPEqual(plug, name, enabled, value):
            self.assertEqual(plug["name"].getValue(), name)
            self.assertEqual(plug["value"].getValue(), value)
            if enabled is not None:
                self.assertEqual(plug["enabled"].getValue(), enabled)

        assertNVPEqual(row["cells"][0]["value"], "a", None, 1)
        assertNVPEqual(row["cells"][1]["value"], "b", None, 2)

        data = _ClipboardAlgo.valueMatrix([[row["cells"][1]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][0]]], 0)

        assertNVPEqual(row["cells"][0]["value"], "a", None, 2)
        assertNVPEqual(row["cells"][1]["value"], "b", None, 2)

        s["rows"].addColumn(
            Gaffer.NameValuePlug("c", Gaffer.IntPlug(defaultValue=3), True))
        s["rows"].addColumn(
            Gaffer.NameValuePlug("d", Gaffer.IntPlug(defaultValue=4), False))

        assertNVPEqual(row["cells"][2]["value"], "c", True, 3)
        assertNVPEqual(row["cells"][3]["value"], "d", False, 4)

        data = _ClipboardAlgo.valueMatrix([[row["cells"][3]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][2]]], 0)

        assertNVPEqual(row["cells"][2]["value"], "c", False, 4)
        assertNVPEqual(row["cells"][3]["value"], "d", False, 4)

        # Test cross-pasting between plugs with/without enabled plugs

        data = _ClipboardAlgo.valueMatrix([[row["cells"][3]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][0]]], 0)

        assertNVPEqual(row["cells"][0]["value"], "a", None, 4)

        data = _ClipboardAlgo.valueMatrix([[row["cells"][1]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][2]]], 0)

        assertNVPEqual(row["cells"][2]["value"], "c", False, 2)

        # Test cross-pasting between ValuePlugs and NameValuePlugs

        s["rows"].addColumn(Gaffer.IntPlug(defaultValue=5))

        data = _ClipboardAlgo.valueMatrix([[row["cells"][4]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][1], row["cells"][2]]],
                                  0)

        assertNVPEqual(row["cells"][1]["value"], "b", None, 5)
        assertNVPEqual(row["cells"][2]["value"], "c", False, 5)

        row["cells"][2]["value"]["value"].setValue(3)

        data = _ClipboardAlgo.valueMatrix([[row["cells"][2]]])
        _ClipboardAlgo.pasteCells(data, [[row["cells"][4]]], 0)

        self.assertEqual(row["cells"][4]["value"].getValue(), 3)
Exemplo n.º 7
0
    def testPasteCells(self):

        # Single column

        s = self.__createSpreadsheet()

        sourceCells = [[s["rows"][r]["cells"][1]] for r in range(1, 5)]
        sourceHashes = self.__cellPlugHashes(sourceCells)

        data = _ClipboardAlgo.valueMatrix(sourceCells)

        #   - matching dest

        destCells = [[s["rows"][r]["cells"][2]] for r in range(1, 5)]
        self.assertNotEqual(self.__cellPlugHashes(destCells), sourceHashes)

        _ClipboardAlgo.pasteCells(data, destCells, 0)
        self.assertEqual(self.__cellPlugHashes(destCells), sourceHashes)

        #  - column wrap

        s = self.__createSpreadsheet()

        destCells = [[s["rows"][r]["cells"][c] for c in (2, 4)]
                     for r in range(1, 5)]
        expected = [[r[0], r[0]] for r in sourceHashes]
        self.assertNotEqual(self.__cellPlugHashes(destCells), expected)

        _ClipboardAlgo.pasteCells(data, destCells, 0)
        self.assertEqual(self.__cellPlugHashes(destCells), expected)

        # - row wrap

        s = self.__createSpreadsheet()

        destCells = [[s["rows"][r]["cells"][2]] for r in range(1, 9)]
        expected = sourceHashes[:] + sourceHashes[:4]
        self.assertNotEqual(self.__cellPlugHashes(destCells), expected)

        _ClipboardAlgo.pasteCells(data, destCells, 0)
        self.assertEqual(self.__cellPlugHashes(destCells), expected)

        # - interleaved paste across 2 matching column types

        s = self.__createSpreadsheet()

        destCells = [[s["rows"][r]["cells"][(r % 2) + 1]] for r in range(1, 5)]
        self.assertNotEqual(self.__cellPlugHashes(destCells), sourceHashes)

        _ClipboardAlgo.pasteCells(data, destCells, 0)
        self.assertEqual(self.__cellPlugHashes(destCells), sourceHashes)

        # Multi-column + row wrap

        s = self.__createSpreadsheet()

        sourceCells = [[
            s["rows"][r]["cells"][c] for c in range(len(s["rows"][0]["cells"]))
        ] for r in range(1, 3)]
        sourceHashes = self.__cellPlugHashes(sourceCells)

        data = _ClipboardAlgo.valueMatrix(sourceCells)

        destCells = [[
            s["rows"][r]["cells"][c] for c in range(len(s["rows"][0]["cells"]))
        ] for r in range(5, 9)]
        self.assertNotEqual(self.__cellPlugHashes(destCells), sourceHashes)

        _ClipboardAlgo.pasteCells(data, destCells, 0)

        expected = sourceHashes[:] + sourceHashes[:]
        self.assertEqual(self.__cellPlugHashes(destCells), expected)