def testTitle(self): s = Gaffer.ScriptNode() g = GafferUI.GraphEditor(s) self.assertEqual(g.getTitle(), "Graph Editor") b1 = Gaffer.Box() b2 = Gaffer.Box() s["a"] = b1 s["a"]["b"] = b2 self.__signalUpdatedTitle = g.getTitle() def titleChangedHandler(widget): self.__signalUpdatedTitle = widget.getTitle() g.titleChangedSignal().connect(titleChangedHandler, scoped=False) g.graphGadget().setRoot(b1) self.assertEqual(self.__signalUpdatedTitle, "Graph Editor : a") g.graphGadget().setRoot(b2) self.assertEqual(self.__signalUpdatedTitle, "Graph Editor : a / b") b1.setName("c") self.assertEqual(self.__signalUpdatedTitle, "Graph Editor : c / b") b2.setName("d") self.assertEqual(self.__signalUpdatedTitle, "Graph Editor : c / d") g.setTitle("This is a test!") self.assertEqual(self.__signalUpdatedTitle, "This is a test!")
def testSimpleAuxiliaryConnectionToNode( self ) : s = Gaffer.ScriptNode() s["n"] = LayoutNode() Gaffer.Metadata.registerValue( s["n"]["top0"], "nodule:type", "" ) s["e"] = Gaffer.Expression() s["e"].setExpression( "parent['n']['top0'] = 0" ) ge = GafferUI.GraphEditor( s ) g = ge.graphGadget() g.getLayout().layoutNodes( g ) # In this simple case the expression node needs to be put to the left # of the affected node. self.assertTrue( g.getNodePosition( s["n"] ).x > g.getNodePosition( s["e"] ).x ) self.assertAlmostEqual( g.getNodePosition( s["n"] ).y, g.getNodePosition( s["e"] ).y, delta = 0.001 ) expressionPosition = g.getNodePosition( s["e"] ) # If the expression has an input, we don't want that to affect the # expression's position if it has only one output like in this case. s["n2"] = LayoutNode() g.setNodePosition( s["n2"], g.getNodePosition( s["n"] ) + imath.V2f( 0, 10 ) ) s["e"].setExpression( "parent['n']['top0'] = parent['n2']['bottom0']" ) g.getLayout().layoutNodes( g ) self.assertAlmostEqual( g.getNodePosition( s["e"] ).x, expressionPosition.x, delta = 0.001 ) self.assertAlmostEqual( g.getNodePosition( s["e"] ).y, expressionPosition.y, delta = 0.001 )
def testMultipleAuxiliaryConnectionsToNode(self): s = Gaffer.ScriptNode() s["n"] = LayoutNode() Gaffer.Metadata.registerValue(s["n"]["left0"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["left1"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["left2"], "nodule:type", "") s["e1"] = Gaffer.Expression() s["e1"].setExpression("parent['n']['left0'] = 0") s["e2"] = Gaffer.Expression() s["e2"].setExpression("parent['n']['left1'] = 0") s["e3"] = Gaffer.Expression() s["e3"].setExpression("parent['n']['left2'] = 0") ge = GafferUI.GraphEditor(s) g = ge.graphGadget() g.getLayout().layoutNodes(g) # All expression nodes needs to be stacked above each other on the left of the affected node self.assertTrue( g.getNodePosition(s["n"]).x > g.getNodePosition(s["e1"]).x) self.assertAlmostEqual(g.getNodePosition(s["e1"]).x, g.getNodePosition(s["e2"]).x, delta=0.001) self.assertAlmostEqual(g.getNodePosition(s["e2"]).x, g.getNodePosition(s["e3"]).x, delta=0.001)
def testSimpleAuxiliaryConnectionToNodule(self): # The nodule's tangent will determine how the auxiliary node is positioned. s = Gaffer.ScriptNode() s["n"] = LayoutNode() s["e"] = Gaffer.Expression() s["e"].setExpression("parent['n']['top1'] = 0") ge = GafferUI.GraphEditor(s) g = ge.graphGadget() g.getLayout().layoutNodes(g) affectedNodeBounds = g.nodeGadget(s["n"]).transformedBound() self.assertTrue( g.getNodePosition(s["e"]).y > g.getNodePosition(s["n"]).y) self.assertTrue(affectedNodeBounds.min().x < g.getNodePosition( s["e"]).x < affectedNodeBounds.max().x) s["e"].setExpression("parent['n']['left1'] = 0") g.getLayout().layoutNodes(g) self.assertTrue( g.getNodePosition(s["n"]).x > g.getNodePosition(s["e"]).x) self.assertTrue(affectedNodeBounds.min().y < g.getNodePosition( s["e"]).y < affectedNodeBounds.max().y)
def testRestore(self): s = Gaffer.ScriptNode() c = GafferUI.CompoundEditor(s) editors = list((GafferUI.NodeEditor(s), GafferUI.AnimationEditor(s), GafferUI.GraphEditor(s), GafferUI.PythonEditor(s))) editorTypes = [type(e) for e in editors] for e in editors[:2]: c.addEditor(e) p = c._createDetachedPanel() for e in editors[2:]: p.addEditor(e) self.assertEqual(len(c._detachedPanels()), 1) self.assertEqual(c.editors(), editors) a = Gaffer.ApplicationRoot("testApp") l = GafferUI.Layouts.acquire(a) l.add("ReprTest", repr(c), persistent=False) cc = l.create("ReprTest", s) self.assertEqual(len(cc._detachedPanels()), 1) ct = [type(e) for e in cc.editors()] self.assertEqual(ct, editorTypes) self.assertEqual(repr(cc.editors()), repr(editors))
def testSimpleAuxiliaryConnectionToShader(self): # A shader is defined as a node that has data flowing left to right as # opposed to top to bottom s = Gaffer.ScriptNode() s["n"] = LayoutNode() Gaffer.Metadata.registerValue(s["n"]["left0"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["top0"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["top1"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["top2"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["bottom0"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["bottom1"], "nodule:type", "") Gaffer.Metadata.registerValue(s["n"]["bottom2"], "nodule:type", "") s["e"] = Gaffer.Expression() s["e"].setExpression("parent['n']['left0'] = 0") ge = GafferUI.GraphEditor(s) g = ge.graphGadget() g.getLayout().layoutNodes(g) # Because the left edge is blocked by nodules, but the top edge isn't, # auxiliary connections to this node should cause the expression to be # put above the "shader" self.assertTrue( g.getNodePosition(s["e"]).y > g.getNodePosition(s["n"]).y) self.assertAlmostEqual(g.getNodePosition(s["n"]).x, g.getNodePosition(s["e"]).x, delta=0.001)
def testGraphGadgetAccess(self): s = Gaffer.ScriptNode() ge = GafferUI.GraphEditor(s) g = ge.graphGadget() self.assertIsInstance(g, GafferUI.GraphGadget)
def testGraphGadgetAccess(self): s = Gaffer.ScriptNode() ge = GafferUI.GraphEditor(s) g = ge.graphGadget() self.failUnless(isinstance(g, GafferUI.GraphGadget))
def testCreateWithExistingGraph( self ) : s = Gaffer.ScriptNode() s["add1"] = GafferTest.AddNode() s["add2"] = GafferTest.AddNode() s["add1"]["op1"].setInput( s["add2"]["sum"] ) g = GafferUI.GraphEditor( s )
def testLifetime(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() e = GafferUI.GraphEditor(s) we = weakref.ref(e) del e self.assertEqual(we(), None)
def testTitle( self ) : s = Gaffer.ScriptNode() g = GafferUI.GraphEditor( s ) self.assertEqual( g.getTitle(), "Graph Editor" ) g.setTitle( "This is a test!" ) self.assertEqual( g.getTitle(), "This is a test!" )
def testConnectNode(self): s = Gaffer.ScriptNode() s["add1"] = GafferTest.AddNode() s["add2"] = GafferTest.AddNode() ge = GafferUI.GraphEditor(s) g = ge.graphGadget() # check we can connect to a top level plug g.getLayout().connectNode(g, s["add2"], Gaffer.StandardSet([s["add1"]])) self.assertTrue(s["add2"]["op1"].getInput().isSame(s["add1"]["sum"])) # check we can connect to a nested plug, but only provided it is represented # in the node graph by a nodule for that exact plug. s["compound"] = GafferTest.CompoundPlugNode() g.getLayout().connectNode(g, s["compound"], Gaffer.StandardSet([s["add2"]])) self.assertEqual(s["compound"]["p"]["f"].getInput(), None) Gaffer.Metadata.registerValue(GafferTest.CompoundPlugNode, "p", "nodule:type", "GafferUI::CompoundNodule") s["compound2"] = GafferTest.CompoundPlugNode() g.getLayout().connectNode(g, s["compound2"], Gaffer.StandardSet([s["add2"]])) self.assertTrue(s["compound2"]["p"]["f"].getInput().isSame( s["add2"]["sum"])) # check we can connect from a nested plug, but only provided it is represented # in the node graph by a nodule for that exact plug. s["add3"] = GafferTest.AddNode() g.getLayout().connectNode(g, s["add3"], Gaffer.StandardSet([s["compound2"]])) self.assertEqual(s["add3"]["op1"].getInput(), None) Gaffer.Metadata.registerValue(GafferTest.CompoundPlugNode, "o", "nodule:type", "GafferUI::CompoundNodule") s["compound3"] = GafferTest.CompoundPlugNode() g.getLayout().connectNode(g, s["add3"], Gaffer.StandardSet([s["compound3"]])) self.assertTrue(s["add3"]["op1"].getInput().isSame( s["compound3"]["o"]["f"]))
def testCreateWithExistingGraph( self ) : s = Gaffer.ScriptNode() s["add1"] = GafferTest.AddNode() s["add2"] = GafferTest.AddNode() s["add1"]["op1"].setInput( s["add2"]["sum"] ) g = GafferUI.GraphEditor( s ) self.failUnless( g.graphGadget().nodeGadget( s["add1"] ).node() is s["add1"] ) self.failUnless( g.graphGadget().nodeGadget( s["add2"] ).node() is s["add2"] ) self.failUnless( g.graphGadget().connectionGadget( s["add1"]["op1"] ).dstNodule().plug().isSame( s["add1"]["op1"] ) )
def testAddEditorLifetime(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() c = GafferUI.CompoundEditor(s) e = GafferUI.GraphEditor(s) c.addEditor(e) wc = weakref.ref(c) we = weakref.ref(e) del c del e self.assertEqual(wc(), None) self.assertEqual(we(), None)
def testAutomaticLayout(self): s = Gaffer.ScriptNode() s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["n2"]["op1"].setInput(s["n1"]["sum"]) s["b"] = Gaffer.Box() s["b"]["n1"] = GafferTest.AddNode() s["b"]["n2"] = GafferTest.AddNode() s["b"]["n2"]["op1"].setInput(s["b"]["n1"]["sum"]) with GafferUI.Window() as w: graphEditor = GafferUI.GraphEditor(s) w.setVisible(True) self.waitForIdle(10000) def assertLower(graphGadget, n1, n2): self.assertLess( graphGadget.getNodePosition(n1).y, graphGadget.getNodePosition(n2).y) self.assertEqual(graphEditor.graphGadget().unpositionedNodeGadgets(), []) assertLower(graphEditor.graphGadget(), s["n2"], s["n1"]) graphEditor.graphGadget().setRoot(s["b"]) self.waitForIdle(10000) self.assertEqual(graphEditor.graphGadget().unpositionedNodeGadgets(), []) assertLower(graphEditor.graphGadget(), s["b"]["n2"], s["b"]["n1"]) s["b"]["n3"] = GafferTest.AddNode() s["b"]["n3"]["op1"].setInput(s["b"]["n2"]["sum"]) self.waitForIdle(10000) self.assertEqual(graphEditor.graphGadget().unpositionedNodeGadgets(), []) assertLower(graphEditor.graphGadget(), s["b"]["n3"], s["b"]["n2"])
def testAuxiliaryConnectionsToMultipleNodes(self): # If an AuxiliaryNode is affecting multiple nodes, it's going to be # positioned between all nodes it has connections to. s = Gaffer.ScriptNode() s["o"] = LayoutNode() Gaffer.Metadata.registerValue(s["o"]["left0"], "nodule:type", "") s["i1"] = LayoutNode() Gaffer.Metadata.registerValue(s["i1"]["left0"], "nodule:type", "") s["i2"] = LayoutNode() Gaffer.Metadata.registerValue(s["i2"]["left0"], "nodule:type", "") s["e"] = Gaffer.Expression() s["e"].setExpression( "parent['i1']['left0'] = 0\nparent['i2']['left0'] = parent['o']['right0']" ) ge = GafferUI.GraphEditor(s) g = ge.graphGadget() g.setNodePosition(s["i1"], imath.V2f(20, 20)) g.setNodePosition(s["i2"], imath.V2f(20, -20)) g.setNodePosition(s["o"], imath.V2f(-20, 0)) g.getLayout().layoutNodes(g) oBounds = g.nodeGadget(s["o"]).transformedBound() i1Bounds = g.nodeGadget(s["i1"]).transformedBound() i2Bounds = g.nodeGadget(s["i2"]).transformedBound() expressionPosition = g.getNodePosition(s["e"]) self.assertTrue(expressionPosition.x < i1Bounds.min().x) self.assertTrue(expressionPosition.x < i2Bounds.min().x) self.assertTrue(expressionPosition.x > oBounds.max().x) self.assertTrue(expressionPosition.y < i1Bounds.min().y) self.assertTrue(expressionPosition.y > i2Bounds.max().y)
def testRootReparenting(self): # This test deliberately keeps b alive to mimic # the effects of an UndoScope or similar. s = Gaffer.ScriptNode() e = GafferUI.GraphEditor(s) b = Gaffer.Box() s["b"] = b e.graphGadget().setRoot(b) self.assertEqual(e.graphGadget().getRoot(), b) s.removeChild(b) self.assertEqual(e.graphGadget().getRoot(), s) s["b"] = b b["bb"] = Gaffer.Box() e.graphGadget().setRoot(b["bb"]) self.assertEqual(e.graphGadget().getRoot(), b["bb"]) s.removeChild(b) self.assertEqual(e.graphGadget().getRoot(), s) # Test with actually deleted nodes too s["b"] = b e.graphGadget().setRoot(b["bb"]) self.assertEqual(e.graphGadget().getRoot(), b["bb"]) del b del s["b"] self.assertEqual(e.graphGadget().getRoot(), s)
import GafferUI GafferUI.Layouts.add( "Default", GafferUI.CompoundEditor( children=(GafferUI.Splittable.SplitDirection.Vertical, ((GafferUI.Splittable.SplitDirection.Horizontal, ((GafferUI.Splittable.SplitDirection.None, (GafferUI.Viewer(), )), (GafferUI.Splittable.SplitDirection.None, (GafferUI.GraphEditor(), )))), (GafferUI.Splittable.SplitDirection.Horizontal, ((GafferUI.Splittable.SplitDirection.None, (GafferUI.NodeEditor(), )), (GafferUI.Splittable.SplitDirection.None, (GafferUI.ScriptEditor(), ))))))))
import IECore import Gaffer import GafferUI import IECore import gtk window = GafferUI.Window( title="Graph Editor test" ) window.gtkWidget().connect( "delete_event", gtk.main_quit ) s = Gaffer.ScriptNode() e = GafferUI.GraphEditor( s ) window.setChild( e ) window.show() GafferUI.EventLoop.start()
viewport = viewer.view().viewportGadget() viewport.frame(viewport.getPrimaryChild().bound()) viewer.view()["minimumExpansionDepth"].setValue(100) __delay(0.5) # Side-on look at scene cameraTransform = imath.M44f((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (60, 5, 200, 1)) viewport.setCameraTransform(cameraTransform) GafferUI.WidgetAlgo.grab( widget=viewer, imagePath="images/conceptPerformanceBestPracticesContextsViewer.png") # Concept: Context performance network in Graph Editor graphEditor.frame(script.children(Gaffer.Node)) with GafferUI.Window() as window: graphEditorWindow = GafferUI.GraphEditor(script) graphEditorWindow.parent().reveal() graphEditorWindow.parent()._qtWidget().resize(800, 520) __delay(0.01) graphEditorWindow.frame(script.children(Gaffer.Node)) __delay(0.01) GafferUI.WidgetAlgo.grab( widget=graphEditorWindow, imagePath="images/conceptPerformanceBestPracticesContextsGraphEditor.png") graphEditorWindow.parent().close() del graphEditorWindow # Concept: Context performance network with stats name = "conceptPerformanceBestPracticesContexts" nameImproved = name + "Improved" inputScript = os.path.abspath("scripts/{name}.gfr".format(name=name))