From c06ded171aae2d6cca2b88b500e49f175f54a426 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 19 Mar 2024 10:21:00 +0000 Subject: [PATCH] Shuffle : Improve ChannelPlug compatibility And add test demonstrating that expressions can still be made using the old names for plugs. This is necessary for an internal expression created by a node at Cinesite. --- Changes.md | 1 + python/GafferImageTest/ShuffleTest.py | 20 ++++++++++++++++++++ startup/GafferImage/shuffleCompatibility.py | 1 + 3 files changed, 22 insertions(+) diff --git a/Changes.md b/Changes.md index 71f2882f609..0fcbf7727fd 100644 --- a/Changes.md +++ b/Changes.md @@ -22,6 +22,7 @@ Fixes - Fixed loading of 2 channel images [^1]. - Fixed error message to include filename [^1]. - Expression : `setExpression()` now respects configs that provide backwards compatibility for old plug names. +- Shuffle : Fixed default name for plugs constructed via the legacy `ChannelPlug( out, in )` constructor [^1]. API --- diff --git a/python/GafferImageTest/ShuffleTest.py b/python/GafferImageTest/ShuffleTest.py index d68fd205de7..c769212d08b 100644 --- a/python/GafferImageTest/ShuffleTest.py +++ b/python/GafferImageTest/ShuffleTest.py @@ -412,5 +412,25 @@ def testIgnoreMissingSourceDoesnCreateChannels( self ) : shuffle["missingSourceMode"].setValue( shuffle.MissingSourceMode.Ignore ) self.assertEqual( shuffle["out"].channelNames(), IECore.StringVectorData( [ "R", "G", "B", "A" ] ) ) + def testLegacyChannelPlugConstructor( self ) : + + p = GafferImage.Shuffle.ChannelPlug( "R", "R" ) + self.assertEqual( p.getName(), "channel" ) + + def testCreateExpressionWithLegacyNames( self ) : + + script = Gaffer.ScriptNode() + script["shuffle"] = GafferImage.Shuffle() + script["shuffle"]["shuffles"].addChild( GafferImage.Shuffle.ChannelPlug( "R", "R" ) ) + script["shuffle"]["shuffles"].addChild( GafferImage.Shuffle.ChannelPlug( "G", "G" ) ) + + script["expression"] = Gaffer.Expression() + script["expression"].setExpression( + 'parent["shuffle"]["channels"]["channel"]["in"] = "X"; parent["shuffle"]["channels"]["channel1"]["in"] = "Y"' + ) + + self.assertEqual( script["shuffle"]["shuffles"][0]["source"].getValue(), "X" ) + self.assertEqual( script["shuffle"]["shuffles"][1]["source"].getValue(), "Y" ) + if __name__ == "__main__": unittest.main() diff --git a/startup/GafferImage/shuffleCompatibility.py b/startup/GafferImage/shuffleCompatibility.py index c3cdd213d83..77618da80f9 100644 --- a/startup/GafferImage/shuffleCompatibility.py +++ b/startup/GafferImage/shuffleCompatibility.py @@ -46,6 +46,7 @@ def __init__( self, *args, **kw ) : and isinstance( args[0], str ) and isinstance( args[1], str ) ) : Gaffer.ShufflePlug.__init__( self, args[1], args[0] ) + self.setName( "channel" ) else : Gaffer.ShufflePlug.__init__( self, *args, **kw )