Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deregister Light Editor columns #5891

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Fixes
API
---

- LightEditor : Added `deregisterColumn()` method for removing columns.
- Loop : Added `nextIterationContext()` method.
- AnnotationsGadget : Added `annotationText()` method.
- ParallelAlgoTest : Added `UIThreadCallHandler.receive()` method.
Expand Down
24 changes: 19 additions & 5 deletions python/GafferSceneUI/LightEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,18 @@ def scene( self ) :
@classmethod
def registerParameter( cls, rendererKey, parameter, section = None, columnName = None ) :

# We use `tuple` to store `ShaderNetwork.Parameter`, because
# the latter isn't hashable and we need to use it as a dict key.
if isinstance( parameter, str ) :
shader = ""
param = parameter
if "." in parameter :
shader, dot, param = parameter.partition( "." )
parameter = ( shader, param )
parameter = IECoreScene.ShaderNetwork.Parameter( shader, param )
else :
assert( isinstance( parameter, IECoreScene.ShaderNetwork.Parameter ) )
parameter = ( parameter.shader, parameter.name )

GafferSceneUI.LightEditor.registerColumn(
rendererKey,
parameter,
".".join( x for x in [ parameter.shader, parameter.name ] if x ),
lambda scene, editScope : _GafferSceneUI._LightEditorInspectorColumn(
GafferSceneUI.Private.ParameterInspector( scene, editScope, rendererKey, parameter ),
columnName if columnName is not None else ""
Expand Down Expand Up @@ -186,11 +183,28 @@ def registerAttribute( cls, rendererKey, attributeName, section = None ) :
@classmethod
def registerColumn( cls, rendererKey, columnKey, inspectorFunction, section = None ) :

assert( isinstance( columnKey, str ) )

sections = cls.__columnRegistry.setdefault( rendererKey, collections.OrderedDict() )
section = sections.setdefault( section, collections.OrderedDict() )

section[columnKey] = inspectorFunction

# Removes a column from the Light Editor.
# `rendererKey` should match the value the parameter or attribute was registered with.
# `columnKey` is the string value of the parameter or attribute name.
@classmethod
def deregisterColumn( cls, rendererKey, columnKey, section = None ) :

assert( isinstance( columnKey, str ) )

sections = cls.__columnRegistry.get( rendererKey, None )
if sections is not None and section in sections.keys() and columnKey in sections[section].keys() :
del sections[section][columnKey]

if len( sections[section] ) == 0 :
del sections[section]

def __repr__( self ) :

return "GafferSceneUI.LightEditor( scriptNode )"
Expand Down
84 changes: 84 additions & 0 deletions python/GafferSceneUITest/LightEditorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import imath

import IECore
import IECoreScene

import Gaffer
import GafferUI
Expand Down Expand Up @@ -778,6 +779,89 @@ def testShaderParameterEditScope( self ) :
self.assertEqual( attributes["light"].shaders()["add"].parameters["a"].value, imath.Color3f( 1.0, 0.5, 0.0 ) )
self.assertEqual( attributes["light"].shaders()["__shader"].parameters["exposure"].value, 2.0 )

def testDeregisterColumn( self ) :

GafferSceneUI.LightEditor.registerParameter( "light", "P" )
GafferSceneUI.LightEditor.registerParameter( "light", "P.X" )
GafferSceneUI.LightEditor.registerAttribute( "light", "A" )
GafferSceneUI.LightEditor.registerParameter( "light", IECoreScene.ShaderNetwork.Parameter( "P", "Y" ) )
GafferSceneUI.LightEditor.registerParameter( "light", IECoreScene.ShaderNetwork.Parameter( "", "Z" ) )
for columnName in [ "P", "P.X", "A", "P.Y" "Z" ] :
self.addCleanup( GafferSceneUI.LightEditor.deregisterColumn, "light", columnName )

script = Gaffer.ScriptNode()

editor = GafferSceneUI.LightEditor( script )
GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor )

widget = editor._LightEditor__pathListing

columnNames = [ c.headerData().value for c in widget.getColumns() ]
self.assertIn( "P", columnNames )
self.assertIn( "X", columnNames )
self.assertIn( "A", columnNames )
self.assertIn( "Y", columnNames )
self.assertIn( "Z", columnNames )

GafferSceneUI.LightEditor.deregisterColumn( "light", "P" )

editor._LightEditor__updateColumns()
GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor )

columnNames = [ c.headerData().value for c in widget.getColumns() ]
self.assertNotIn( "P", columnNames )
self.assertIn( "X", columnNames )
self.assertIn( "A", columnNames )
self.assertIn( "Y", columnNames )
self.assertIn( "Z", columnNames )

GafferSceneUI.LightEditor.deregisterColumn( "light", "P.X" )

editor._LightEditor__updateColumns()
GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor )

columnNames = [ c.headerData().value for c in widget.getColumns() ]
self.assertNotIn( "P", columnNames )
self.assertNotIn( "X", columnNames )
self.assertIn( "A", columnNames )
self.assertIn( "Y", columnNames )
self.assertIn( "Z", columnNames )

GafferSceneUI.LightEditor.deregisterColumn( "light", "A" )

editor._LightEditor__updateColumns()
GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor )

columnNames = [ c.headerData().value for c in widget.getColumns() ]
self.assertNotIn( "P", columnNames )
self.assertNotIn( "P.X", columnNames )
self.assertNotIn( "A", columnNames )
self.assertIn( "Y", columnNames )
self.assertIn( "Z", columnNames )

GafferSceneUI.LightEditor.deregisterColumn( "light", "P.Y" )

editor._LightEditor__updateColumns()
GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor )

columnNames = [ c.headerData().value for c in widget.getColumns() ]
self.assertNotIn( "P", columnNames )
self.assertNotIn( "P.X", columnNames )
self.assertNotIn( "A", columnNames )
self.assertNotIn( "Y", columnNames )
self.assertIn( "Z", columnNames )

GafferSceneUI.LightEditor.deregisterColumn( "light", "Z" )

editor._LightEditor__updateColumns()
GafferSceneUI.LightEditor._LightEditor__updateColumns.flush( editor )

columnNames = [ c.headerData().value for c in widget.getColumns() ]
self.assertNotIn( "P", columnNames )
self.assertNotIn( "P.X", columnNames )
self.assertNotIn( "A", columnNames )
self.assertNotIn( "Y", columnNames )
self.assertNotIn( "Z", columnNames )

if __name__ == "__main__" :
unittest.main()
Loading