Skip to content

Commit

Permalink
Merge pull request #1032 from andrewkaufman/dispatcherFramesUI
Browse files Browse the repository at this point in the history
FrameRange UI displays the value that will actually be dispatched.
  • Loading branch information
johnhaddon committed Oct 14, 2014
2 parents 938f4bf + 4d8ff3b commit 1d4d49b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 25 deletions.
119 changes: 95 additions & 24 deletions python/GafferUI/DispatcherUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,8 @@ def setNodesToDispatch( self, nodes ) :
self.__updateTitle()

def __update( self ) :

nodeUI = GafferUI.NodeUI.create( self.__dispatcher )

# force the framesMode widget to update so we start with
# the correct enabled state on the frameRange plug.
framesModeWidget = nodeUI.plugValueWidget( self.__dispatcher["framesMode"], lazy = False )
if framesModeWidget :
framesModeWidget.selectionMenu().setSelection( framesModeWidget.selectionMenu().getSelection() )

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

Expand Down Expand Up @@ -182,33 +175,38 @@ def __executeClicked( self, button ) :
_showDispatcherWindow( [ self.getPlug().node() ] )


#################################
# PlugValueWidget for framesMode
#################################
########################################
# PlugValueWidgets for frame range plugs
########################################

# Much of this is copied from EnumPlugValueWidget, but we're not deriving because we
# want the ability to add in menu items that don't correspond to plug values directly.
class __FramesModePlugValueWidget( GafferUI.PlugValueWidget ) :

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

self.__selectionMenu = GafferUI.MultiSelectionMenu( allowMultipleSelection = False, allowEmptySelection = False )
GafferUI.PlugValueWidget.__init__( self, self.__selectionMenu, plug, **kw )

self.__labelsAndValues = (
( "CurrentFrame", Gaffer.Dispatcher.FramesMode.CurrentFrame ),
( "FullRange", Gaffer.Dispatcher.FramesMode.FullRange ),
( "CustomRange", Gaffer.Dispatcher.FramesMode.CustomRange ),
( "PlaybackRange", Gaffer.Dispatcher.FramesMode.CustomRange ),
( "CustomRange", Gaffer.Dispatcher.FramesMode.CustomRange ),
)

for label, value in self.__labelsAndValues :
self.__selectionMenu.append( label )

self.__updateFrameRangeConnection = None
self.__visibilityChangedConnection = self.visibilityChangedSignal().connect( Gaffer.WeakMethod( self.__visibilityChanged ) )
self.__selectionChangedConnection = self.__selectionMenu.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__selectionChanged ) )

self._addPopupMenu( self.__selectionMenu )

# save the metadata in case the frameRange plug is set prior to enabling CustomRange mode
self.__customFrameRangeChanged( self.getPlug().node()["frameRange"] )

self._updateFromPlug()

def selectionMenu( self ) :
Expand All @@ -231,6 +229,14 @@ def _updateFromPlug( self ) :
self.__selectionMenu.setSelection( labelAndValue[0] )
break

def __frameRangeWidget( self ) :

nodeUI = self.ancestor( GafferUI.NodeUI )
if nodeUI :
return nodeUI.plugValueWidget( self.getPlug().node()["frameRange"], lazy = False )

return None

def __selectionChanged( self, selectionMenu ) :

label = selectionMenu.getSelection()[0]
Expand All @@ -239,19 +245,83 @@ def __selectionChanged( self, selectionMenu ) :
with Gaffer.BlockedConnection( self._plugConnections() ) :
self.getPlug().setValue( value )

nodeUI = self.ancestor( GafferUI.NodeUI )
if nodeUI :
frameRangeWidget = nodeUI.plugValueWidget( self.getPlug().node()["frameRange"], lazy = False )
frameRangeWidget = self.__frameRangeWidget()
if frameRangeWidget :
## \todo: This should be managed by activator metadata once we've ported
# that functionality out of RenderManShaderUI and into PlugLayout.
frameRangeWidget.setReadOnly( label in [ "CurrentFrame", "FullRange", "PlaybackRange" ] )

self.__updateFrameRangeConnection = None

window = self.ancestor( GafferUI.ScriptWindow )
if not window :
return

script = window.scriptNode()
context = script.context()

if label == "CurrentFrame" :
self.__updateFrameRangeConnection = context.changedSignal().connect( Gaffer.WeakMethod( self.__contextChanged ) )
self.__contextChanged( context, "frame" )
elif label == "FullRange" :
self.__updateFrameRangeConnection = script.plugDirtiedSignal().connect( Gaffer.WeakMethod( self.__scriptPlugDirtied ) )
self.__scriptPlugDirtied( script["frameRange"] )
elif label == "PlaybackRange" :
playback = GafferUI.Playback.acquire( context )
self.__updateFrameRangeConnection = playback.frameRangeChangedSignal().connect( Gaffer.WeakMethod( self.__playbackFrameRangeChanged ) )
self.__playbackFrameRangeChanged( playback )
else :
frameRange = Gaffer.Metadata.plugValue( self.getPlug(), "dispatcherWindow:frameRange", inherit=False )
if frameRange is not None :
self.getPlug().node()["frameRange"].setValue( frameRange )
self.__updateFrameRangeConnection = self.getPlug().node().plugDirtiedSignal().connect( Gaffer.WeakMethod( self.__customFrameRangeChanged ) )

def __visibilityChanged( self, widget ) :

if self.visible() :
self.__selectionChanged( self.__selectionMenu )
else :
self.__updateFrameRangeConnection = None

def __contextChanged( self, context, key ) :

if key == "frame" :
frameRangeWidget = self.__frameRangeWidget()
if frameRangeWidget :
## \todo: This should be managed by activator metadata once we've ported
# that functionality out of RenderManShaderUI and into PlugLayout.
frameRangeWidget.setReadOnly( value != Gaffer.Dispatcher.FramesMode.CustomRange )
frameRangeWidget.textWidget().setText( str(int(context.getFrame())) )

def __playbackFrameRangeChanged( self, playback ) :

frameRange = playback.getFrameRange()
frameRange = str(IECore.frameListFromList( range(frameRange[0], frameRange[1]+1) ))
self.getPlug().node()["frameRange"].setValue( frameRange )

def __scriptPlugDirtied( self, plug ) :

script = plug.ancestor( Gaffer.ScriptNode )
if script and plug.isSame( script["frameRange"] ) or plug.parent().isSame( script["frameRange"] ) :
frameRangeWidget = self.__frameRangeWidget()
if frameRangeWidget :
frameRangeWidget.textWidget().setText( str(IECore.FrameRange( script["frameRange"]["start"].getValue(), script["frameRange"]["end"].getValue() )) )

def __customFrameRangeChanged( self, plug ) :

if plug.isSame( self.getPlug().node()["frameRange"] ) :
with self.getContext() :
Gaffer.Metadata.registerPlugValue( self.getPlug(), "dispatcherWindow:frameRange", plug.getValue() )

class __FrameRangePlugValueWidget( GafferUI.StringPlugValueWidget ) :

def _updateFromPlug( self ) :

with self.getContext() :
framesMode = self.getPlug().node()["framesMode"].getValue()

# we need to disable the normal update in CurrentFrame and FullRange modes
if framesMode == Gaffer.Dispatcher.FramesMode.CustomRange :
GafferUI.StringPlugValueWidget._updateFromPlug( self )

if label == "PlaybackRange" :
window = self.ancestor( GafferUI.ScriptWindow )
frameRange = GafferUI.Playback.acquire( window.scriptNode().context() ).getFrameRange()
frameRange = str(IECore.frameListFromList( range(frameRange[0], frameRange[1]+1) ))
self.getPlug().node()["frameRange"].setValue( frameRange )
self.textWidget().setEditable( self._editable() )

##########################################################################
# Metadata, PlugValueWidgets and Nodules
Expand Down Expand Up @@ -283,6 +353,7 @@ def __selectionChanged( self, selectionMenu ) :

GafferUI.PlugValueWidget.registerCreator( Gaffer.Dispatcher, "user", None )
GafferUI.PlugValueWidget.registerCreator( Gaffer.Dispatcher, "framesMode", __FramesModePlugValueWidget )
GafferUI.PlugValueWidget.registerCreator( Gaffer.Dispatcher, "frameRange", __FrameRangePlugValueWidget )
GafferUI.PlugValueWidget.registerCreator( Gaffer.ExecutableNode, "requirement", __RequirementPlugValueWidget )
GafferUI.PlugValueWidget.registerCreator( Gaffer.ExecutableNode, "dispatcher", GafferUI.CompoundPlugValueWidget, collapsed = None )

Expand Down
2 changes: 1 addition & 1 deletion src/Gaffer/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Dispatcher::Dispatcher( const std::string &name )
storeIndexOfNextChild( g_firstPlugIndex );

addChild( new IntPlug( "framesMode", Plug::In, CurrentFrame, CurrentFrame ) );
addChild( new StringPlug( "frameRange", Plug::In, "" ) );
addChild( new StringPlug( "frameRange", Plug::In, "1-100x10" ) );
addChild( new StringPlug( "jobName", Plug::In, "" ) );
addChild( new StringPlug( "jobsDirectory", Plug::In, "" ) );
}
Expand Down

0 comments on commit 1d4d49b

Please sign in to comment.