Skip to content

Commit

Permalink
LightEditor : Use inspectionContext
Browse files Browse the repository at this point in the history
Replace contexts with hard-coded references to `scene:path` with calls to the path's `inspectionContext()`.
  • Loading branch information
murraystevenson authored and johnhaddon committed Aug 7, 2024
1 parent 9ff4248 commit dbf8694
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
73 changes: 37 additions & 36 deletions python/GafferSceneUI/LightEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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()
Expand All @@ -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 :
Expand All @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions python/GafferSceneUITest/LightEditorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down Expand Up @@ -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.
Expand All @@ -712,6 +719,8 @@ def testToggleContext( self ) :
True # quickBoolean
)

del widget, editor

def testShaderParameterEditScope( self ) :

GafferSceneUI.LightEditor.registerShaderParameter( "light", "add.a" )
Expand Down

0 comments on commit dbf8694

Please sign in to comment.