def __nodeGadgetCreator(node): import IECore import GafferUI result = GafferUI.StandardNodeGadget(node) row = GafferUI.LinearContainer( orientation=GafferUI.LinearContainer.Orientation.X, alignment=GafferUI.LinearContainer.Alignment.Centre, spacing=0.5, ) image = None for typeId in [node.typeId()] + IECore.RunTimeTyped.baseTypeIds( node.typeId()): try: image = GafferUI.ImageGadget( "nodeIcon" + IECore.RunTimeTyped.typeNameFromTypeId(typeId) + ".png") break except: pass if image is not None: image.setTransform( IECore.M44f.createScaled(IECore.V3f(2.0 / image.bound().size().y))) row.addChild(GafferUI.IndividualContainer(image)) row.addChild(GafferUI.NameGadget(node)) result.setContents(row) return result
def __updateViewportMessage( self, unused = None ) : if self.view() is not None : return text = None icon = None if self.getNodeSet() == self.scriptNode().focusSet() : text = "Focus a node to view" icon = "viewerFocusPrompt.png" elif self.getNodeSet() == self.scriptNode().selection() : text = "Select a node to view" icon = "viewerSelectPrompt.png" else : self.__gadgetWidget.setViewportGadget( GafferUI.ViewportGadget() ) return image = GafferUI.ImageGadget( icon ) image.setTransform( imath.M44f().setScale( imath.V3f( 3.0 ) / image.bound().size().y ) ) message = GafferUI.TextGadget( text ) messageStyle = GafferUI.StandardStyle() messageStyle.setColor( GafferUI.StandardStyle.Color.ForegroundColor, imath.Color3f( 94 / 255.0 ) ) message.setStyle( messageStyle ) column = GafferUI.LinearContainer( "column", GafferUI.LinearContainer.Orientation.Y, GafferUI.LinearContainer.Alignment.Centre, spacing = 0.5 ) column.addChild( GafferUI.IndividualContainer( message ) ) column.addChild( GafferUI.IndividualContainer( image ) ) column.setPadding( imath.Box3f( imath.V3f( -10 ), imath.V3f( 10 ) ) ) viewport = GafferUI.ViewportGadget( column ) viewport.frame( column.bound() ) viewport.setCameraEditable( False ) self.__gadgetWidget.setViewportGadget( viewport )
def testDerivationInPython(self): class MyGadget(GafferUI.Gadget): def __init__(self): GafferUI.Gadget.__init__(self) def bound(self): return IECore.Box3f(IECore.V3f(-20, 10, 2), IECore.V3f(10, 15, 5)) mg = MyGadget() # we can't call the methods of the gadget directly in python to test the # bindings, as that doesn't prove anything (we're no exercising the virtual # method override code in the wrapper). instead cause c++ to call through # for us by adding our gadget to a parent and making calls to the parent. c = GafferUI.IndividualContainer() c.addChild(mg) self.assertEqual(c.bound().size(), mg.bound().size())
def testDerivationInPython(self): class MyGadget(GafferUI.Gadget): def __init__(self): GafferUI.Gadget.__init__(self) self.layersRendered = set() def bound(self): return IECore.Box3f(IECore.V3f(-20, 10, 2), IECore.V3f(10, 15, 5)) def doRenderLayer(self, layer, style): self.layersRendered.add(layer) mg = MyGadget() # we can't call the methods of the gadget directly in python to test the # bindings, as that doesn't prove anything (we're no exercising the virtual # method override code in the wrapper). instead cause c++ to call through # for us by adding our gadget to a parent and making calls to the parent. c = GafferUI.IndividualContainer() c.addChild(mg) self.assertEqual(c.bound().size(), mg.bound().size()) with GafferUI.Window() as w: GafferUI.GadgetWidget(c) w.setVisible(True) self.waitForIdle(1000) self.assertEqual(mg.layersRendered, set(GafferUI.Gadget.Layer.values.values()))
def testDerivationInPython(self): b = imath.Box3f(imath.V3f(-20, 10, 2), imath.V3f(10, 15, 5)) layers = [ GafferUI.Gadget.Layer.Main, GafferUI.Gadget.Layer.MidBack, GafferUI.Gadget.Layer.Front ] class MyGadget(GafferUI.Gadget): def __init__(self): GafferUI.Gadget.__init__(self) self.layersRendered = set() def bound(self): return b def renderLayer(self, layer, style, reason): self.layersRendered.add((layer, style, reason)) def layerMask(self): return functools.reduce(operator.or_, layers) def renderBound(self): return b mg = MyGadget() # we can't call the methods of the gadget directly in python to test the # bindings, as that doesn't prove anything (we're no exercising the virtual # method override code in the wrapper). instead cause c++ to call through # for us by adding our gadget to a parent and making calls to the parent. c = GafferUI.IndividualContainer() c.addChild(mg) self.assertEqual(c.bound().size(), mg.bound().size()) with GafferUI.Window() as w: gw = GafferUI.GadgetWidget(c) gw.getViewportGadget().frame(b) w.setVisible(True) self.waitForIdle(1000) self.assertEqual(set(i[0] for i in mg.layersRendered), set(layers)) mg.layersRendered = set() s = GafferUI.StandardStyle() c.setStyle(s) self.waitForIdle(1000) self.assertEqual( mg.layersRendered, set((i, s, GafferUI.Gadget.RenderReason.Draw) for i in layers))