def __init__( self, parameterHandler ) : PresetDialogue.__init__( self, "Save Preset", parameterHandler ) with GafferUI.ListContainer( spacing = 8 ) as column : with GafferUI.GridContainer( spacing = 6 ) : GafferUI.Label( "<h3>Location</h3>", parenting = { "index" : ( 0, 0 ), "alignment" : ( GafferUI.Label.HorizontalAlignment.Right, GafferUI.Label.VerticalAlignment.None, ), } ) self._locationMenu( writable=True, parenting = { "index" : ( slice( 1, 3 ), 0 ) } ) GafferUI.Label( "<h3>Name</h3>", parenting = { "index" : ( 0, 1 ), "alignment" : ( GafferUI.Label.HorizontalAlignment.Right, GafferUI.Label.VerticalAlignment.None, ), } ) self.__presetNameWidget = GafferUI.TextWidget( self.__defaultName, parenting = { "index" : ( 1, 1 ) } ) self.__presetNameWidget.setSelection( None, None ) # select all self.__presetNameChangedConnection = self.__presetNameWidget.textChangedSignal().connect( Gaffer.WeakMethod( self.__presetNameChanged ) ) self.__loadAutomaticallyWidget = GafferUI.BoolWidget( "Load automatically", parenting = { "index" : ( 2, 1 ) } ) self.__loadAutomaticallyChangedConnection = self.__loadAutomaticallyWidget.stateChangedSignal().connect( Gaffer.WeakMethod( self.__loadAutomaticallyChanged ) ) GafferUI.Label( "<h3>Description</h3>", parenting = { "index" : ( 0, 2 ), "alignment" : ( GafferUI.Label.HorizontalAlignment.Right, GafferUI.Label.VerticalAlignment.Top, ), } ) self.__presetDescriptionWidget = GafferUI.MultiLineTextWidget( parenting = { "index" : ( slice( 1, 3 ), 2 ) } ) self.__presetDescriptionChangedConnection = self.__presetDescriptionWidget.textChangedSignal().connect( Gaffer.WeakMethod( self.__updateSaveButton ) ) with GafferUI.Collapsible( "Parameters To Save", collapsed=True ) as cl : # forcing CompoundVectorParameter to act as a leaf, because allowing the selection of some children but not others # makes no sense (because they must all have the same length). parameterPath = GafferCortex.ParameterPath( parameterHandler.parameter(), "/", forcedLeafTypes = ( IECore.CompoundVectorParameter, ) ) self.__parameterListing = GafferUI.PathListingWidget( parameterPath, columns = [ GafferUI.PathListingWidget.defaultNameColumn ], allowMultipleSelection = True, displayMode = GafferUI.PathListingWidget.DisplayMode.Tree ) self.__parameterListing.setSelectedPaths( self.__allPaths( parameterPath ) ) self.__haveSelectedParameters = True self.__selectionChangedConnection = self.__parameterListing.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__selectionChanged ) ) self._setWidget( column ) self._addButton( "Cancel" ) self.__saveButton = self._addButton( "Save" ) self.__saveButton.setEnabled( False )
def testClassParameter(self): ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised("classParameter", 1, "GAFFERCORTEXTEST_CLASS_PATHS") p = ph.getParameterised()[0] with ph.parameterModificationContext(): p["class"].setClass(*self.classSpecification( "files/sequenceLs", "IECORE_OP_PATHS")) seqLsParameterNames = p["class"].keys() for n in seqLsParameterNames: self.failUnless(n in ph["parameters"]["class"]) with ph.parameterModificationContext(): p["class"].setClass("", 0) for n in seqLsParameterNames: self.failIf(n in ph["parameters"]["class"])
def testDateTimeParameter(self): p = IECore.Parameterised("") now = datetime.datetime.now() p.parameters().addParameters([IECore.DateTimeParameter("dt", "", now)]) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.failUnless(isinstance(ph["parameters"]["dt"], Gaffer.StringPlug)) ph.parameterHandler().setParameterValue() self.assertEqual(p["dt"].getValue(), IECore.DateTimeData(now)) tomorrow = now + datetime.timedelta(days=1) p["dt"].setValue(IECore.DateTimeData(tomorrow)) ph.parameterHandler().setPlugValue() ph.parameterHandler().setParameterValue() self.assertEqual(p["dt"].getValue(), IECore.DateTimeData(tomorrow))
def testParameterChangingType(self): p = IECore.Parameterised("") p.parameters().addParameter(IECore.IntParameter("a", "", 1)) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.failUnless(isinstance(ph["parameters"], Gaffer.CompoundPlug)) self.failUnless(isinstance(ph["parameters"]["a"], Gaffer.IntPlug)) self.assertEqual(len(ph["parameters"]), 1) with ph.parameterModificationContext(): p.parameters().removeParameter(p.parameters()["a"]) p.parameters().addParameter(IECore.FloatParameter("a", "", 2)) self.failUnless(isinstance(ph["parameters"], Gaffer.CompoundPlug)) self.failUnless(isinstance(ph["parameters"]["a"], Gaffer.FloatPlug)) self.assertEqual(len(ph["parameters"]), 1)
def testProperties(self): p = GafferCortex.ClassLoaderPath(IECore.ClassLoader.defaultOpLoader(), "/files") self.assertEqual(p.propertyNames(), ["name", "fullName", "classLoader:versions"]) self.assertEqual(p.property("name"), "files") self.assertEqual(p.property("fullName"), "/files") self.assertEqual(p.property("classLoader:versions"), None) p.append("sequenceRenumber") self.assertEqual(p.propertyNames(), ["name", "fullName", "classLoader:versions"]) self.assertEqual(p.property("name"), "sequenceRenumber") self.assertEqual(p.property("fullName"), "/files/sequenceRenumber") self.assertTrue( isinstance(p.property("classLoader:versions"), IECore.IntVectorData))
def testSimplePlugTypes(self): n = GafferCortex.ParameterisedHolderNode() op = IECore.SequenceRenumberOp() n.setParameterised(op) self.failUnless(isinstance(n["parameters"]["src"], Gaffer.StringPlug)) self.failUnless(isinstance(n["parameters"]["dst"], Gaffer.StringPlug)) self.failUnless(isinstance(n["parameters"]["multiply"], Gaffer.IntPlug)) self.failUnless(isinstance(n["parameters"]["offset"], Gaffer.IntPlug)) self.assertEqual(n["parameters"]["src"].defaultValue(), "") self.assertEqual(n["parameters"]["dst"].defaultValue(), "") self.assertEqual(n["parameters"]["multiply"].defaultValue(), 1) self.assertEqual(n["parameters"]["offset"].defaultValue(), 0) self.assertEqual(n["parameters"]["src"].getValue(), "") self.assertEqual(n["parameters"]["dst"].getValue(), "") self.assertEqual(n["parameters"]["multiply"].getValue(), 1) self.assertEqual(n["parameters"]["offset"].getValue(), 0) for k in op.parameters().keys(): self.assertEqual(n["parameters"][k].defaultValue(), op.parameters()[k].defaultValue.value) with n.parameterModificationContext() as parameters: parameters["multiply"].setNumericValue(10) parameters["dst"].setTypedValue("/tmp/s.####.exr") self.assertEqual(n["parameters"]["multiply"].getValue(), 10) self.assertEqual(n["parameters"]["dst"].getValue(), "/tmp/s.####.exr") n["parameters"]["multiply"].setValue(20) n["parameters"]["dst"].setValue("lalalal.##.tif") n.setParameterisedValues() self.assertEqual(op["multiply"].getNumericValue(), 20) self.assertEqual(op["dst"].getTypedValue(), "lalalal.##.tif")
def testHash(self): c = Gaffer.Context() c.setFrame(1) c2 = Gaffer.Context() c2.setFrame(2) s = Gaffer.ScriptNode() s["n"] = GafferCortex.ObjectWriter() # no file produces no effect with c: self.assertEqual(s["n"]["task"].hash(), IECore.MurmurHash()) # no input object produces no effect with c: s["n"]["fileName"].setValue(self.__exrFileName) self.assertEqual(s["n"]["task"].hash(), IECore.MurmurHash()) # now theres a file and object, we get some output with c: s["sphere"] = GafferTest.SphereNode() s["n"]["in"].setInput(s["sphere"]["out"]) self.assertNotEqual(s["n"]["task"].hash(), IECore.MurmurHash()) # output doesn't vary by time with c: h1 = s["n"]["task"].hash() with c2: h2 = s["n"]["task"].hash() self.assertEqual(h1, h2) # output varies by time since the file name does s["n"]["fileName"].setValue(self.__exrSequence.fileName) with c: h1 = s["n"]["task"].hash() with c2: h2 = s["n"]["task"].hash() self.assertNotEqual(h1, h2)
def testCompoundParameterHandler( self ) : c = IECore.CompoundParameter( "c", "", [ IECore.IntParameter( "i", "" ), IECore.FloatParameter( "f", "" ) ] ) n = Gaffer.Node() h = GafferCortex.CompoundParameterHandler( c ) h.setupPlug( n ) self.failUnless( h.childParameterHandler( c["i"] ).parameter().isSame( c["i"] ) ) self.failUnless( h.childParameterHandler( c["f"] ).parameter().isSame( c["f"] ) )
def testSerialisation( self ) : ph = GafferCortex.ParameterisedHolderNode() classSpec = self.classSpecification( "files/sequenceRenumber", "IECORE_OP_PATHS" ) ph.setParameterised( *classSpec ) s = Gaffer.ScriptNode() s["n"] = ph s["n"]["parameters"]["offset"].setValue( 21 ) ss = s.serialise() s = Gaffer.ScriptNode() s.execute( ss ) self.failUnless( "n" in s ) parameterised = s["n"].getParameterised() self.assertEqual( parameterised[1:], classSpec ) self.assertEqual( parameterised[0].typeName(), "SequenceRenumberOp" ) self.assertEqual( s["n"]["parameters"]["offset"].getValue(), 21 )
def testAddAndRemoveParameters(self): p = IECore.Parameterised("") p.parameters().addParameter(IECore.IntParameter("a", "", 1)) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.assertEqual(ph["parameters"].typeId(), Gaffer.Plug.staticTypeId()) self.assertIsInstance(ph["parameters"]["a"], Gaffer.IntPlug) self.assertEqual(len(ph["parameters"]), 1) with ph.parameterModificationContext(): p.parameters().removeParameter(p.parameters()["a"]) p.parameters().addParameter(IECore.IntParameter("b", "", 2)) self.assertEqual(ph["parameters"].typeId(), Gaffer.Plug.staticTypeId()) self.assertIsInstance(ph["parameters"]["b"], Gaffer.IntPlug) self.assertEqual(len(ph["parameters"]), 1)
def testHash(self): c = IECore.CompoundParameter( "c", "", [IECore.IntParameter("i", ""), IECore.FloatParameter("f", "")]) n = Gaffer.Node() h = GafferCortex.CompoundParameterHandler(c) h.setupPlug(n) hash1 = h.hash() n["c"]["i"].setValue(10) hash2 = h.hash() n["c"]["f"].setValue(10) hash3 = h.hash() self.assertNotEqual(hash1, hash2) self.assertNotEqual(hash1, hash3) self.assertNotEqual(hash2, hash3)
def __init__(self, name="_ObjectPreview"): Gaffer.Node.__init__(self, name) import GafferCortex self["fileName"] = Gaffer.StringPlug( defaultValue="", substitutions=Gaffer.Context.Substitutions.NoSubstitutions) self["frameRate"] = Gaffer.FloatPlug(defaultValue=24.0) self["samplesPerFrame"] = Gaffer.IntPlug(defaultValue=1, minValue=1) # single object scenes using Reader ops behind the scenes? self["ObjectReader"] = GafferCortex.ObjectReader() self["ObjectReaderExpression"] = Gaffer.Expression("Expression") self["ObjectReaderExpression"].setExpression(''' import IECore fileName = parent['fileName'] try : sequence = IECore.FileSequence( fileName ) calc = IECore.OversamplesCalculator( frameRate = parent["frameRate"], samplesPerFrame = parent["samplesPerFrame"] ) if isinstance( sequence.frameList, IECore.FrameRange ) and sequence.frameList.step == 1 : calc.setTicksPerSecond( 24 ) result = sequence.fileNameForFrame( calc.framesToTicks( context['frame'] ) ) except : result = fileName parent['ObjectReader']['fileName'] = result ''') self["ObjectToScene"] = GafferScene.ObjectToScene("ObjectToScene") self["ObjectToScene"]["object"].setInput(self["ObjectReader"]["out"]) self["out"] = GafferScene.ScenePlug( direction=Gaffer.Plug.Direction.Out) self["out"].setInput(self["ObjectToScene"]["out"])
def testCompute( self ) : m = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) ) self.failUnless( "P" in m ) self.failUnless( "renamed" not in m ) n = GafferCortex.OpHolder() opSpec = GafferCortexTest.ParameterisedHolderTest.classSpecification( "primitive/renameVariables", "IECORE_OP_PATHS" )[:-1] n.setOp( *opSpec ) n["parameters"]["input"].setValue( m ) n["parameters"]["names"].setValue( IECore.StringVectorData( [ "P renamed" ] ) ) m2 = n["result"].getValue() self.failUnless( "P" not in m2 ) self.failUnless( "renamed" in m2 ) n["parameters"]["names"].setValue( IECore.StringVectorData( [ "P renamedAgain" ] ) ) self.failUnless( "P" not in m2 ) self.failUnless( "renamed" in m2 )
def testNoHostMapping(self): p = IECore.Parameterised("") p.parameters().addParameters([ IECore.IntParameter( "i1", "", 1, userData={"noHostMapping": IECore.BoolData(False)}), IECore.IntParameter( "i2", "", 2, userData={"noHostMapping": IECore.BoolData(True)}), IECore.IntParameter("i3", "", 2), ]) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.failUnless("i1" in ph["parameters"]) self.failIf("i2" in ph["parameters"]) self.failUnless("i3" in ph["parameters"])
def testParameterInvalidWhenParameterChangedRaises(self): class InvalidValueRaiser(IECore.Parameterised): def __init__(self): IECore.Parameterised.__init__(self, "") self.parameters().addParameters([ IECore.IntParameter( name="driver", description="", defaultValue=0, ), ], ) self.changes = [] def parameterChanged(self, parameter): # this puts the parameter in a state where its value # is not valid. parameter.setValue(IECore.StringData("oh dear")) # then when we raise here, a further exception will # occur when the invalid parameter value is discovered # during the application of parameter changes to the plugs. raise RuntimeError("Ooops!") c = InvalidValueRaiser() ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(c) with IECore.CapturingMessageHandler() as mh: # We want the original exception to be the visible one. self.assertRaisesRegexp(RuntimeError, "Ooops!", ph["parameters"]["driver"].setValue, 1) # And we want the secondary exception to be reported as a message. self.assertEqual(len(mh.messages), 1) self.assertTrue("Value is not an instance of \"IntData\"" in mh.messages[0].message)
def __init__(self, name="ObjectWriter"): Gaffer.ExecutableNode.__init__(self, name) inPlug = Gaffer.ObjectPlug("in", Gaffer.Plug.Direction.In, IECore.NullObject.defaultNullObject()) self.addChild(inPlug) fileNamePlug = Gaffer.StringPlug("fileName", Gaffer.Plug.Direction.In) self.addChild(fileNamePlug) self.addChild(Gaffer.CompoundPlug("parameters")) self.__writer = None self.__writerExtension = "" self.__exposedParameters = IECore.CompoundParameter() self.__parameterHandler = GafferCortex.CompoundParameterHandler( self.__exposedParameters) self.__parameterHandler.setupPlug(self) self.__plugSetConnection = self.plugSetSignal().connect( Gaffer.WeakMethod(self.__plugSet))
def testCompoundNumericTypes(self): p = IECore.Parameterised("") p.parameters().addParameters([ IECore.V2iParameter("v2i", "", IECore.V2i(1, 2)), IECore.V3fParameter("v3f", "", IECore.V3f(1, 2, 3)), IECore.Color4fParameter("color4f", "", IECore.Color4f(0.25, 0.5, 0.75, 1)), ]) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.assertEqual(ph["parameters"]["v2i"].defaultValue(), IECore.V2i(1, 2)) self.assertEqual(ph["parameters"]["v3f"].defaultValue(), IECore.V3f(1, 2, 3)) self.assertEqual(ph["parameters"]["color4f"].defaultValue(), IECore.Color4f(0.25, 0.5, 0.75, 1)) self.assertEqual(ph["parameters"]["v2i"].getValue(), IECore.V2i(1, 2)) self.assertEqual(ph["parameters"]["v3f"].getValue(), IECore.V3f(1, 2, 3)) self.assertEqual(ph["parameters"]["color4f"].getValue(), IECore.Color4f(0.25, 0.5, 0.75, 1)) ph["parameters"]["v2i"].setValue(IECore.V2i(2, 3)) ph["parameters"]["v3f"].setValue(IECore.V3f(4, 5, 6)) ph["parameters"]["color4f"].setValue(IECore.Color4f( 0.1, 0.2, 0.3, 0.5)) ph.setParameterisedValues() self.assertEqual(p["v2i"].getTypedValue(), IECore.V2i(2, 3)) self.assertEqual(p["v3f"].getTypedValue(), IECore.V3f(4, 5, 6)) self.assertEqual(p["color4f"].getTypedValue(), IECore.Color4f(0.1, 0.2, 0.3, 0.5))
def testClassVectorParameterMaintainsPlugValues( self ) : ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised( "classVectorParameter", 1, "GAFFERCORTEXTEST_CLASS_PATHS" ) p = ph.getParameterised()[0] seqLsClassSpec = self.classSpecification( "files/sequenceLs", "IECORE_OP_PATHS" )[:2] gradeClassSpec = self.classSpecification( "files/sequenceRenumber", "IECORE_OP_PATHS" )[:2] classes = [ ( "p0", ) + gradeClassSpec, ] with ph.parameterModificationContext() : p["classes"].setClasses( classes ) ph["parameters"]["classes"]["p0"]["multiply"].setValue( 15 ) ph.setParameterisedValues() classes.append( ( "p1", ) + seqLsClassSpec ) with ph.parameterModificationContext() : p["classes"].setClasses( classes ) self.assertEqual( ph["parameters"]["classes"]["p0"]["multiply"].getValue(), 15 )
def testClassVectorParameterSerialisation( self ) : s = Gaffer.ScriptNode() s["ph"] = GafferCortex.ParameterisedHolderNode() s["ph"].setParameterised( "classVectorParameter", 1, "GAFFERCORTEXTEST_CLASS_PATHS" ) p = s["ph"].getParameterised()[0] gradeClassSpec = self.classSpecification( "files/sequenceRenumber", "IECORE_OP_PATHS" )[:2] classes = [ ( "p0", ) + gradeClassSpec, ] with s["ph"].parameterModificationContext() : p["classes"].setClasses( classes ) s["ph"]["parameters"]["classes"]["p0"]["multiply"].setValue( 12 ) ss = s.serialise() s2 = Gaffer.ScriptNode() s2.execute( ss ) self.assertEqual( s2["ph"]["parameters"]["classes"]["p0"]["multiply"].getValue(), 12 )
def testCompute( self ) : class MultiplyOp( IECore.Op ) : def __init__( self ) : IECore.Op.__init__( self, "", IECore.IntParameter( "result", "", 0 ) ) self.parameters().addParameters( [ IECore.IntParameter( "a", "", 0 ), IECore.IntParameter( "b", "", 0 ) ] ) def doOperation( self, args ) : return IECore.IntData( args["a"].value * args["b"].value ) n = GafferCortex.OpHolder() n.setParameterised( MultiplyOp() ) n["parameters"]["a"].setValue( 2 ) n["parameters"]["b"].setValue( 20 ) self.assertEqual( n["result"].getValue(), 40 ) n["parameters"]["b"].setValue( 3 ) self.assertEqual( n["result"].getValue(), 6 )
def testParameterChangedWithCompoundParameters(self): class ParameterChanger(IECore.Parameterised): def __init__(self): IECore.Parameterised.__init__(self, "") self.parameters().addParameters([ IECore.IntParameter( name="driver", description="", ), IECore.CompoundParameter(name="c", members=[ IECore.IntParameter("i", ""), IECore.StringParameter( "s", "", ""), ]), ], ) self.changes = [] # the mere existence of this function caused the problem this # test is checking is fixed. def parameterChanged(self, parameter): pass c = ParameterChanger() ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(c) self.failUnless("parameters" in ph) self.failUnless("c" in ph["parameters"]) self.failUnless("i" in ph["parameters"]["c"]) self.failUnless("s" in ph["parameters"]["c"])
def testParameterChangedWithIntermediateClasses(self): class ClassParameterChanger(IECore.Parameterised): def __init__(self): IECore.Parameterised.__init__(self, "") self.parameters().addParameters([ IECore.IntParameter( name="driver", description="", ), IECore.IntParameter( name="driven", description="", ), IECore.CompoundParameter( name="c", description="", members=[ IECore.IntParameter( name="driver2", description="", ), IECore.IntParameter( name="driven2", description="", ), IECore.ClassParameter( name="class", description="", searchPathEnvVar="GAFFERCORTEXTEST_CLASS_PATHS", ), IECore.ClassVectorParameter( name="classes", description="", searchPathEnvVar="GAFFERCORTEXTEST_CLASS_PATHS", ), ], ), ], ) self.changes = [] def parameterChanged(self, parameter): self.changes.append((parameter, str(parameter.getValue()))) if parameter.isSame(self.parameters()["driver"]): self.parameters()["driven"].setNumericValue( parameter.getNumericValue() * 2) elif parameter.isSame(self.parameters()["c"]["driver2"]): self.parameters()["c"]["driven2"].setNumericValue( parameter.getNumericValue() * 4) c = ClassParameterChanger() ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(c) with ph.parameterModificationContext(): c["c"]["class"].setClass("parameterChangedCallback", 1) c["c"]["classes"].setClasses([ ("p0", "parameterChangedCallback", 1), ("p1", "parameterChangedCallback", 1), ]) # check that the main class gets callbacks for the parameters it # owns directly. self.assertEqual(ph["parameters"]["driver"].getValue(), 0) self.assertEqual(ph["parameters"]["driven"].getValue(), 0) self.assertEqual(len(c.changes), 0) ph["parameters"]["driver"].setValue(10) self.assertEqual(ph["parameters"]["driver"].getValue(), 10) self.assertEqual(ph["parameters"]["driven"].getValue(), 20) self.assertEqual(len(c.changes), 1) self.failUnless(c.changes[0][0].isSame(c["driver"])) self.assertEqual(c.changes[0][1], "10") ph["parameters"]["driven"].setValue(30) self.assertEqual(ph["parameters"]["driver"].getValue(), 10) self.assertEqual(ph["parameters"]["driven"].getValue(), 30) self.assertEqual(len(c.changes), 2) self.failUnless(c.changes[1][0].isSame(c["driven"])) self.assertEqual(c.changes[1][1], "30") # check that the main class gets callbacks for the parameters it # owns directly via a CompoundParameter. self.assertEqual(ph["parameters"]["c"]["driver2"].getValue(), 0) self.assertEqual(ph["parameters"]["c"]["driven2"].getValue(), 0) self.assertEqual(len(c.changes), 2) ph["parameters"]["c"]["driver2"].setValue(10) self.assertEqual(ph["parameters"]["c"]["driver2"].getValue(), 10) self.assertEqual(ph["parameters"]["c"]["driven2"].getValue(), 40) self.assertEqual(len(c.changes), 4) self.failUnless(c.changes[2][0].isSame(c["c"]["driver2"])) self.assertEqual(c.changes[2][1], "10") self.failUnless(c.changes[3][0].isSame(c["c"])) ph["parameters"]["c"]["driven2"].setValue(30) self.assertEqual(ph["parameters"]["c"]["driver2"].getValue(), 10) self.assertEqual(ph["parameters"]["c"]["driven2"].getValue(), 30) self.assertEqual(len(c.changes), 6) self.failUnless(c.changes[4][0].isSame(c["c"]["driven2"])) self.assertEqual(c.changes[4][1], "30") self.failUnless(c.changes[5][0].isSame(c["c"])) # check that parameters changed on the classparameter are passed to # the class itself and not the top level parameterised. c2 = c["c"]["class"].getClass() self.assertEqual(len(c2.changes), 0) ph["parameters"]["c"]["class"]["driver"].setValue(10) self.assertEqual(ph["parameters"]["c"]["class"]["driver"].getValue(), 10) self.assertEqual(ph["parameters"]["c"]["class"]["driven"].getValue(), 50) self.assertEqual(len(c2.changes), 1) self.failUnless(c2.changes[0][0].isSame(c2["driver"])) self.assertEqual(c2.changes[0][1], "10") # check that parameters changed on the classvectorparameter are passed to # the class itself and not the top level parameterised. c3 = c["c"]["classes"].getClass("p0") self.assertEqual(len(c3.changes), 0) ph["parameters"]["c"]["classes"]["p0"]["driver"].setValue(10) self.assertEqual( ph["parameters"]["c"]["classes"]["p0"]["driver"].getValue(), 10) self.assertEqual( ph["parameters"]["c"]["classes"]["p0"]["driven"].getValue(), 50) self.assertEqual(len(c3.changes), 2) self.failUnless(c3.changes[0][0].isSame(c3["driver"])) self.assertEqual(c3.changes[0][1], "10") self.failUnless(c3.changes[1][0].isSame(c["c"]["classes"]["p0"])) c4 = c["c"]["classes"].getClass("p1") self.assertEqual(len(c4.changes), 0) ph["parameters"]["c"]["classes"]["p1"]["driver"].setValue(10) self.assertEqual( ph["parameters"]["c"]["classes"]["p1"]["driver"].getValue(), 10) self.assertEqual( ph["parameters"]["c"]["classes"]["p1"]["driven"].getValue(), 50) self.assertEqual(len(c4.changes), 2) self.failUnless(c4.changes[0][0].isSame(c4["driver"])) self.assertEqual(c4.changes[0][1], "10") self.failUnless(c4.changes[1][0].isSame(c["c"]["classes"]["p1"]))
def testTimeCodeParameter(self): p = IECore.Parameterised("") p.parameters().addParameters([ IECore.TimeCodeParameter( "t", "", IECore.TimeCode( hours=10, minutes=15, seconds=1, frame=12, )) ]) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.failUnless("t" in ph["parameters"]) self.failUnless(isinstance(ph["parameters"]["t"], Gaffer.CompoundPlug)) self.failUnless( isinstance(ph["parameters"]["t"]["hours"], Gaffer.IntPlug)) self.assertEqual(ph["parameters"]["t"]["hours"].minValue(), 0) self.assertEqual(ph["parameters"]["t"]["hours"].maxValue(), 23) self.assertEqual(ph["parameters"]["t"]["hours"].defaultValue(), 10) self.assertEqual(ph["parameters"]["t"]["hours"].getValue(), 10) self.failUnless( isinstance(ph["parameters"]["t"]["minutes"], Gaffer.IntPlug)) self.assertEqual(ph["parameters"]["t"]["minutes"].minValue(), 0) self.assertEqual(ph["parameters"]["t"]["minutes"].maxValue(), 59) self.assertEqual(ph["parameters"]["t"]["minutes"].defaultValue(), 15) self.assertEqual(ph["parameters"]["t"]["minutes"].getValue(), 15) self.failUnless( isinstance(ph["parameters"]["t"]["seconds"], Gaffer.IntPlug)) self.assertEqual(ph["parameters"]["t"]["seconds"].minValue(), 0) self.assertEqual(ph["parameters"]["t"]["seconds"].maxValue(), 59) self.assertEqual(ph["parameters"]["t"]["seconds"].defaultValue(), 1) self.assertEqual(ph["parameters"]["t"]["seconds"].getValue(), 1) self.failUnless( isinstance(ph["parameters"]["t"]["frame"], Gaffer.IntPlug)) self.assertEqual(ph["parameters"]["t"]["frame"].minValue(), 0) self.assertEqual(ph["parameters"]["t"]["frame"].maxValue(), 29) self.assertEqual(ph["parameters"]["t"]["frame"].defaultValue(), 12) self.assertEqual(ph["parameters"]["t"]["frame"].getValue(), 12) ph["parameters"]["t"]["hours"].setValue(11) ph["parameters"]["t"]["minutes"].setValue(10) ph["parameters"]["t"]["seconds"].setValue(2) ph["parameters"]["t"]["frame"].setValue(20) ph.parameterHandler().setParameterValue() tc = p["t"].getTypedValue() self.assertEqual(tc.hours(), 11) self.assertEqual(tc.minutes(), 10) self.assertEqual(tc.seconds(), 2) self.assertEqual(tc.frame(), 20) with ph.parameterModificationContext(): tc.setHours(1) tc.setMinutes(2) tc.setSeconds(3) tc.setFrame(4) p["t"].setTypedValue(tc) self.assertEqual(ph["parameters"]["t"]["hours"].getValue(), 1) self.assertEqual(ph["parameters"]["t"]["minutes"].getValue(), 2) self.assertEqual(ph["parameters"]["t"]["seconds"].getValue(), 3) self.assertEqual(ph["parameters"]["t"]["frame"].getValue(), 4)
def testCreateEmpty(self): n = GafferCortex.ParameterisedHolderNode() self.assertEqual(n.getName(), "ParameterisedHolderNode") self.assertEqual(n.getParameterised(), (None, "", -1, ""))
def __init__( self, opInstanceOrOpHolderInstance, title=None, sizeMode=GafferUI.Window.SizeMode.Manual, postExecuteBehaviour = PostExecuteBehaviour.FromUserData, executeInBackground = False, defaultButton = DefaultButton.FromUserData, executeImmediately = False, **kw ) : # sort out our op and op holder if isinstance( opInstanceOrOpHolderInstance, IECore.Op ) : opInstance = opInstanceOrOpHolderInstance self.__node = GafferCortex.ParameterisedHolderNode() self.__node.setParameterised( opInstance ) # set the current plug values as userDefaults to provide # a clean NodeUI based on the initial settings of the Op. # we assume that if an OpHolder was passed directly then # the metadata has already been setup as preferred. self.__setUserDefaults( self.__node ) else : self.__node = opInstanceOrOpHolderInstance opInstance = self.__node.getParameterised()[0] # initialise the dialogue if title is None : title = IECore.CamelCase.toSpaced( opInstance.typeName() ) GafferUI.Dialogue.__init__( self, title, sizeMode=sizeMode, **kw ) # decide what we'll do after execution. if postExecuteBehaviour == self.PostExecuteBehaviour.FromUserData : postExecuteBehaviour = self.PostExecuteBehaviour.DisplayResult d = None with IECore.IgnoredExceptions( KeyError ) : d = opInstance.userData()["UI"]["postExecuteBehaviour"] if d is not None : for v in self.PostExecuteBehaviour.values() : if str( v ).lower() == d.value.lower() : postExecuteBehaviour = v break else : # backwards compatibility with batata with IECore.IgnoredExceptions( KeyError ) : d = opInstance.userData()["UI"]["closeAfterExecution"] if d is not None : postExecuteBehaviour = self.PostExecuteBehaviour.Close if d.value else self.PostExecuteBehaviour.DisplayResult self.__postExecuteBehaviour = postExecuteBehaviour self.__executeInBackground = executeInBackground self.__defaultButton = defaultButton # make a frame to contain our main ui element. this will # contain different elements depending on our state. self.__frame = GafferUI.Frame() self._setWidget( self.__frame ) # get the ui for the op - we'll use this when we want # the user to edit parameters. self.__parameterEditingUI = GafferUI.NodeUI.create( self.__node ) # build a ui element for progress feedback and suchlike. # we'll use this when executing and displaying the result. with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Vertical, spacing = 4 ) as self.__progressUI : GafferUI.Spacer( imath.V2i( 1 ), preferredSize = imath.V2i( 1, 1 ) ) self.__progressIconFrame = GafferUI.Frame( borderStyle = GafferUI.Frame.BorderStyle.None_, parenting = { "horizontalAlignment" : GafferUI.HorizontalAlignment.Center } ) self.__progressLabel = GafferUI.Label( parenting = { "expand" : True, "horizontalAlignment" : GafferUI.HorizontalAlignment.Center, } ) GafferUI.Spacer( imath.V2i( 250, 1 ), preferredSize = imath.V2i( 250, 1 ) ) with GafferUI.Collapsible( "Details", collapsed = True ) as self.__messageCollapsible : self.__messageWidget = GafferUI.MessageWidget( toolbars = True ) # connect to the collapsible state change so we can increase the window # size when the details pane is first shown. self.__messageCollapsibleStateChangedConnection = self.__messageCollapsible.stateChangedSignal().connect( Gaffer.WeakMethod( self.__messageCollapsibleStateChanged ) ) # add buttons. our buttons mean different things depending on our current state, # but they equate roughly to going forwards or going backwards. self.__backButton = self._addButton( "Back" ) self.__forwardButton = self._addButton( "Forward" ) self.__preExecuteSignal = GafferUI.WidgetSignal() self.__postExecuteSignal = Gaffer.Signal2() self.__opExecutedSignal = Gaffer.Signal1() self.__haveResizedToFitParameters = False if executeImmediately : self.__initiateExecution() else : self.__initiateParameterEditing()
def testLoad( self ) : p = GafferCortex.ClassLoaderPath( IECore.ClassLoader.defaultOpLoader(), "/files/sequenceRenumber" ) op = p.load()() self.assertIsInstance( op, IECore.Op )
def testCustomHandler(self): class CustomParameter(IECore.IntParameter): def __init__(self, name, description, defaultValue): IECore.IntParameter.__init__(self, name, description, defaultValue) IECore.registerRunTimeTyped(CustomParameter) class CustomHandler(GafferCortex.ParameterHandler): def __init__(self, parameter): GafferCortex.ParameterHandler.__init__(self) self.__parameter = parameter self.__plug = None def parameter(self): return self.__parameter def setupPlug(self, plugParent, direction, flags): self.__plug = plugParent.getChild(self.__parameter.name) if not isinstance(self.__plug, Gaffer.IntPlug ) or self.__plug.direction() != direction: self.__plug = Gaffer.IntPlug( self.__parameter.name, Gaffer.Plug.Direction.In, self.__parameter.numericDefaultValue, self.__parameter.minValue, self.__parameter.maxValue) ## \todo: should ParameterHandler::setupPlugFlags be exposed so we can call it here? self.__plug.setFlags(flags) plugParent[self.__parameter.name] = self.__plug def plug(self): return self.__plug def setParameterValue(self): self.__parameter.setValue(self.__plug.getValue() * 10) def setPlugValue(self): self.__plug.setValue(self.__parameter.getNumericValue() / 10) GafferCortex.ParameterHandler.registerParameterHandler( CustomParameter, CustomHandler) p = IECore.Parameterised("") p.parameters().addParameter(CustomParameter("i", "d", 10)) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.assertEqual(ph["parameters"]["i"].getValue(), 1) with ph.parameterModificationContext() as parameters: p["i"].setNumericValue(100) self.assertEqual(ph["parameters"]["i"].getValue(), 10) ph["parameters"]["i"].setValue(1000) ph.setParameterisedValues() self.assertEqual(p["i"].getNumericValue(), 10000)
def testVectorTypedParameter(self): p = IECore.Parameterised("") p.parameters().addParameters([ IECore.BoolVectorParameter("bv", "", IECore.BoolVectorData()), IECore.IntVectorParameter("iv", "", IECore.IntVectorData()), IECore.FloatVectorParameter("fv", "", IECore.FloatVectorData()), IECore.StringVectorParameter("sv", "", IECore.StringVectorData()), IECore.V3fVectorParameter("vv", "", IECore.V3fVectorData()), ]) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised(p) self.assertEqual(ph["parameters"]["bv"].defaultValue(), IECore.BoolVectorData()) self.assertEqual(ph["parameters"]["iv"].defaultValue(), IECore.IntVectorData()) self.assertEqual(ph["parameters"]["fv"].defaultValue(), IECore.FloatVectorData()) self.assertEqual(ph["parameters"]["sv"].defaultValue(), IECore.StringVectorData()) self.assertEqual(ph["parameters"]["vv"].defaultValue(), IECore.V3fVectorData()) self.assertEqual(ph["parameters"]["bv"].getValue(), IECore.BoolVectorData()) self.assertEqual(ph["parameters"]["iv"].getValue(), IECore.IntVectorData()) self.assertEqual(ph["parameters"]["fv"].getValue(), IECore.FloatVectorData()) self.assertEqual(ph["parameters"]["sv"].getValue(), IECore.StringVectorData()) self.assertEqual(ph["parameters"]["vv"].getValue(), IECore.V3fVectorData()) with ph.parameterModificationContext() as parameters: parameters["bv"].setValue(IECore.BoolVectorData([True, False])) parameters["iv"].setValue(IECore.IntVectorData([1, 2, 3])) parameters["fv"].setValue(IECore.FloatVectorData([1])) parameters["sv"].setValue(IECore.StringVectorData(["a"])) parameters["vv"].setValue( IECore.V3fVectorData([IECore.V3f(1, 2, 3)])) self.assertEqual(ph["parameters"]["bv"].getValue(), IECore.BoolVectorData([True, False])) self.assertEqual(ph["parameters"]["iv"].getValue(), IECore.IntVectorData([1, 2, 3])) self.assertEqual(ph["parameters"]["fv"].getValue(), IECore.FloatVectorData([1])) self.assertEqual(ph["parameters"]["sv"].getValue(), IECore.StringVectorData(["a"])) self.assertEqual(ph["parameters"]["vv"].getValue(), IECore.V3fVectorData([IECore.V3f(1, 2, 3)])) ph["parameters"]["bv"].setValue(IECore.BoolVectorData([True, True])) ph["parameters"]["iv"].setValue(IECore.IntVectorData([2, 3, 4])) ph["parameters"]["fv"].setValue(IECore.FloatVectorData([2])) ph["parameters"]["sv"].setValue(IECore.StringVectorData(["b"])) ph["parameters"]["vv"].setValue( IECore.V3fVectorData([IECore.V3f(10, 20, 30)])) ph.setParameterisedValues() self.assertEqual(parameters["bv"].getValue(), IECore.BoolVectorData([True, True])) self.assertEqual(parameters["iv"].getValue(), IECore.IntVectorData([2, 3, 4])) self.assertEqual(parameters["fv"].getValue(), IECore.FloatVectorData([2])) self.assertEqual(parameters["sv"].getValue(), IECore.StringVectorData(["b"])) self.assertEqual(parameters["vv"].getValue(), IECore.V3fVectorData([IECore.V3f(10, 20, 30)]))
def testReadNoFilename(self): r = GafferCortex.ObjectReader() self.assertEqual(r["out"].getValue(), r["out"].defaultValue())
def testSetOp(self): n = GafferCortex.ExecutableOpHolder() opSpec = GafferCortexTest.ParameterisedHolderTest.classSpecification( "primitive/renameVariables", "IECORE_OP_PATHS")[:-1] n.setOp(*opSpec)