Beispiel #1
0
    def create(self, name, scriptNode):

        layout = self.__namedLayouts[name]

        # first try to import the modules the layout needs
        contextDict = {"scriptNode": scriptNode, "imath": imath}
        imported = set()
        classNameRegex = re.compile(r"[a-zA-Z]*Gaffer[^(,]*\(")
        for className in classNameRegex.findall(layout.repr):
            moduleName = className.partition(".")[0]
            if moduleName not in imported:
                try:
                    exec("import %s" % moduleName, contextDict, contextDict)
                except (ImportError):
                    IECore.msg(
                        IECore.MessageHandler.Level.Error, "GafferUI.Layouts",
                        "Failed to load \"{layout}\" layout. {module} is not available."
                        .format(layout=name, module=moduleName))
                    return GafferUI.CompoundEditor(scriptNode)
                imported.add(moduleName)

        try:
            return eval(layout.repr, contextDict, contextDict)
        except Exception as e:
            traceback.print_exc()
            IECore.msg(
                IECore.MessageHandler.Level.Error, "GafferUI.Layouts",
                "Failed to load \"{layout}\" layout. {message}.".format(
                    layout=name, message=e))
            return GafferUI.CompoundEditor(scriptNode)
Beispiel #2
0
    def __init__(self, script, **kw):

        GafferUI.Window.__init__(self, **kw)

        self.__script = script

        self.__listContainer = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Vertical, spacing=2)

        menuDefinition = self.menuDefinition(script.applicationRoot(
        )) if script.applicationRoot() else IECore.MenuDefinition()
        self.__listContainer.append(GafferUI.MenuBar(menuDefinition))

        applicationRoot = self.__script.ancestor(
            Gaffer.ApplicationRoot.staticTypeId())
        layouts = GafferUI.Layouts.acquire(
            applicationRoot) if applicationRoot is not None else None
        if layouts is not None and "Default" in layouts.names():
            self.setLayout(layouts.create("Default", script))
        else:
            self.setLayout(GafferUI.CompoundEditor(script))

        self.setChild(self.__listContainer)

        self.__closedConnection = self.closedSignal().connect(
            Gaffer.WeakMethod(self.__closed))

        self.__scriptPlugSetConnection = script.plugSetSignal().connect(
            Gaffer.WeakMethod(self.__scriptPlugChanged))

        self.__updateTitle()

        ScriptWindow.__instances.append(weakref.ref(self))
Beispiel #3
0
    def testSetNodeSetDriverRestore(self):

        s = Gaffer.ScriptNode()
        c = GafferUI.CompoundEditor(s)

        GafferUI.NodeSetEditor.registerNodeSetDriverMode(
            "testMode", lambda e, t: t.getNodeSet())

        editors = list((GafferUI.NodeEditor(s), GafferUI.NodeEditor(s),
                        GafferUI.AnimationEditor(s), GafferUI.NodeEditor(s)))

        editors[0].setNodeSetDriver(editors[1])
        editors[2].setNodeSetDriver(editors[3], "testMode")

        for e in editors:
            c.addEditor(e)

        a = Gaffer.ApplicationRoot("testApp")
        l = GafferUI.Layouts.acquire(a)
        l.add("ReprDriverTest", repr(c), persistent=False)

        cc = l.create("ReprDriverTest", s)

        editors = cc.editors()

        driver, mode = editors[0].getNodeSetDriver()
        self.assertTrue(driver is editors[1])
        self.assertTrue(mode is GafferUI.NodeSetEditor.DriverModeNodeSet)

        driver, mode = editors[2].getNodeSetDriver()
        self.assertTrue(driver is editors[3])
        self.assertTrue(mode is "testMode")

        driver, mode = editors[3].getNodeSetDriver()
        self.assertIsNone(driver)
Beispiel #4
0
    def __init__(self, script, **kw):

        self.__titleChangedSignal = GafferUI.WidgetEventSignal()

        GafferUI.Window.__init__(self, **kw)

        self.__script = script

        self.__titleBehaviour = _WindowTitleBehaviour(self, script)

        self.__listContainer = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Vertical, spacing=0)

        menuDefinition = self.menuDefinition(script.applicationRoot(
        )) if script.applicationRoot() else IECore.MenuDefinition()
        self.__listContainer.append(GafferUI.MenuBar(menuDefinition))

        applicationRoot = self.__script.ancestor(Gaffer.ApplicationRoot)
        layouts = GafferUI.Layouts.acquire(
            applicationRoot) if applicationRoot is not None else None
        if layouts is not None:
            self.setLayout(layouts.createDefault(script))
        else:
            self.setLayout(GafferUI.CompoundEditor(script))

        self.setChild(self.__listContainer)

        self.closedSignal().connect(Gaffer.WeakMethod(self.__closed),
                                    scoped=False)

        ScriptWindow.__instances.append(weakref.ref(self))
Beispiel #5
0
    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))
Beispiel #6
0
	def testReprLifetime( self ) :

		s = Gaffer.ScriptNode()
		c = GafferUI.CompoundEditor( s )

		wc = weakref.ref( c )
		repr( c )

		del c

		self.assertEqual( wc(), None )
Beispiel #7
0
	def testEditorAddedSignal( self ) :

		s = Gaffer.ScriptNode()
		c = GafferUI.CompoundEditor( s )

		cs = GafferTest.CapturingSlot( c.editorAddedSignal() )

		n = GafferUI.NodeEditor( s )
		c.addEditor( n )

		self.assertEqual( len( cs ), 1 )
		self.assertTrue( cs[0][0] is c )
		self.assertTrue( cs[0][1] is n )
    def testWindowStateCompatibility(self):

        s = Gaffer.ScriptNode()
        c = GafferUI.CompoundEditor(s)

        sw = GafferUI.ScriptWindow.acquire(s)
        sw.setLayout(c)
        sw.setVisible(True)

        d = eval(c._serializeWindowState())

        self.assertIsInstance(d, dict)
        self.assertIsInstance(d["fullScreen"], bool)
        self.assertIsInstance(d["maximized"], bool)
        self.assertIsInstance(d["screen"], int)
        self.assertIsInstance(d["bound"], imath.Box2f)
    def testDetachedPanelsLifetime(self):

        s = Gaffer.ScriptNode()
        c = GafferUI.CompoundEditor(s)

        p = c._createDetachedPanel()

        wp = weakref.ref(p)

        ps = c._detachedPanels()
        self.assertTrue(ps[0] is p)

        del ps
        del p
        del c

        self.assertEqual(wp(), None)
Beispiel #10
0
    def testAddEditorLifetime(self):

        s = Gaffer.ScriptNode()
        s["n"] = GafferTest.AddNode()

        c = GafferUI.CompoundEditor(s)
        e = GafferUI.NodeGraph(s)
        c.addEditor(e)

        wc = weakref.ref(c)
        we = weakref.ref(e)

        del c
        del e

        self.assertEqual(wc(), None)
        self.assertEqual(we(), None)
Beispiel #11
0
    def testAcquireTargetTypes(self):

        a = Gaffer.Application()

        b = GafferUI.Bookmarks.acquire(a)
        b.setDefault("/a/default/path")

        b = GafferUI.Bookmarks.acquire(a.root())
        self.assertEqual(b.getDefault(), "/a/default/path")

        a.root()["scripts"]["one"] = Gaffer.ScriptNode()

        b = GafferUI.Bookmarks.acquire(a.root()["scripts"]["one"])
        self.assertEqual(b.getDefault(), "/a/default/path")

        s = GafferUI.ScriptWindow(a.root()["scripts"]["one"])

        b = GafferUI.Bookmarks.acquire(s)
        self.assertEqual(b.getDefault(), "/a/default/path")

        s.setLayout(GafferUI.CompoundEditor(a.root()["scripts"]["one"]))

        b = GafferUI.Bookmarks.acquire(s.getLayout())
        self.assertEqual(b.getDefault(), "/a/default/path")

        w = GafferUI.Window()
        w.setChild(GafferUI.Button())
        s.addChildWindow(w)

        b = GafferUI.Bookmarks.acquire(w)
        self.assertEqual(b.getDefault(), "/a/default/path")

        b = GafferUI.Bookmarks.acquire(w.getChild())
        self.assertEqual(b.getDefault(), "/a/default/path")

        w2 = GafferUI.Window()  # not attached to a script at all
        w2.setChild(GafferUI.Button())

        b = GafferUI.Bookmarks.acquire((w2.getChild(), a))
        self.assertEqual(b.getDefault(), "/a/default/path")

        g = Gaffer.GraphComponent()  # not attached to a script at all

        b = GafferUI.Bookmarks.acquire((g, w.getChild()))
        self.assertEqual(b.getDefault(), "/a/default/path")
Beispiel #12
0
	def testEditorsLifetime( self ) :

		s = Gaffer.ScriptNode()
		c = GafferUI.CompoundEditor( s )

		n = GafferUI.NodeEditor( s )
		c.addEditor( n )

		wc = weakref.ref( c )
		wn = weakref.ref( n )

		e = c.editors()
		self.assertTrue( e[0] is n )

		del e
		del c
		del n

		self.assertEqual( wc(), None )
		self.assertEqual( wn(), None )
Beispiel #13
0
    def testNodeSetRestore(self):

        s = Gaffer.ScriptNode()
        c = GafferUI.CompoundEditor(s)

        editors = list((GafferUI.NodeEditor(s), GafferUI.NodeEditor(s),
                        GafferUI.AnimationEditor(s), GafferUI.NodeEditor(s)))

        editors[0].setNodeSet(Gaffer.NumericBookmarkSet(s, 1))
        editors[1].setNodeSet(Gaffer.NumericBookmarkSet(s, 2))
        editors[2].setNodeSet(Gaffer.NumericBookmarkSet(s, 3))

        for e in editors:
            c.addEditor(e)

        a = Gaffer.ApplicationRoot("testApp")
        l = GafferUI.Layouts.acquire(a)
        l.add("ReprNodeSetTest", repr(c), persistent=False)

        cc = l.create("ReprNodeSetTest", s)

        editors = cc.editors()

        ns = editors[0].getNodeSet()
        self.assertTrue(isinstance(ns, Gaffer.NumericBookmarkSet))
        self.assertTrue(ns.getBookmark(), 1)

        ns = editors[1].getNodeSet()
        self.assertTrue(isinstance(ns, Gaffer.NumericBookmarkSet))
        self.assertTrue(ns.getBookmark(), 2)

        ns = editors[2].getNodeSet()
        self.assertTrue(isinstance(ns, Gaffer.NumericBookmarkSet))
        self.assertTrue(ns.getBookmark(), 3)

        ns = editors[3].getNodeSet()
        self.assertTrue(isinstance(ns, Gaffer.StandardSet))
    def __init__(self, script):

        GafferUI.Window.__init__(self)

        self.__script = script

        self.__listContainer = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Vertical)
        self.__listContainer.show()

        m = GafferUI.MenuBar(self.menuDefinition())

        self.__listContainer.append(m)

        if "Default" in GafferUI.Layouts.names():
            self.setLayout(GafferUI.Layouts.create("Default"))
        else:
            self.setLayout(GafferUI.CompoundEditor())

        self.setChild(self.__listContainer)

        scriptParent = script.parent()
        if scriptParent:
            self.__scriptRemovedConnection = scriptParent.childRemovedSignal(
            ).connect(self.__scriptRemoved)

        self.__closedConnection = self.closedSignal().connect(self.__closed)

        self.__scriptPlugSetConnection = script.plugSetSignal().connect(
            self.__scriptPlugChanged)
        self.__scriptPlugDirtiedConnection = script.plugDirtiedSignal(
        ).connect(self.__scriptPlugChanged)

        self.__updateTitle()

        ScriptWindow.__instances.append(self)
Beispiel #15
0
    def createDefault(self, scriptNode):

        if self.__default in self.__namedLayouts:
            return self.create(self.__default, scriptNode)
        else:
            return GafferUI.CompoundEditor(scriptNode)
Beispiel #16
0
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 gtk

## \todo Rejig this to remove all gtk specific code, and use only GafferUI classes instead

window = GafferUI.Window( "Panel test" )
window.gtkWidget().connect( "delete_event", gtk.main_quit )

window.setChild( GafferUI.CompoundEditor( Gaffer.ScriptNode() ) )

window.show()

GafferUI.EventLoop.start()