Skip to content

Commit

Permalink
Merge pull request #891 from andrewkaufman/currentDispatcher
Browse files Browse the repository at this point in the history
Added Current Dispatcher dropdown to DispatcherWindow.
  • Loading branch information
johnhaddon committed Jun 30, 2014
2 parents b76ff29 + ba2d623 commit 6499520
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 49 deletions.
2 changes: 1 addition & 1 deletion python/Gaffer/LocalDispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ def __nextJobId( self, directory ) :

IECore.registerRunTimeTyped( LocalDispatcher, typeName = "Gaffer::LocalDispatcher" )

Gaffer.Dispatcher.registerDispatcher( "local", LocalDispatcher() )
Gaffer.Dispatcher.registerDispatcher( "Local", LocalDispatcher() )
20 changes: 10 additions & 10 deletions python/GafferTest/LocalDispatcherTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ class LocalDispatcherTest( GafferTest.TestCase ) :

def setUp( self ) :

localDispatcher = Gaffer.Dispatcher.dispatcher( "local" )
localDispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
localDispatcher["jobDirectory"].setValue( "/tmp/dispatcherTest" )
localDispatcher["framesMode"].setValue( Gaffer.Dispatcher.FramesMode.CurrentFrame )

def testDispatcherRegistration( self ) :

self.failUnless( "local" in Gaffer.Dispatcher.dispatcherNames() )
self.failUnless( Gaffer.Dispatcher.dispatcher( "local" ).isInstanceOf( Gaffer.LocalDispatcher.staticTypeId() ) )
self.failUnless( "Local" in Gaffer.Dispatcher.dispatcherNames() )
self.failUnless( Gaffer.Dispatcher.dispatcher( "Local" ).isInstanceOf( Gaffer.LocalDispatcher.staticTypeId() ) )

def testDispatch( self ) :

dispatcher = Gaffer.Dispatcher.dispatcher( "local" )
dispatcher = Gaffer.Dispatcher.dispatcher( "Local" )

def createWriter( text ) :
node = GafferTest.TextWriter()
Expand Down Expand Up @@ -146,7 +146,7 @@ def testDispatchDifferentFrame( self ) :
context.setFrame( s.context().getFrame() + 10 )

with context :
Gaffer.Dispatcher.dispatcher( "local" ).dispatch( [ s["n1"] ] )
Gaffer.Dispatcher.dispatcher( "Local" ).dispatch( [ s["n1"] ] )

fileName = context.substitute( s["n1"]["fileName"].getValue() )
self.assertTrue( os.path.isfile( fileName ) )
Expand All @@ -156,7 +156,7 @@ def testDispatchDifferentFrame( self ) :

def testDispatchScriptRange( self ) :

dispatcher = Gaffer.Dispatcher.dispatcher( "local" )
dispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
dispatcher["framesMode"].setValue( Gaffer.Dispatcher.FramesMode.ScriptRange )
frameList = IECore.FrameList.parse( "5-7" )

Expand Down Expand Up @@ -229,7 +229,7 @@ def verify( contexts, nodes = [ "n1", "n2", "n2a", "n2b" ], exist = True ) :

def testDispatchCustomRange( self ) :

dispatcher = Gaffer.Dispatcher.dispatcher( "local" )
dispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
dispatcher["framesMode"].setValue( Gaffer.Dispatcher.FramesMode.CustomRange )
frameList = IECore.FrameList.parse( "2-6x2" )
dispatcher["frameRange"].setValue( str(frameList) )
Expand Down Expand Up @@ -301,7 +301,7 @@ def verify( contexts, nodes = [ "n1", "n2", "n2a", "n2b" ], exist = True ) :

def testDispatchBadCustomRange( self ) :

dispatcher = Gaffer.Dispatcher.dispatcher( "local" )
dispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
dispatcher["framesMode"].setValue( Gaffer.Dispatcher.FramesMode.CustomRange )
dispatcher["frameRange"].setValue( "notAFrameRange" )

Expand All @@ -328,7 +328,7 @@ def testContextVariation( self ) :
self.assertFalse( os.path.isfile( fileName ) )

with context :
Gaffer.Dispatcher.dispatcher( "local" ).dispatch( [ s["n1"] ] )
Gaffer.Dispatcher.dispatcher( "Local" ).dispatch( [ s["n1"] ] )

self.assertTrue( os.path.isfile( fileName ) )
self.assertTrue( os.path.basename( fileName ).startswith( context["script:name"] ) )
Expand Down Expand Up @@ -361,7 +361,7 @@ def __slot( self, d, nodes ) :
s["n1"]["fileName"].setValue( "/tmp/dispatcherTest/n1_####.txt" )
s["n1"]["text"].setValue( "n1 on ${frame}" )

dispatcher = Gaffer.Dispatcher.dispatcher( "local" )
dispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
dispatcher.dispatch( [ s["n1"] ] )

self.assertEqual( len( preCs ), 1 )
Expand Down
73 changes: 36 additions & 37 deletions python/GafferUI/DispatcherUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,29 @@ def repeatPrevious( menu ) :

class _DispatcherWindow( GafferUI.Window ) :

def __init__( self, dispatcher, **kw ) :
def __init__( self, **kw ) :

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

self.__dispatcher = dispatcher
self.__dispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
self.__nodes = []

with self :

with GafferUI.ListContainer( orientation = GafferUI.ListContainer.Orientation.Vertical, spacing = 2, borderWidth = 4 ) :

GafferUI.NodeUI.create( dispatcher )
with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal, spacing = 4 ) :
GafferUI.Label( "Dispatcher" )
dispatchersMenu = GafferUI.MultiSelectionMenu( allowMultipleSelection = False, allowEmptySelection = False )
dispatchersMenu.append( Gaffer.Dispatcher.dispatcherNames() )
dispatchersMenu.setSelection( [ "Local" ] )
self.__dispatchersMenuSelectionChangedConnection = dispatchersMenu.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__dispatcherChanged ) )

self.__frame = GafferUI.Frame( borderStyle=GafferUI.Frame.BorderStyle.None, borderWidth=0 )
self.__dispatchButton = GafferUI.Button( "Dispatch" )
self.__dispatchClickedConnection = self.__dispatchButton.clickedSignal().connect( Gaffer.WeakMethod( self.__dispatchClicked ) )

self.__updateTitle()

_DispatcherWindow.__instances.append( weakref.ref( self ) )
self.__update()

def setVisible( self, visible ) :

Expand All @@ -116,9 +121,14 @@ def setNodesToDispatch( self, nodes ) :
self.__nodes = nodes
self.__updateTitle()

def __update( self ) :

self.__frame.setChild( GafferUI.NodeUI.create( self.__dispatcher ) )
self.__updateTitle()

def __updateTitle( self ) :

title = IECore.CamelCase.toSpaced( self.__dispatcher.getName() )
title = "Dispatching"
if len(self.__nodes) :
title += ": " + ", ".join( [ x.getName() for x in self.__nodes ] )

Expand All @@ -135,31 +145,10 @@ def __dispatch( self ) :
self.__dispatcher.dispatch( self.__nodes )
## \todo: update _executeUILastExecuted

__instances = [] # weak references to all instances - used by acquire()

## Returns the DispatcherWindow for the specified dispatcher, creating one if necessary.
@staticmethod
def acquire( dispatcher ) :

for w in _DispatcherWindow.__instances :

window = w()
if window is not None and window.dispatcher().isSame( dispatcher ) :
return window

return _DispatcherWindow( dispatcher )

__currentDispatcherName = "local"

@staticmethod
def currentDispatcher() :
def __dispatcherChanged( self, menu ) :

return Gaffer.Dispatcher.dispatcher( _DispatcherWindow.__currentDispatcherName )

@staticmethod
def setCurrentDispatcherName( name ) :

_DispatcherWindow.__currentDispatcherName = name
self.__dispatcher = Gaffer.Dispatcher.dispatcher( menu.getSelection()[0] )
self.__update()

##################################################################################
# PlugValueWidget for execution - this forms the header for the ExecutableNode ui.
Expand Down Expand Up @@ -265,20 +254,30 @@ def _execute( nodes ) :
script._executeUILastExecuted = []

with script.context() :
_DispatcherWindow.currentDispatcher().dispatch( nodes )
__dispatcherWindow( script ).dispatcher().dispatch( nodes )

script._executeUILastExecuted = [ weakref.ref( node ) for node in nodes ]

def _showDispatcherWindow( nodes ) :
__dispatcherWindowInstance = None
def __dispatcherWindow( script ) :

dispatcher = _DispatcherWindow.currentDispatcher()
global __dispatcherWindowInstance

window = _DispatcherWindow.acquire( dispatcher )
window.setNodesToDispatch( nodes )
if __dispatcherWindowInstance is not None and __dispatcherWindowInstance() :
window = __dispatcherWindowInstance()
else :
window = _DispatcherWindow()
__dispatcherWindowInstance = weakref.ref( window )

scriptWindow = GafferUI.ScriptWindow.acquire( nodes[0].scriptNode() )
scriptWindow = GafferUI.ScriptWindow.acquire( script )
scriptWindow.addChildWindow( window )

return window

def _showDispatcherWindow( nodes ) :

window = __dispatcherWindow( nodes[0].scriptNode() )
window.setNodesToDispatch( nodes )
window.setVisible( True )

def __selectedNodes( script ) :
Expand Down
2 changes: 1 addition & 1 deletion startup/gui/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __projectBookmark( forWidget, location ) :
else :
return os.getcwd()

localDispatcher = Gaffer.Dispatcher.dispatcher( "local" )
localDispatcher = Gaffer.Dispatcher.dispatcher( "Local" )
localDispatcher["jobName"].setValue( "${script:name}" )
localDispatcher["jobDirectory"].setValue( "${project:rootDirectory}/dispatcher" )

Expand Down

0 comments on commit 6499520

Please sign in to comment.