diff --git a/python/GafferSceneUI/LightEditor.py b/python/GafferSceneUI/LightEditor.py index fa48906714..78b2710775 100644 --- a/python/GafferSceneUI/LightEditor.py +++ b/python/GafferSceneUI/LightEditor.py @@ -333,19 +333,17 @@ def __editSelectedCells( self, pathListing, quickBoolean = True ) : inspectors = {} inspections = [] - with Gaffer.Context( self.context() ) as context : - - for selection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) : - if not isinstance( column, GafferSceneUI.Private.InspectorColumn ) : - continue - for pathString in selection.paths() : - path = GafferScene.ScenePlug.stringToPath( pathString ) - - context["scene:path"] = path + path = pathListing.getPath().copy() + for selection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) : + if not isinstance( column, GafferSceneUI.Private.InspectorColumn ) : + continue + for pathString in selection.paths() : + path.setFromString( pathString ) + with path.inspectionContext() : inspection = column.inspector().inspect() if inspection is not None : - inspectors.setdefault( column.inspector(), {} )[path] = inspection + inspectors.setdefault( column.inspector(), {} )[pathString] = inspection inspections.append( inspection ) if len( inspectors ) == 0 : @@ -439,12 +437,13 @@ def __disablableInspectionTweaks( self, pathListing ) : tweaks = [] - with Gaffer.Context( self.context() ) as context : - for columnSelection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) : - if not isinstance( column, GafferSceneUI.Private.InspectorColumn ) : - continue - for path in columnSelection.paths() : - context["scene:path"] = GafferScene.ScenePlug.stringToPath( path ) + path = pathListing.getPath().copy() + for columnSelection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) : + if not isinstance( column, GafferSceneUI.Private.InspectorColumn ) : + continue + for pathString in columnSelection.paths() : + path.setFromString( pathString ) + with path.inspectionContext() : inspection = column.inspector().inspect() if inspection is not None and inspection.editable() : source = inspection.source() @@ -459,7 +458,7 @@ def __disablableInspectionTweaks( self, pathListing ) : ) and ( editScope is None or editScope.node().isAncestorOf( source ) ) ) : - tweaks.append( ( path, column.inspector() ) ) + tweaks.append( ( pathString, column.inspector() ) ) else : return [] else : @@ -471,31 +470,33 @@ def __disableEdits( self, pathListing ) : edits = self.__disablableInspectionTweaks( pathListing ) - with Gaffer.UndoScope( self.scriptNode() ), Gaffer.Context( self.context() ) as context : - for path, inspector in edits : - context["scene:path"] = GafferScene.ScenePlug.stringToPath( path ) - - inspection = inspector.inspect() - if inspection is not None and inspection.editable() : - source = inspection.source() + path = pathListing.getPath().copy() + with Gaffer.UndoScope( self.scriptNode() ) : + for pathString, inspector in edits : + path.setFromString( pathString ) + with path.inspectionContext() : + inspection = inspector.inspect() + if inspection is not None and inspection.editable() : + source = inspection.source() - if isinstance( source, ( Gaffer.TweakPlug, Gaffer.NameValuePlug ) ) : - source["enabled"].setValue( False ) - elif isinstance( inspector, GafferSceneUI.Private.SetMembershipInspector ) : - inspector.editSetMembership( inspection, path, GafferScene.EditScopeAlgo.SetMembership.Unchanged ) + if isinstance( source, ( Gaffer.TweakPlug, Gaffer.NameValuePlug ) ) : + source["enabled"].setValue( False ) + elif isinstance( inspector, GafferSceneUI.Private.SetMembershipInspector ) : + inspector.editSetMembership( inspection, pathString, GafferScene.EditScopeAlgo.SetMembership.Unchanged ) def __removableAttributeInspections( self, pathListing ) : inspections = [] - with Gaffer.Context( self.context() ) as context : - for columnSelection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) : - if not isinstance( column, GafferSceneUI.Private.InspectorColumn ) : - continue - elif not columnSelection.isEmpty() and type( column.inspector() ) != GafferSceneUI.Private.AttributeInspector : - return [] - for path in columnSelection.paths() : - context["scene:path"] = GafferScene.ScenePlug.stringToPath( path ) + path = pathListing.getPath().copy() + for columnSelection, column in zip( pathListing.getSelection(), pathListing.getColumns() ) : + if not isinstance( column, GafferSceneUI.Private.InspectorColumn ) : + continue + elif not columnSelection.isEmpty() and type( column.inspector() ) != GafferSceneUI.Private.AttributeInspector : + return [] + for pathString in columnSelection.paths() : + path.setFromString( pathString ) + with path.inspectionContext() : inspection = column.inspector().inspect() if inspection is not None and inspection.editable() : source = inspection.source() diff --git a/python/GafferSceneUITest/LightEditorTest.py b/python/GafferSceneUITest/LightEditorTest.py index 18938f369d..a875a73961 100644 --- a/python/GafferSceneUITest/LightEditorTest.py +++ b/python/GafferSceneUITest/LightEditorTest.py @@ -652,6 +652,10 @@ def testLightMuteAttribute( toggleCount, toggleLocation, newStates ) : editor._LightEditor__updateColumns() GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor ) + editor.setNodeSet( Gaffer.StandardSet( [ script["editScope"] ] ) ) + editor._LightEditor__setPathListingPath() + GafferSceneUI.LightEditor._LightEditor__setPathListingPath.flush( editor ) + widget = editor._LightEditor__pathListing self.setLightEditorMuteSelection( widget, togglePaths ) @@ -704,6 +708,9 @@ def testToggleContext( self ) : widget = editor._LightEditor__pathListing editor.setNodeSet( Gaffer.StandardSet( [ script["custAttr"] ] ) ) + editor._LightEditor__setPathListingPath() + GafferSceneUI.LightEditor._LightEditor__setPathListingPath.flush( editor ) + self.setLightEditorMuteSelection( widget, ["/group/light"] ) # This will raise an exception if the context is not scoped correctly. @@ -712,6 +719,8 @@ def testToggleContext( self ) : True # quickBoolean ) + del widget, editor + def testShaderParameterEditScope( self ) : GafferSceneUI.LightEditor.registerShaderParameter( "light", "add.a" )