Ejemplo n.º 1
0
    def testHorizontalCentred(self):

        twoByFour = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        fourByFour = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-2, -2, 0), imath.V3f(2, 2, 0)))
        fourByTwo = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-2, -1, 0), imath.V3f(2, 1, 0)))

        c = GafferUI.LinearContainer()

        c["c1"] = twoByFour
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        self.assertEqual(twoByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(0)))

        c["c2"] = fourByFour
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-3, -2, 0), imath.V3f(3, 2, 0)))
        self.assertEqual(twoByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(-2, 0, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(1, 0, 0)))

        c["c3"] = fourByTwo
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-5, -2, 0), imath.V3f(5, 2, 0)))
        self.assertEqual(twoByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(-4, 0, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(-1, 0, 0)))
        self.assertEqual(fourByTwo.getTransform(),
                         imath.M44f().translate(imath.V3f(3, 0, 0)))
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    def testDirection(self):

        first = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1, -2), IECore.V2f(1, 2))))

        second = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1, -2), IECore.V2f(1, 2))))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)

        c["c1"] = first
        c["c2"] = second

        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -4, 0), IECore.V3f(1, 4,
                                                                      0)))
        self.assertEqual(first.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, -2, 0)))
        self.assertEqual(second.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, 2, 0)))

        c.setDirection(GafferUI.LinearContainer.Direction.Decreasing)

        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -4, 0), IECore.V3f(1, 4,
                                                                      0)))
        self.assertEqual(first.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, 2, 0)))
        self.assertEqual(second.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, -2, 0)))
Ejemplo n.º 4
0
    def testDirection(self):

        first = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        second = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)

        c["c1"] = first
        c["c2"] = second

        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -4, 0), imath.V3f(1, 4, 0)))
        self.assertEqual(first.getTransform(),
                         imath.M44f().translate(imath.V3f(0, -2, 0)))
        self.assertEqual(second.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 2, 0)))

        c.setDirection(GafferUI.LinearContainer.Direction.Decreasing)

        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -4, 0), imath.V3f(1, 4, 0)))
        self.assertEqual(first.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 2, 0)))
        self.assertEqual(second.getTransform(),
                         imath.M44f().translate(imath.V3f(0, -2, 0)))
    def testConstruction(self):

        c = GafferUI.LinearContainer()
        self.assertEqual(c.getName(), "LinearContainer")
        self.assertEqual(c.getOrientation(),
                         GafferUI.LinearContainer.Orientation.X)
        self.assertEqual(c.getAlignment(),
                         GafferUI.LinearContainer.Alignment.Centre)
        self.assertEqual(c.getSpacing(), 0)

        c = GafferUI.LinearContainer(name="a")
        self.assertEqual(c.getName(), "a")
        self.assertEqual(c.getOrientation(),
                         GafferUI.LinearContainer.Orientation.X)
        self.assertEqual(c.getAlignment(),
                         GafferUI.LinearContainer.Alignment.Centre)
        self.assertEqual(c.getSpacing(), 0)

        c = GafferUI.LinearContainer(spacing=10)
        self.assertEqual(c.getName(), "LinearContainer")
        self.assertEqual(c.getOrientation(),
                         GafferUI.LinearContainer.Orientation.X)
        self.assertEqual(c.getAlignment(),
                         GafferUI.LinearContainer.Alignment.Centre)
        self.assertEqual(c.getSpacing(), 10)

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)
        self.assertEqual(c.getName(), "LinearContainer")
        self.assertEqual(c.getOrientation(),
                         GafferUI.LinearContainer.Orientation.Y)
        self.assertEqual(c.getAlignment(),
                         GafferUI.LinearContainer.Alignment.Centre)
        self.assertEqual(c.getSpacing(), 0)

        c = GafferUI.LinearContainer(
            alignment=GafferUI.LinearContainer.Alignment.Min)
        self.assertEqual(c.getName(), "LinearContainer")
        self.assertEqual(c.getOrientation(),
                         GafferUI.LinearContainer.Orientation.X)
        self.assertEqual(c.getAlignment(),
                         GafferUI.LinearContainer.Alignment.Min)
        self.assertEqual(c.getSpacing(), 0)

        self.assert_(c.bound().isEmpty())
Ejemplo n.º 6
0
    def testTransform(self):

        g = GafferUI.TextGadget("hello")
        self.assertEqual(g.getTransform(), IECore.M44f())

        t = IECore.M44f.createScaled(IECore.V3f(2))
        g.setTransform(t)
        self.assertEqual(g.getTransform(), t)

        c1 = GafferUI.LinearContainer()
        c1.addChild(g)

        c2 = GafferUI.LinearContainer()
        c2.addChild(c1)
        t2 = IECore.M44f.createTranslated(IECore.V3f(1, 2, 3))
        c2.setTransform(t2)

        self.assertEqual(g.fullTransform(), t * t2)
        self.assertEqual(g.fullTransform(c1), t)
Ejemplo n.º 7
0
    def testTransform(self):

        g = GafferUI.TextGadget("hello")
        self.assertEqual(g.getTransform(), imath.M44f())

        t = imath.M44f().scale(imath.V3f(2))
        g.setTransform(t)
        self.assertEqual(g.getTransform(), t)

        c1 = GafferUI.LinearContainer()
        c1.addChild(g)

        c2 = GafferUI.LinearContainer()
        c2.addChild(c1)
        t2 = imath.M44f().translate(imath.V3f(1, 2, 3))
        c2.setTransform(t2)

        self.assertEqual(g.fullTransform(), t * t2)
        self.assertEqual(g.fullTransform(c1), t)
    def testVerticalMin(self):

        twoByFour = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1, -2), IECore.V2f(1, 2))))

        fourByFour = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2, -2), IECore.V2f(2, 2))))

        fourByTwo = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2, -1), IECore.V2f(2, 1))))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y,
            alignment=GafferUI.LinearContainer.Alignment.Min)

        c["c1"] = twoByFour
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -2, 0), IECore.V3f(1, 2,
                                                                      0)))
        self.assertEqual(twoByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0)))

        c["c2"] = fourByFour
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-2, -4, 0), IECore.V3f(2, 4,
                                                                      0)))
        self.assertEqual(twoByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(-1, -2, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, 2, 0)))

        c["c3"] = fourByTwo
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-2, -5, 0), IECore.V3f(2, 5,
                                                                      0)))
        self.assertEqual(twoByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(-1, -3, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, 1, 0)))
        self.assertEqual(fourByTwo.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0, 4, 0)))
Ejemplo n.º 9
0
    def testDirectionAndSpacing(self):

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)
        c["g1"] = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -1, 0), imath.V3f(1, 1, 0)))
        c["g2"] = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -1, 0), imath.V3f(1, 1, 0)))

        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))

        c.setSpacing(2)
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -3, 0), imath.V3f(1, 3, 0)))

        c.setDirection(GafferUI.LinearContainer.Direction.Decreasing)
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -3, 0), imath.V3f(1, 3, 0)))
    def testHorizontalCentred(self):

        twoByFour = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1, -2), IECore.V2f(1, 2))))

        fourByFour = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2, -2), IECore.V2f(2, 2))))

        fourByTwo = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2, -1), IECore.V2f(2, 1))))

        c = GafferUI.LinearContainer()

        c["c1"] = twoByFour
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -2, 0), IECore.V3f(1, 2,
                                                                      0)))
        self.assertEqual(twoByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(0)))

        c["c2"] = fourByFour
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-3, -2, 0), IECore.V3f(3, 2,
                                                                      0)))
        self.assertEqual(twoByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(-2, 0, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(1, 0, 0)))

        c["c3"] = fourByTwo
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-5, -2, 0), IECore.V3f(5, 2,
                                                                      0)))
        self.assertEqual(twoByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(-4, 0, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(-1, 0, 0)))
        self.assertEqual(fourByTwo.getTransform(),
                         IECore.M44f.createTranslated(IECore.V3f(3, 0, 0)))
Ejemplo n.º 11
0
    def testStyle(self):

        g = GafferUI.TextGadget("test")
        l = GafferUI.LinearContainer()
        l.addChild(g)

        self.assertEqual(g.getStyle(), None)
        self.assertEqual(l.getStyle(), None)

        self.failUnless(g.style().isSame(GafferUI.Style.getDefaultStyle()))
        self.failUnless(l.style().isSame(GafferUI.Style.getDefaultStyle()))

        s = GafferUI.StandardStyle()
        l.setStyle(s)

        self.failUnless(l.getStyle().isSame(s))
        self.assertEqual(g.getStyle(), None)

        self.failUnless(g.style().isSame(s))
        self.failUnless(l.style().isSame(s))
Ejemplo n.º 12
0
    def testPadding(self):

        twoByFour = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)
        c.addChild(twoByFour)

        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        self.assertEqual(c.getPadding(), imath.Box3f(imath.V3f(0),
                                                     imath.V3f(0)))

        c.setPadding(imath.Box3f(imath.V3f(-1, -2, -3), imath.V3f(1, 2, 3)))
        self.assertEqual(
            c.getPadding(),
            imath.Box3f(imath.V3f(-1, -2, -3), imath.V3f(1, 2, 3)))
        self.assertEqual(
            c.bound(), imath.Box3f(imath.V3f(-2, -4, -3), imath.V3f(2, 4, 3)))
Ejemplo n.º 13
0
    def testChildVisibility(self):

        g1 = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(0), imath.V3f(1, 1, 0)))
        g2 = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(0), imath.V3f(2, 1, 0)))
        g3 = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(0), imath.V3f(5, 1, 0)))

        c = GafferUI.LinearContainer(spacing=1)
        c.addChild(g1)

        self.assertEqual(
            c.bound(),
            imath.Box3f(imath.V3f(-0.5, -0.5, 0), imath.V3f(0.5, 0.5, 0)))

        c.addChild(g2)
        self.assertEqual(
            c.bound(), imath.Box3f(imath.V3f(-2, -0.5, 0),
                                   imath.V3f(2, 0.5, 0)))

        g2.setVisible(False)
        # should be as if the child didn't exist
        self.assertEqual(
            c.bound(),
            imath.Box3f(imath.V3f(-0.5, -0.5, 0), imath.V3f(0.5, 0.5, 0)))

        g2.setVisible(True)
        self.assertEqual(
            c.bound(), imath.Box3f(imath.V3f(-2, -0.5, 0),
                                   imath.V3f(2, 0.5, 0)))

        c.addChild(g3)
        self.assertEqual(
            c.bound(), imath.Box3f(imath.V3f(-5, -0.5, 0),
                                   imath.V3f(5, 0.5, 0)))

        g1.setVisible(False)
        self.assertEqual(
            c.bound(), imath.Box3f(imath.V3f(-4, -0.5, 0),
                                   imath.V3f(4, 0.5, 0)))
Ejemplo n.º 14
0
	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 )
Ejemplo n.º 15
0
    def testPadding(self):

        twoByFour = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1, -2), IECore.V2f(1, 2))))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)
        c.addChild(twoByFour)

        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -2, 0), IECore.V3f(1, 2,
                                                                      0)))
        self.assertEqual(c.getPadding(),
                         IECore.Box3f(IECore.V3f(0), IECore.V3f(0)))

        c.setPadding(IECore.Box3f(IECore.V3f(-1, -2, -3), IECore.V3f(1, 2, 3)))
        self.assertEqual(
            c.getPadding(),
            IECore.Box3f(IECore.V3f(-1, -2, -3), IECore.V3f(1, 2, 3)))
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-2, -4, -3),
                                    IECore.V3f(2, 4, 3)))
Ejemplo n.º 16
0
    def testVerticalMin(self):

        twoByFour = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        fourByFour = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-2, -2, 0), imath.V3f(2, 2, 0)))
        fourByTwo = GafferUI.SpacerGadget(
            imath.Box3f(imath.V3f(-2, -1, 0), imath.V3f(2, 1, 0)))

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y,
            alignment=GafferUI.LinearContainer.Alignment.Min)

        c["c1"] = twoByFour
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-1, -2, 0), imath.V3f(1, 2, 0)))
        self.assertEqual(twoByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(0)))

        c["c2"] = fourByFour
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-2, -4, 0), imath.V3f(2, 4, 0)))
        self.assertEqual(twoByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(-1, -2, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 2, 0)))

        c["c3"] = fourByTwo
        self.assertEqual(c.bound(),
                         imath.Box3f(imath.V3f(-2, -5, 0), imath.V3f(2, 5, 0)))
        self.assertEqual(twoByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(-1, -3, 0)))
        self.assertEqual(fourByFour.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 1, 0)))
        self.assertEqual(fourByTwo.getTransform(),
                         imath.M44f().translate(imath.V3f(0, 4, 0)))
Ejemplo n.º 17
0
    def testDirectionAndSpacing(self):

        c = GafferUI.LinearContainer(
            orientation=GafferUI.LinearContainer.Orientation.Y)
        c["g1"] = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))))
        c["g2"] = GafferUI.RenderableGadget(
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))))

        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -2, 0), IECore.V3f(1, 2,
                                                                      0)))

        c.setSpacing(2)
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -3, 0), IECore.V3f(1, 3,
                                                                      0)))

        c.setDirection(GafferUI.LinearContainer.Direction.Decreasing)
        self.assertEqual(
            c.bound(), IECore.Box3f(IECore.V3f(-1, -3, 0), IECore.V3f(1, 3,
                                                                      0)))
import GafferUI
import gtk
		
window = GafferUI.Window( title="Linear container test" )
window.gtkWidget().connect( "delete_event", gtk.main_quit )

twoByFour = GafferUI.RenderableGadget(
	IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1, -2 ), IECore.V2f( 1, 2 ) ) )
)

fourByFour = GafferUI.RenderableGadget(
	IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -2, -2 ), IECore.V2f( 2, 2 ) ) )
)

fourByTwo = GafferUI.RenderableGadget(
	IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -2, -1 ), IECore.V2f( 2, 1 ) ) )
)
		
c = GafferUI.LinearContainer( orientation=GafferUI.LinearContainer.Orientation.Y, alignment=GafferUI.LinearContainer.Alignment.Min, spacing=1 )
c.c1 = twoByFour
c.c2 = fourByFour
c.c3 = fourByTwo

s = GafferUI.GadgetWidget( c )

window.setChild( s )

window.show()

GafferUI.EventLoop.start()