GafferHQ / gaffer

Gaffer is a node-based application for lookdev, lighting and automation
http://www.gafferhq.org
BSD 3-Clause "New" or "Revised" License
969 stars 207 forks source link

Should Gaffer.ScriptNode().applicationRoot() ever == None ?? #521

Closed bentoogood closed 11 years ago

bentoogood commented 11 years ago

Hi - in context of writing a gaffer app, once a Gaffer.ScriptNode is instantiated, should it not have a valid applicationRoot ?

In this example scriptNode.applicationRoot() returns None, causing the isinstance check to return False:

import Gaffer, IECore

class appRootDebug( Gaffer.Application ) :
    def __init__( self ) :

        Gaffer.Application.__init__( self, "Simple UI" )

    def _run( self, args ) :

        import GafferUI
        import GafferSceneUI

        scriptNode = Gaffer.ScriptNode()

        print scriptNode.applicationRoot()
        print isinstance( self, Gaffer.Application )
        print isinstance( scriptNode.applicationRoot(), Gaffer.Application )

        GafferUI.EventLoop.mainEventLoop().start()
        return 0

IECore.registerRunTimeTyped( appRootDebug )

This appears to be causing trouble in a more complex example. In an app with a NodeGraph editor, right click raises this error:

Traceback (most recent call last):
  File ".../python/GafferUI/Widget.py", line 1550, in eventFilter
    return self.__mouseButtonPress( qObject, qEvent )
  File ".../python/GafferUI/Widget.py", line 1643, in __mouseButtonPress
    result = widget._buttonPressSignal( widget, event )
  File ".../python/Gaffer/WeakMethod.py", line 57, in __call__
    return m( *args, **kwArgs )
  File ".../python/GafferUI/NodeGraph.py", line 264, in __buttonPress
    self._nodeMenu().popup( self )
  File ".../python/GafferUI/NodeGraph.py", line 225, in _nodeMenu
    self.__nodeMenu = GafferUI.Menu( GafferUI.NodeMenu.acquire( self.scriptNode().applicationRoot() ).definition(), searchable=True )
  File ".../python/GafferUI/NodeMenu.py", line 68, in acquire
    assert( isinstance( applicationOrApplicationRoot, Gaffer.ApplicationRoot ) )
AssertionError

The call to looks like line 225 in NodeGraph.py is passing None through as the applicationOrApplicationRoot causing the assert error.

thoughts?

johnhaddon commented 11 years ago

It's the responsibility of the app to add the ScriptNode to the scripts container in the ApplicationRoot - see the gui app for example :

self.root()["scripts"].addChild( scriptNode )