diff --git a/Changes.md b/Changes.md index e435d838569..d89f31dac8c 100644 --- a/Changes.md +++ b/Changes.md @@ -7,6 +7,7 @@ Improvements - MeshSplit : Added `ignoreMissing` plug. - Cycles : Added render-time translation of `UsdPreviewSurface` normal maps, these require a FaceVarying `uv` primitive variable to render correctly. - Parent, Duplicate, Instancer, Group, MergeScenes : Improved performance when handling large numbers of sets. +- Viewer : Added a search field to the channels menu. - RampPlug : Added ability to load `.gfr` files saved from Gaffer 1.8. Fixes diff --git a/python/GafferImageUI/ImageViewUI.py b/python/GafferImageUI/ImageViewUI.py index 131ef91a495..0615e9e0666 100644 --- a/python/GafferImageUI/ImageViewUI.py +++ b/python/GafferImageUI/ImageViewUI.py @@ -306,6 +306,7 @@ def _menuDefinition( self ) : "command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), value = denoiseValue ), "shortCut" : "D", "active" : denoiseValue is not None and denoiseValue != currentValue, + "searchable" : False, } ) @@ -318,6 +319,7 @@ def _menuDefinition( self ) : "command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), value = previousValue ), "shortCut" : "PgUp", "active" : previousValue is not None and previousValue != currentValue, + "searchable" : False, } ) @@ -328,6 +330,7 @@ def _menuDefinition( self ) : "command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), value = nextValue ), "shortCut" : "PgDown", "active" : nextValue is not None and nextValue != currentValue, + "searchable" : False, } ) @@ -338,6 +341,7 @@ def _menuDefinition( self ) : "command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), value = firstValue ), "shortCut" : "Ctrl+PgUp", "active" : firstValue is not None and firstValue != currentValue, + "searchable" : False, } ) diff --git a/python/GafferImageUI/RGBAChannelsPlugValueWidget.py b/python/GafferImageUI/RGBAChannelsPlugValueWidget.py index ec32b3d6a37..13520755acb 100644 --- a/python/GafferImageUI/RGBAChannelsPlugValueWidget.py +++ b/python/GafferImageUI/RGBAChannelsPlugValueWidget.py @@ -48,11 +48,19 @@ ## Supported plug metadata : # # - "rgbaChannelsPlugValueWidget:allowNone" : Allows "None" to be chosen to assign an empty StringVectorData. +# - "rgbaChannelsPlugValueWidget:searchable" : Set to False to remove the search field from the menu. Defaults to True. class RGBAChannelsPlugValueWidget( GafferUI.PlugValueWidget ) : def __init__( self, plugs, **kw ) : - self.__menuButton = GafferUI.MenuButton( menu = GafferUI.Menu( Gaffer.WeakMethod( self._menuDefinition ) ) ) + searchable = all( + Gaffer.Metadata.value( p, "rgbaChannelsPlugValueWidget:searchable" ) is not False + for p in ( { plugs } if isinstance( plugs, Gaffer.Plug ) else plugs ) + ) + + self.__menuButton = GafferUI.MenuButton( + menu = GafferUI.Menu( Gaffer.WeakMethod( self._menuDefinition ), searchable = searchable ) + ) self.__menuButton._qtWidget().setMinimumWidth( 150 ) GafferUI.PlugValueWidget.__init__( self, self.__menuButton, plugs, **kw ) @@ -161,7 +169,7 @@ def _menuDefinition( self ) : result = IECore.MenuDefinition() if not rgbaChannels : - result.append( "/No channels available", { "active" : False } ) + result.append( "/No channels available", { "active" : False, "searchable" : False } ) return result for text, value in rgbaChannels.items() : @@ -171,6 +179,7 @@ def _menuDefinition( self ) : { "command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), value = value ), "checkBox" : value == self.__currentValue, + "searchText" : text, } ) diff --git a/python/GafferImageUITest/ImageViewTest.py b/python/GafferImageUITest/ImageViewTest.py index 6a9b3bc77d9..0b6eaab6560 100644 --- a/python/GafferImageUITest/ImageViewTest.py +++ b/python/GafferImageUITest/ImageViewTest.py @@ -89,3 +89,34 @@ def testImageGadget( self ) : view = GafferImageUI.ImageView( script ) self.assertIsInstance( view.imageGadget(), GafferImageUI.ImageGadget ) self.assertTrue( view.viewportGadget().isAncestorOf( view.imageGadget() ) ) + + def testChannelsMenuViewerOnlyItemsAreNotSearchable( self ) : + + script = Gaffer.ScriptNode() + script["constant"] = GafferImage.Constant() + script["shuffle"] = GafferImage.Shuffle() + script["shuffle"]["in"].setInput( script["constant"]["out"] ) + for channel in "RGBA" : + script["shuffle"]["shuffles"].addChild( Gaffer.ShufflePlug( channel, f"diffuse.{channel}" ) ) + + view = GafferUI.View.create( script["shuffle"]["out"] ) + widget = GafferImageUI.ImageViewUI._ChannelsPlugValueWidget( view["channels"] ) + GafferUITest.PlugValueWidgetTest.waitForUpdate( widget ) + + searchable = { + path : getattr( item, "searchable", True ) + for path, item in widget._menuDefinition().items() + if not item.divider + } + + self.assertEqual( + searchable, + { + "/RGBA" : True, + "/diffuse" : True, + "/Denoised" : False, + "/Previous" : False, + "/Next" : False, + "/First" : False, + } + ) diff --git a/python/GafferImageUITest/RGBAChannelsPlugValueWidgetTest.py b/python/GafferImageUITest/RGBAChannelsPlugValueWidgetTest.py new file mode 100644 index 00000000000..9d60ccc197e --- /dev/null +++ b/python/GafferImageUITest/RGBAChannelsPlugValueWidgetTest.py @@ -0,0 +1,110 @@ +########################################################################## +# +# Copyright (c) 2026, Image Engine Design Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided with +# the distribution. +# +# * Neither the name of John Haddon nor the names of +# any other contributors to this software may be used to endorse or +# promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +########################################################################## + +import unittest + +import Gaffer +import GafferUI +import GafferUITest +import GafferImage +import GafferImageUI + +class RGBAChannelsPlugValueWidgetTest( GafferUITest.TestCase ) : + + @staticmethod + def __script( layers ) : + + script = Gaffer.ScriptNode() + script["constant"] = GafferImage.Constant() + + script["shuffle"] = GafferImage.Shuffle() + script["shuffle"]["in"].setInput( script["constant"]["out"] ) + for layer in layers : + for channel in "RGBA" : + script["shuffle"]["shuffles"].addChild( Gaffer.ShufflePlug( channel, f"{layer}.{channel}" ) ) + + script["stats"] = GafferImage.ImageStats() + script["stats"]["in"].setInput( script["shuffle"]["out"] ) + + return script + + def testSearchable( self ) : + + script = self.__script( [] ) + + widget = GafferImageUI.RGBAChannelsPlugValueWidget( script["stats"]["channels"] ) + self.assertTrue( widget._RGBAChannelsPlugValueWidget__menuButton.getMenu().searchable() ) + + Gaffer.Metadata.registerValue( script["stats"]["channels"], "rgbaChannelsPlugValueWidget:searchable", False ) + widget = GafferImageUI.RGBAChannelsPlugValueWidget( script["stats"]["channels"] ) + self.assertFalse( widget._RGBAChannelsPlugValueWidget__menuButton.getMenu().searchable() ) + + def testSearchTextIsFullLayerName( self ) : + + script = self.__script( [ "diffuse", "diffuse.direct", "specular.indirect" ] ) + + widget = GafferImageUI.RGBAChannelsPlugValueWidget( script["stats"]["channels"] ) + GafferUITest.PlugValueWidgetTest.waitForUpdate( widget ) + + searchTexts = { + path : item.searchText + for path, item in widget._menuDefinition().items() + } + + self.assertEqual( + searchTexts, + { + "/RGBA" : "RGBA", + "/diffuse" : "diffuse", + "/diffuse/direct" : "diffuse.direct", + "/specular/indirect" : "specular.indirect", + } + ) + + def testNoChannelsItemIsNotSearchable( self ) : + + script = Gaffer.ScriptNode() + script["stats"] = GafferImage.ImageStats() + + widget = GafferImageUI.RGBAChannelsPlugValueWidget( script["stats"]["channels"] ) + GafferUITest.PlugValueWidgetTest.waitForUpdate( widget ) + + items = widget._menuDefinition().items() + self.assertEqual( [ path for path, item in items ], [ "/No channels available" ] ) + self.assertIs( items[0][1].searchable, False ) + +if __name__ == "__main__": + unittest.main() diff --git a/python/GafferImageUITest/__init__.py b/python/GafferImageUITest/__init__.py index b0422de4957..2a7b46c7e6e 100644 --- a/python/GafferImageUITest/__init__.py +++ b/python/GafferImageUITest/__init__.py @@ -36,6 +36,7 @@ from .FormatPlugValueWidgetTest import FormatPlugValueWidgetTest from .ImageViewTest import ImageViewTest +from .RGBAChannelsPlugValueWidgetTest import RGBAChannelsPlugValueWidgetTest from .DocumentationTest import DocumentationTest from .ImageGadgetTest import ImageGadgetTest from .NodeUITest import NodeUITest diff --git a/python/GafferUITest/PlugValueWidgetTest.py b/python/GafferUITest/PlugValueWidgetTest.py index b629eac6c1e..cbd87b02993 100644 --- a/python/GafferUITest/PlugValueWidgetTest.py +++ b/python/GafferUITest/PlugValueWidgetTest.py @@ -35,6 +35,7 @@ # ########################################################################## +import itertools import warnings import weakref @@ -57,7 +58,10 @@ def waitForUpdate( widget ) : # And updates for computed values are done in the background, so we # need to wait until they're done. - if any( isinstance( p, Gaffer.ValuePlug ) and Gaffer.PlugAlgo.dependsOnCompute( p ) for p in widget.getPlugs() ) : + if any( + isinstance( p, Gaffer.ValuePlug ) and Gaffer.PlugAlgo.dependsOnCompute( p ) + for p in itertools.chain( widget.getPlugs(), *widget._PlugValueWidget__auxiliaryPlugs ) + ) : handler.assertCalled() def testContext( self ) :