From 876e5d92e51e62864c183736d66ef9051efc28e9 Mon Sep 17 00:00:00 2001 From: Murray Stevenson <50844517+murraystevenson@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:14:17 -0700 Subject: [PATCH] LightEditor : Use inspectionContext Replace contexts with hard-coded references to `scene:path` with calls to the path's `inspectionContext()`. --- python/GafferSceneUI/LightEditor.py | 73 +++++++++++---------- python/GafferSceneUITest/LightEditorTest.py | 9 +++ 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/python/GafferSceneUI/LightEditor.py b/python/GafferSceneUI/LightEditor.py index fa48906714..4d23e91b53 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 Gaffer.Context( 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 Gaffer.Context( 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 Gaffer.Context( 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 Gaffer.Context( 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" )