Skip to content

Commit

Permalink
Merge pull request #6032 from johnhaddon/connectUnscoped
Browse files Browse the repository at this point in the history
SignalBinding : Default `scoped = False` for `connect[Front]()`
  • Loading branch information
johnhaddon authored Sep 9, 2024
2 parents c8d834d + 08b5eb8 commit bfce40d
Show file tree
Hide file tree
Showing 211 changed files with 803 additions and 842 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Breaking Changes
- LightTool : Removed `selection()` and `selectionChangedSignal()`.
- ArnoldRender, CyclesRender, DelightRender, OpenGLRender : Removed. Use the generic Render node instead.
- Render : Removed protected constructor for creating renderer-specific derived classes.
- Signal : The `connect()` and `connectFront()` methods now default to `scoped = False`. If a scoped connection is required, pass `scoped = True`.

Build
-----
Expand Down
2 changes: 1 addition & 1 deletion apps/execute/execute-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _run( self, args ) :

with context :
for node in nodes :
node.errorSignal().connect( Gaffer.WeakMethod( self.__error ), scoped = False )
node.errorSignal().connect( Gaffer.WeakMethod( self.__error ) )
try :
node["task"].executeSequence( frames )
except Exception as exception :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Copy this code to a new a `customVariables.py` file in `~/gaffer/startup/gui`:
Gaffer.MetadataAlgo.setReadOnly( variables["projectResources"]["name"], True )
application.root()["scripts"].childAddedSignal().connect( __scriptAdded, scoped = False )
application.root()["scripts"].childAddedSignal().connect( __scriptAdded )
```

Let's break down what's going on here.
Expand Down Expand Up @@ -125,7 +125,7 @@ We wrap up the config by adding our function to an event signal that fires when
.. code-block:: python
:lineno-start: 17
application.root()["scripts"].childAddedSignal().connect( __scriptAdded, scoped = False )
application.root()["scripts"].childAddedSignal().connect( __scriptAdded )
```

Notice the use of the `application` variable. This is a special variable that refers to the startup config's parent application.
Expand Down
10 changes: 5 additions & 5 deletions include/GafferBindings/SignalBinding.inl
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ void visit_each( Visitor &visitor, const Slot<Signal, Caller> &slot, int )
}
}

GAFFERBINDINGS_API boost::python::object pythonConnection( const Gaffer::Signals::Connection &connection, const boost::python::object &scoped );
GAFFERBINDINGS_API boost::python::object pythonConnection( const Gaffer::Signals::Connection &connection, bool scoped );

template<typename Signal, typename SlotCaller>
boost::python::object connect( Signal &s, boost::python::object &slot, const boost::python::object &scoped )
boost::python::object connect( Signal &s, boost::python::object &slot, bool scoped )
{
return pythonConnection( s.connect( Slot<Signal, SlotCaller>( slot ) ), scoped );
}

template<typename Signal, typename SlotCaller>
boost::python::object connectFront( Signal &s, boost::python::object &slot, const boost::python::object &scoped )
boost::python::object connectFront( Signal &s, boost::python::object &slot, bool scoped )
{
return pythonConnection( s.connectFront( Slot<Signal, SlotCaller>( slot ) ), scoped );
}
Expand Down Expand Up @@ -185,8 +185,8 @@ template<typename Signal, typename SignalCaller, typename SlotCaller>
SignalClass<Signal, SignalCaller, SlotCaller>::SignalClass( const char *className, const char *docString )
: boost::python::class_<Signal, boost::noncopyable>( className, docString )
{
this->def( "connect", &Detail::connect<Signal, SlotCaller>, ( boost::python::arg( "slot" ), boost::python::arg( "scoped" ) = boost::python::object() ) );
this->def( "connectFront", &Detail::connectFront<Signal, SlotCaller>, (boost::python::arg( "slot" ), boost::python::arg( "scoped" ) = boost::python::object() ) );
this->def( "connect", &Detail::connect<Signal, SlotCaller>, ( boost::python::arg( "slot" ), boost::python::arg( "scoped" ) = false ) );
this->def( "connectFront", &Detail::connectFront<Signal, SlotCaller>, (boost::python::arg( "slot" ), boost::python::arg( "scoped" ) = false ) );
this->def( "disconnectAllSlots", &Signal::disconnectAllSlots );
this->def( "numSlots", &Signal::numSlots );
this->def( "empty", &Signal::empty );
Expand Down
6 changes: 3 additions & 3 deletions python/GafferCortexUI/ClassVectorParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _headerWidget( self ) :
with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal ) as result :

collapseButton = GafferUI.Button( image = "collapsibleArrowRight.png", hasFrame=False )
collapseButton.clickedSignal().connect( Gaffer.WeakMethod( self.__collapseButtonClicked ), scoped = False )
collapseButton.clickedSignal().connect( Gaffer.WeakMethod( self.__collapseButtonClicked ) )

GafferUI.Spacer( imath.V2i( 2 ) )

Expand Down Expand Up @@ -293,8 +293,8 @@ def _headerWidget( self ) :
self.__parameterHandler.childParameterHandler( self.__parameterHandler.parameter()["label"] ),
),
)
self.__label.buttonPressSignal().connect( Gaffer.WeakMethod( self.__labelButtonPress ), scoped = False )
self.getPlug().node().plugSetSignal().connect( Gaffer.WeakMethod( self.__plugSet ), scoped = False )
self.__label.buttonPressSignal().connect( Gaffer.WeakMethod( self.__labelButtonPress ) )
self.getPlug().node().plugSetSignal().connect( Gaffer.WeakMethod( self.__plugSet ) )

# parameters after the label
for parameter in headerParameters :
Expand Down
6 changes: 3 additions & 3 deletions python/GafferCortexUI/CompoundVectorParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def _headerWidget( self ) :
sizeEditable = sizeEditable,
)

self.__vectorDataWidget.editSignal().connect( Gaffer.WeakMethod( self.__edit ), scoped = False )
self.__vectorDataWidget.dataChangedSignal().connect( Gaffer.WeakMethod( self.__dataChanged ), scoped = False )
self.__vectorDataWidget.editSignal().connect( Gaffer.WeakMethod( self.__edit ) )
self.__vectorDataWidget.dataChangedSignal().connect( Gaffer.WeakMethod( self.__dataChanged ) )

self._requestUpdateFromValues()

Expand Down Expand Up @@ -302,4 +302,4 @@ def __parameterPopupMenu( menuDefinition, parameterValueWidget ) :
},
)

GafferCortexUI.ParameterValueWidget.popupMenuSignal().connect( __parameterPopupMenu, scoped = False )
GafferCortexUI.ParameterValueWidget.popupMenuSignal().connect( __parameterPopupMenu )
2 changes: 1 addition & 1 deletion python/GafferCortexUI/OpPathPreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__( self, path ) :
# we'll replace this with the op in _deferredUpdate()
GafferUI.Spacer( imath.V2i( 1 ) )
button = GafferUI.Button( "Launch" )
button.clickedSignal().connect( Gaffer.WeakMethod( self.__executeClicked ), scoped = False )
button.clickedSignal().connect( Gaffer.WeakMethod( self.__executeClicked ) )

self._updateFromPath()

Expand Down
2 changes: 1 addition & 1 deletion python/GafferCortexUI/ParameterPresets.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,4 @@ def __parameterPopupMenu( menuDefinition, parameterValueWidget ) :
menuDefinition.append( "/Load Preset...", { "command" : IECore.curry( __loadPreset, parameterHandler ), "active" : editable } )
menuDefinition.append( "/Delete Presets...", { "command" : IECore.curry( __deletePresets, parameterHandler ) } )

GafferCortexUI.ParameterValueWidget.popupMenuSignal().connect( __parameterPopupMenu, scoped = False )
GafferCortexUI.ParameterValueWidget.popupMenuSignal().connect( __parameterPopupMenu )
2 changes: 1 addition & 1 deletion python/GafferCortexUI/ParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __plugPopupMenu( menuDefinition, plugValueWidget ) :

ParameterValueWidget.popupMenuSignal()( menuDefinition, parameterValueWidget )

GafferUI.PlugValueWidget.popupMenuSignal().connect( __plugPopupMenu, scoped = False )
GafferUI.PlugValueWidget.popupMenuSignal().connect( __plugPopupMenu )

# add menu items for presets

Expand Down
2 changes: 1 addition & 1 deletion python/GafferCortexUI/ParameterisedHolderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__( self, node ) :

self.__node = node
self.__window = None
self.clickedSignal().connect( Gaffer.WeakMethod( self.__clicked ), scoped = False )
self.clickedSignal().connect( Gaffer.WeakMethod( self.__clicked ) )

def getToolTip( self ) :

Expand Down
2 changes: 1 addition & 1 deletion python/GafferCyclesUI/CyclesOptionsUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ def __init__( self, plugs, **kw ) :

GafferUI.PresetsPlugValueWidget.__init__( self, plugs, **kw )

self.getPlug().node().plugSetSignal().connect( Gaffer.WeakMethod( self.__plugSet ), scoped = False )
self.getPlug().node().plugSetSignal().connect( Gaffer.WeakMethod( self.__plugSet ) )

def __plugSet( self, plug ) :

Expand Down
2 changes: 1 addition & 1 deletion python/GafferDispatch/LocalDispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__( self, batch, dispatcher ) :

self.__messageHandler = _MessageHandler()
self.__messagesChangedSignal = Gaffer.Signal1()
self.__messageHandler.messagesChangedSignal().connect( Gaffer.WeakMethod( self.__messagesChanged, fallbackResult = None ), scoped = False )
self.__messageHandler.messagesChangedSignal().connect( Gaffer.WeakMethod( self.__messagesChanged, fallbackResult = None ) )

self.__initBatchWalk( batch )

Expand Down
8 changes: 4 additions & 4 deletions python/GafferDispatchTest/DispatcherTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ def testPostDispatchSignalSuccess( self ) :
self.assertEqual( postDispatchSlot[0], ( script["dispatcher"], True ) )

preDispatchConnection = GafferDispatch.Dispatcher.preDispatchSignal().connect(
lambda dispatcher : True, scoped = False
lambda dispatcher : True
)

script["dispatcher"]["task"].execute()
Expand All @@ -2300,17 +2300,17 @@ def testDispatchSignalShutdownCrash( self ) :

subprocess.check_call( [
Gaffer.executablePath(), "env", "python", "-c",
"""import GafferDispatch; GafferDispatch.Dispatcher.preDispatchSignal().connect( lambda d : True, scoped = False )"""
"""import GafferDispatch; GafferDispatch.Dispatcher.preDispatchSignal().connect( lambda d : True )"""
] )

subprocess.check_call( [
Gaffer.executablePath(), "env", "python", "-c",
"""import GafferDispatch; GafferDispatch.Dispatcher.dispatchSignal().connect( lambda d : None, scoped = False )"""
"""import GafferDispatch; GafferDispatch.Dispatcher.dispatchSignal().connect( lambda d : None )"""
] )

subprocess.check_call( [
Gaffer.executablePath(), "env", "python", "-c",
"""import GafferDispatch; GafferDispatch.Dispatcher.postDispatchSignal().connect( lambda d, s : None, scoped = False )"""
"""import GafferDispatch; GafferDispatch.Dispatcher.postDispatchSignal().connect( lambda d, s : None )"""
] )

def testAccessTaskNodeInSetupPlugs( self ) :
Expand Down
4 changes: 2 additions & 2 deletions python/GafferDispatchTest/LocalDispatcherTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,9 @@ def statusChanged( job ) :

def jobAdded( job ) :

job.statusChangedSignal().connect( statusChanged, scoped = False )
job.statusChangedSignal().connect( statusChanged )

script["dispatcher"].jobPool().jobAddedSignal().connect( jobAdded, scoped = False )
script["dispatcher"].jobPool().jobAddedSignal().connect( jobAdded )

# Test foreground dispatch

Expand Down
6 changes: 3 additions & 3 deletions python/GafferDispatchUI/DispatchDialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__( self, tasks, dispatchers, nodesToShow, postDispatchBehaviour=PostD
self.__dispatchersMenu = GafferUI.MultiSelectionMenu( allowMultipleSelection = False, allowEmptySelection = False )
self.__dispatchersMenu.append( [ x.getName() for x in self.__dispatchers ] )
self.__dispatchersMenu.setSelection( [ self.__dispatchers[0].getName() ] )
self.__dispatchersMenu.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__dispatcherChanged ), scoped = False )
self.__dispatchersMenu.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__dispatcherChanged ) )
dispatcherMenuColumn.setVisible( len(self.__dispatchers) > 1 )

self.__dispatcherFrame = GafferUI.Frame( borderStyle=GafferUI.Frame.BorderStyle.None_, borderWidth=0 )
Expand All @@ -125,10 +125,10 @@ def __init__( self, tasks, dispatchers, nodesToShow, postDispatchBehaviour=PostD
self.__messageWidget = GafferUI.MessageWidget( toolbars = True )
# connect to the collapsible state change so we can increase the window
# size when the details pane is first shown.
self.__messageCollapsibleConnection = self.__messageCollapsible.stateChangedSignal().connect( Gaffer.WeakMethod( self.__messageCollapsibleChanged ), scoped = False )
self.__messageCollapsibleConnection = self.__messageCollapsible.stateChangedSignal().connect( Gaffer.WeakMethod( self.__messageCollapsibleChanged ) )

self.__backButton = self._addButton( "Back" )
self.__backButton.clickedSignal().connectFront( Gaffer.WeakMethod( self.__initiateSettings ), scoped = False )
self.__backButton.clickedSignal().connectFront( Gaffer.WeakMethod( self.__initiateSettings ) )

self.__primaryButton = self._addButton( "Dispatch" )

Expand Down
4 changes: 2 additions & 2 deletions python/GafferDispatchUI/DispatcherUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def __init__( self, node, **kw ) :
GafferUI.Button.__init__( self, "Dispatch", **kw )

self.__node = node
self.clickedSignal().connect( Gaffer.WeakMethod( self.__clicked ), scoped = False )
self.clickedSignal().connect( Gaffer.WeakMethod( self.__clicked ) )

def __clicked( self, button ) :

Expand Down Expand Up @@ -283,7 +283,7 @@ def __init__( self, node, **kw ) :
# Dummy `gaffer://...` URL is sufficient to trigger `linkActivatedSignal`, which is all we need.
f'<a href="gaffer://createDispatcher"><font color={textColor}>Create a dispatcher</font></a> <font color={textColor}>to execute this node</font>',
)
label.linkActivatedSignal().connect( Gaffer.WeakMethod( self.__linkActivated ), scoped = False )
label.linkActivatedSignal().connect( Gaffer.WeakMethod( self.__linkActivated ) )

GafferUI.Spacer( size = imath.V2i( 0 ), parenting = { "expand" : True } )

Expand Down
14 changes: 7 additions & 7 deletions python/GafferDispatchUI/LocalJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ def __init__( self, scriptNode, **kw ) :
selectionMode = GafferUI.PathListingWidget.SelectionMode.Rows,
)
self.__jobListingWidget._qtWidget().header().setSortIndicator( 1, QtCore.Qt.AscendingOrder )
self.__jobListingWidget.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__jobSelectionChanged ), scoped = False )
self.__jobListingWidget.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__jobSelectionChanged ) )

with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal, spacing=5 ) :
GafferUI.Spacer( imath.V2i( 0 ), parenting = { "expand" : True } )
self.__killButton = GafferUI.Button( "Kill Selected Jobs" )
self.__killButton.clickedSignal().connect( Gaffer.WeakMethod( self.__killClicked ), scoped = False )
self.__killButton.clickedSignal().connect( Gaffer.WeakMethod( self.__killClicked ) )
self.__removeButton = GafferUI.Button( "Remove Selected Jobs" )
self.__removeButton.clickedSignal().connect( Gaffer.WeakMethod( self.__removeClicked ), scoped = False )
self.__removeButton.clickedSignal().connect( Gaffer.WeakMethod( self.__removeClicked ) )

with GafferUI.TabbedContainer() :

Expand All @@ -255,14 +255,14 @@ def __init__( self, scriptNode, **kw ) :

# Connecting to the JobPool and Job signals allows us to update our PathListingWidget
# immediately when jobs are added and removed or their status changes.
jobPool.jobAddedSignal().connect( Gaffer.WeakMethod( self.__jobAdded ), scoped = False )
jobPool.jobRemovedSignal().connect( Gaffer.WeakMethod( self.__jobRemoved ), scoped = False )
jobPool.jobAddedSignal().connect( Gaffer.WeakMethod( self.__jobAdded ) )
jobPool.jobRemovedSignal().connect( Gaffer.WeakMethod( self.__jobRemoved ) )

# But we also want to perform periodic updates to sample CPU/memory statistics, which
# we do using this timer.
self.__statisticsTimer = QtCore.QTimer()
self.__statisticsTimer.timeout.connect( Gaffer.WeakMethod( self.__statisticsTimeout ) )
self.visibilityChangedSignal().connect( Gaffer.WeakMethod( self.__visibilityChanged ), scoped = False )
self.visibilityChangedSignal().connect( Gaffer.WeakMethod( self.__visibilityChanged ) )

self.__updateButtons()

Expand All @@ -280,7 +280,7 @@ def __visibilityChanged( self, widget ) :
def __jobAdded( self, job ) :

assert( threading.current_thread() is threading.main_thread() )
job.statusChangedSignal().connect( Gaffer.WeakMethod( self.__jobStatusChanged ), scoped = False )
job.statusChangedSignal().connect( Gaffer.WeakMethod( self.__jobStatusChanged ) )
self.__jobListingWidget.getPath()._emitPathChanged()

def __jobRemoved( self, job ) :
Expand Down
4 changes: 2 additions & 2 deletions python/GafferDispatchUI/PythonCommandUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ def __init__( self, plug, **kw ) :
self.__codeWidget.setHighlighter( GafferUI.CodeWidget.PythonHighlighter() )
self.__codeWidget.setCommentPrefix( "#" )

self.__codeWidget.editingFinishedSignal().connect( Gaffer.WeakMethod( self.__setPlugValue ), scoped = False )
self.__codeWidget.editingFinishedSignal().connect( Gaffer.WeakMethod( self.__setPlugValue ) )

self._addPopupMenu( self.__codeWidget )

node = self.__pythonCommandNode()
if node is not None :
node.plugDirtiedSignal().connect( Gaffer.WeakMethod( self.__pythonCommandPlugDirtied ), scoped = False )
node.plugDirtiedSignal().connect( Gaffer.WeakMethod( self.__pythonCommandPlugDirtied ) )
self.__updateCompleter()

def _updateFromValues( self, values, exception ) :
Expand Down
2 changes: 1 addition & 1 deletion python/GafferDispatchUI/WedgeUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__( self, previewWidget, node, **kw ) :
previewWidget.setToolTip( "The values generated by the wedge" )

self.__node = node
node.plugDirtiedSignal().connect( Gaffer.WeakMethod( self.__plugDirtied ), scoped = False )
node.plugDirtiedSignal().connect( Gaffer.WeakMethod( self.__plugDirtied ) )

def node( self ) :

Expand Down
4 changes: 2 additions & 2 deletions python/GafferImageTest/DisplayTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ def testSignalShutdownCrash( self ) :

subprocess.check_call( [
Gaffer.executablePath(), "env", "python", "-c",
"""import GafferImage; GafferImage.Display.driverCreatedSignal().connect( lambda d, p : None, scoped = False )"""
"""import GafferImage; GafferImage.Display.driverCreatedSignal().connect( lambda d, p : None )"""
] )

subprocess.check_call( [
Gaffer.executablePath(), "env", "python", "-c",
"""import GafferImage; GafferImage.Display.imageReceivedSignal().connect( lambda p : None, scoped = False )"""
"""import GafferImage; GafferImage.Display.imageReceivedSignal().connect( lambda p : None )"""
] )

def __testTransferImage( self, fileName ) :
Expand Down
Loading

0 comments on commit bfce40d

Please sign in to comment.