From fcbb9c33603fe0f800ee20aba0e8a96a675f45ec Mon Sep 17 00:00:00 2001 From: Eric Mehl Date: Fri, 1 Nov 2024 11:20:33 -0400 Subject: [PATCH] fixup! ColorChooser : Static color slider widgets --- python/GafferUI/ColorChooser.py | 44 +++++++++---------- .../GafferUI/ColorChooserPlugValueWidget.py | 22 +++++----- python/GafferUI/ColorSwatchPlugValueWidget.py | 14 +++--- python/GafferUITest/ColorChooserTest.py | 38 ++++++++-------- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/python/GafferUI/ColorChooser.py b/python/GafferUI/ColorChooser.py index b191b252e92..808da051591 100644 --- a/python/GafferUI/ColorChooser.py +++ b/python/GafferUI/ColorChooser.py @@ -117,7 +117,7 @@ def _drawIndicator( painter, position ) : # A custom slider for drawing the backgrounds. class _ComponentSlider( GafferUI.Slider ) : - def __init__( self, color, component, dynamicColors = False, **kw ) : + def __init__( self, color, component, dynamicBackground = False, **kw ) : GafferUI.Slider.__init__( self, 0.0, @@ -128,7 +128,7 @@ def __init__( self, color, component, dynamicColors = False, **kw ) : self.color = color self.component = component - self.__dynamicColors = dynamicColors + self.__dynamicBackground = dynamicBackground self.__gradientToDraw = None self.__size = self.size() @@ -137,8 +137,8 @@ def __init__( self, color, component, dynamicColors = False, **kw ) : def setColor( self, color ) : if ( - ( self.__dynamicColors and color != self.color ) or - ( not self.__dynamicColors and self.component == "s" ) + ( self.__dynamicBackground and color != self.color ) or + ( not self.__dynamicBackground and self.component == "s" ) ) : self.__gradientToDraw = None self.color = color @@ -148,15 +148,15 @@ def getColor( self ) : return self.color - def setDynamicColors( self, dynamic ) : + def setDynamicBackground( self, dynamicBackground ) : - self.__dynamicColors = dynamic + self.__dynamicBackground = dynamicBackground self.__gradientToDraw = None self._qtWidget().update() - def getDynamicColors( self ) : + def getDynamicBackground( self ) : - return self.__dynamicColors + return self.__dynamicBackground def _drawBackground( self, painter ) : @@ -171,7 +171,7 @@ def _drawBackground( self, painter ) : c1 = imath.Color3f( 0 ) c2 = imath.Color3f( 1 ) else : - if self.__dynamicColors : + if self.__dynamicBackground : c1 = imath.Color3f( self.color[0], self.color[1], self.color[2] ) elif self.component in "rgbvi" : c1 = imath.Color3f( 0 ) @@ -887,7 +887,7 @@ def __init__( self, color=imath.Color3f( 1 ), **kw ) : self.__visibleComponentsChangedSignal = Gaffer.Signals.Signal1() self.__staticComponentChangedSignal = Gaffer.Signals.Signal1() self.__colorFieldVisibleChangedSignal = Gaffer.Signals.Signal1() - self.__dynamicColorsChangedSignal = Gaffer.Signals.Signal1() + self.__dynamicSliderBackgroundsChangedSignal = Gaffer.Signals.Signal1() self.__optionsMenuSignal = Gaffer.Signals.Signal2() self.__colorFieldPrimaryIcon = GafferUI.Image( "colorFieldPrimaryIcon.png" ) @@ -898,7 +898,7 @@ def __init__( self, color=imath.Color3f( 1 ), **kw ) : self.__updateUIFromColor() self.__updateComponentIcons() - self.setDynamicColors( False ) + self.setDynamicSliderBackgrounds( False ) ## The default color starts as the value passed when creating the widget. # It is represented with a swatch which when clicked will revert the current @@ -975,17 +975,17 @@ def getColorFieldVisible( self ) : return self.__colorField.getVisible() - def setDynamicColors( self, dynamic ) : + def setDynamicSliderBackgrounds( self, dynamic ) : for component, slider in self.__sliders.items() : - slider.setDynamicColors( dynamic ) + slider.setDynamicBackground( dynamic ) self.__colorField.setDynamicColors( dynamic ) - self.__dynamicColorsChangedSignal( self ) + self.__dynamicSliderBackgroundsChangedSignal( self ) - def getDynamicColors( self ) : + def getDynamicSliderBackgrounds( self ) : - return self.__sliders["r"].getDynamicColors() + return self.__sliders["r"].getDynamicBackground() ## A signal emitted whenever the color is changed. Slots should # have the signature slot( ColorChooser, reason ). The reason @@ -1016,9 +1016,9 @@ def colorFieldVisibleChangedSignal( self ) : ## A signal emitted whenever the dynamic colors option is changed. # Slots should have the signature slot( ColorChooser ). - def dynamicColorsChangedSignal( self ) : + def dynamicSliderBackgroundsChangedSignal( self ) : - return self.__dynamicColorsChangedSignal + return self.__dynamicSliderBackgroundsChangedSignal ## A signal emitted whenever the options menu is opened. # Slots should have the signature slot( ColorChooser, menuDefinition ) @@ -1086,13 +1086,13 @@ def __optionsMenuDefinition( self ) : } ) - result.append( "/__appearance__", { "divider": True, "label": "Appearance" } ) + result.append( "/__sliders__", { "divider": True, "label": "Sliders" } ) result.append( - "/Dynamic Colors", + "/Dynamic Backgrounds", { - "command": Gaffer.WeakMethod( self.setDynamicColors ), - "checkBox": self.getDynamicColors(), + "command": Gaffer.WeakMethod( self.setDynamicSliderBackgrounds ), + "checkBox": self.getDynamicSliderBackgrounds(), } ) diff --git a/python/GafferUI/ColorChooserPlugValueWidget.py b/python/GafferUI/ColorChooserPlugValueWidget.py index 5354fe0976e..7e5116cc9db 100644 --- a/python/GafferUI/ColorChooserPlugValueWidget.py +++ b/python/GafferUI/ColorChooserPlugValueWidget.py @@ -65,9 +65,9 @@ def __init__( self, plugs, **kw ) : if colorFieldVisible is not None : self.__colorChooser.setColorFieldVisible( colorFieldVisible ) - dynamicColors = self.__colorChooserOption( "dynamicColors" ) - if dynamicColors is not None : - self.__colorChooser.setDynamicColors( dynamicColors ) + dynamicSliderBackgrounds = self.__colorChooserOption( "dynamicSliderBackgrounds" ) + if dynamicSliderBackgrounds is not None : + self.__colorChooser.setDynamicSliderBackgrounds( dynamicSliderBackgrounds ) self.__colorChangedConnection = self.__colorChooser.colorChangedSignal().connect( Gaffer.WeakMethod( self.__colorChanged ) @@ -82,8 +82,8 @@ def __init__( self, plugs, **kw ) : self.__colorChooser.colorFieldVisibleChangedSignal().connect( functools.partial( Gaffer.WeakMethod( self.__colorChooserColorFieldVisibleChanged ) ) ) - self.__colorChooser.dynamicColorsChangedSignal().connect( - functools.partial( Gaffer.WeakMethod( self.__dynamicColorsChanged ) ) + self.__colorChooser.dynamicSliderBackgroundsChangedSignal().connect( + functools.partial( Gaffer.WeakMethod( self.__dynamicSliderBackgroundsChanged ) ) ) self.__colorChooser.optionsMenuSignal().connect( functools.partial( Gaffer.WeakMethod( self.__colorChooserOptionsMenu ) ), @@ -148,9 +148,9 @@ def __colorChooserColorFieldVisibleChanged( self, colorChooser ) : self.__colorChooserOptionChanged( "colorFieldVisible", colorChooser.getColorFieldVisible() ) - def __dynamicColorsChanged( self, colorChooser ) : + def __dynamicSliderBackgroundsChanged( self, colorChooser ) : - self.__colorChooserOptionChanged( "dynamicColors", colorChooser.getDynamicColors() ) + self.__colorChooserOptionChanged( "dynamicSliderBackgrounds", colorChooser.getDynamicSliderBackgrounds() ) def __colorChooserOptionsMenu( self, colorChooser, menuDefinition ) : @@ -188,16 +188,16 @@ def saveDefaultOptions( colorChooser, keyPrefix, scriptPath = None ) : visibleComponents = colorChooser.getVisibleComponents() staticComponent = colorChooser.getColorFieldStaticComponent() colorFieldVisible = colorChooser.getColorFieldVisible() - dynamicColors = colorChooser.getDynamicColors() + dynamicSliderBackgrounds = colorChooser.getDynamicSliderBackgrounds() for p in [ Gaffer.Color3fPlug, Gaffer.Color4fPlug ] : - for k in [ "visibleComponents", "staticComponent", "colorFieldVisible", "dynamicColors" ] : + for k in [ "visibleComponents", "staticComponent", "colorFieldVisible", "dynamicSliderBackgrounds" ] : Gaffer.Metadata.deregisterValue( p, keyPrefix + k ) Gaffer.Metadata.registerValue( p, keyPrefix + "visibleComponents", visibleComponents ) Gaffer.Metadata.registerValue( p, keyPrefix + "staticComponent", staticComponent ) Gaffer.Metadata.registerValue( p, keyPrefix + "colorFieldVisible", colorFieldVisible ) - Gaffer.Metadata.registerValue( p, keyPrefix + "dynamicColors", dynamicColors ) + Gaffer.Metadata.registerValue( p, keyPrefix + "dynamicSliderBackgrounds", dynamicSliderBackgrounds ) if scriptPath is None : return @@ -223,7 +223,7 @@ def saveDefaultOptions( colorChooser, keyPrefix, scriptPath = None ) : newScript.append( f"Gaffer.Metadata.registerValue( Gaffer.Color{c}fPlug, \"{keyPrefix}visibleComponents\", \"{visibleComponents}\" )\n" ) newScript.append( f"Gaffer.Metadata.registerValue( Gaffer.Color{c}fPlug, \"{keyPrefix}staticComponent\", \"{staticComponent}\" )\n" ) newScript.append( f"Gaffer.Metadata.registerValue( Gaffer.Color{c}fPlug, \"{keyPrefix}colorFieldVisible\", {colorFieldVisible} )\n" ) - newScript.append( f"Gaffer.Metadata.registerValue( Gaffer.Color{c}fPlug, \"{keyPrefix}dynamicColors\", {dynamicColors} )\n" ) + newScript.append( f"Gaffer.Metadata.registerValue( Gaffer.Color{c}fPlug, \"{keyPrefix}dynamicSliderBackgrounds\", {dynamicSliderBackgrounds} )\n" ) with open( scriptPath, "w" ) as outFile : outFile.writelines( newScript ) \ No newline at end of file diff --git a/python/GafferUI/ColorSwatchPlugValueWidget.py b/python/GafferUI/ColorSwatchPlugValueWidget.py index dbb68879fdb..0ed0604bf55 100644 --- a/python/GafferUI/ColorSwatchPlugValueWidget.py +++ b/python/GafferUI/ColorSwatchPlugValueWidget.py @@ -147,8 +147,8 @@ def __init__( self, plugs, parentWindow ) : self.colorChooser().colorFieldVisibleChangedSignal().connect( functools.partial( Gaffer.WeakMethod( self.__colorChooserColorFieldVisibleChanged ) ) ) - self.colorChooser().dynamicColorsChangedSignal().connect( - functools.partial( Gaffer.WeakMethod( self.__dynamicColorsChanged ) ) + self.colorChooser().dynamicSliderBackgroundsChangedSignal().connect( + functools.partial( Gaffer.WeakMethod( self.__dynamicSliderBackgroundsChanged ) ) ) self.colorChooser().optionsMenuSignal().connect( functools.partial( Gaffer.WeakMethod( self.__colorChooserOptionsMenu ) ), @@ -186,9 +186,9 @@ def __init__( self, plugs, parentWindow ) : if colorFieldVisible is not None : self.colorChooser().setColorFieldVisible( colorFieldVisible ) - dynamicColors = self.__colorChooserOption( "dynamicColors" ) - if dynamicColors is not None : - self.colorChooser().setDynamicColors( dynamicColors ) + dynamicSliderBackgrounds = self.__colorChooserOption( "dynamicSliderBackgrounds" ) + if dynamicSliderBackgrounds is not None : + self.colorChooser().setDynamicSliderBackgrounds( dynamicSliderBackgrounds ) parentWindow.addChildWindow( self, removeOnClose = True ) @@ -295,6 +295,6 @@ def __colorChooserColorFieldVisibleChanged( self, colorChooser ) : self.__colorChooserOptionChanged( "colorFieldVisible", colorChooser.getColorFieldVisible() ) - def __dynamicColorsChanged( self, colorChooser ) : + def __dynamicSliderBackgroundsChanged( self, colorChooser ) : - self.__colorChooserOptionChanged( "dynamicColors", colorChooser.getDynamicColors() ) + self.__colorChooserOptionChanged( "dynamicSliderBackgrounds", colorChooser.getDynamicSliderBackgrounds() ) diff --git a/python/GafferUITest/ColorChooserTest.py b/python/GafferUITest/ColorChooserTest.py index d62dd8375b7..0d9c692ef8e 100644 --- a/python/GafferUITest/ColorChooserTest.py +++ b/python/GafferUITest/ColorChooserTest.py @@ -123,15 +123,15 @@ def __getColorFieldVisibility( self, widget ) : c = self.__colorChooserFromWidget( widget ) return c.getColorFieldVisible() - def __setDynamicColors( self, widget, dynamic ) : + def __setDynamicSliderBackgrounds( self, widget, dynamic ) : c = self.__colorChooserFromWidget( widget ) - c.setDynamicColors( dynamic ) + c.setDynamicSliderBackgrounds( dynamic ) - def __getDynamicColors( self, widget ) : + def __getDynamicSliderBackgrounds( self, widget ) : c = self.__colorChooserFromWidget( widget ) - return c.getDynamicColors() + return c.getDynamicSliderBackgrounds() def testMetadata( self ) : @@ -155,14 +155,14 @@ def testMetadata( self ) : self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:visibleComponents" ) ) self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:staticComponent" ) ) self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:colorFieldVisible" ) ) - self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:dynamicColors" ) ) + self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:dynamicSliderBackgrounds" ) ) # Modify widget self.__setVisibleComponents( widget, "rgbtmi" ) self.__setStaticComponent( widget, "t" ) self.__setColorFieldVisibility( widget, False ) - self.__setDynamicColors( widget, True ) + self.__setDynamicSliderBackgrounds( widget, True ) for c in "rgbtmi" : self.assertTrue( self.__sliderFromWidget( widget, c ).getVisible() ) @@ -170,18 +170,18 @@ def testMetadata( self ) : self.assertFalse( self.__sliderFromWidget( widget, c ).getVisible() ) self.assertEqual( self.__getStaticComponent( widget ), "t" ) self.assertFalse( self.__getColorFieldVisibility( widget ) ) - self.assertTrue( self.__getDynamicColors( widget ) ) + self.assertTrue( self.__getDynamicSliderBackgrounds( widget ) ) for p in [ "rgbPlug2" ] : self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:visibleComponents" ) ) self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:staticComponent" ) ) self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:colorFieldVisible" ) ) - self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:dynamicColors" ) ) + self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:dynamicSliderBackgrounds" ) ) self.assertEqual( set( Gaffer.Metadata.value( script["node"]["rgbPlug1"], "colorChooser:inline:visibleComponents" ) ), set( "rgbtmi" ) ) self.assertEqual( Gaffer.Metadata.value( script["node"]["rgbPlug1"], "colorChooser:inline:staticComponent" ), "t" ) self.assertFalse( Gaffer.Metadata.value( script["node"]["rgbPlug1"], "colorChooser:inline:colorFieldVisible" ) ) - self.assertTrue( Gaffer.Metadata.value( script["node"]["rgbPlug1"], "colorChooser:inline:dynamicColors" ) ) + self.assertTrue( Gaffer.Metadata.value( script["node"]["rgbPlug1"], "colorChooser:inline:dynamicSliderBackgrounds" ) ) # Recreate widget and should have the same state @@ -195,7 +195,7 @@ def testMetadata( self ) : self.assertFalse( self.__sliderFromWidget( widget, c ).getVisible() ) self.assertEqual( self.__getStaticComponent( widget ), "t" ) self.assertFalse( self.__getColorFieldVisibility( widget ) ) - self.assertTrue( self.__getDynamicColors( widget ) ) + self.assertTrue( self.__getDynamicSliderBackgrounds( widget ) ) # We haven't saved the defaults, so a widget for a second plug # gets the original defaults. @@ -207,13 +207,13 @@ def testMetadata( self ) : self.assertTrue( self.__sliderFromWidget( widget2, c ).getVisible() ) self.assertEqual( self.__getStaticComponent( widget2 ), "v" ) self.assertTrue( self.__getColorFieldVisibility( widget2 ) ) - self.assertFalse( self.__getDynamicColors( widget2 ) ) + self.assertFalse( self.__getDynamicSliderBackgrounds( widget2 ) ) for p in [ "rgbPlug2" ] : self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:visibleComponents" ) ) self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:staticComponent" ) ) self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:colorFieldVisible" ) ) - self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:dynamicColors" ) ) + self.assertIsNone( Gaffer.Metadata.value( script["node"][p], "colorChooser:inline:dynamicSliderBackgrounds" ) ) # Don't serialize state @@ -229,13 +229,13 @@ def testMetadata( self ) : self.assertTrue( self.__sliderFromWidget( widget, c ).getVisible() ) self.assertEqual( self.__getStaticComponent( widget ), "v" ) self.assertTrue( self.__getColorFieldVisibility( widget ) ) - self.assertFalse( self.__getDynamicColors( widget ) ) + self.assertFalse( self.__getDynamicSliderBackgrounds( widget ) ) for p in [ "rgbPlug1", "rgbPlug2" ] : self.assertIsNone( Gaffer.Metadata.value( script2["node"][p], "colorChooser:inline:visibleComponents" ) ) self.assertIsNone( Gaffer.Metadata.value( script2["node"][p], "colorChooser:inline:staticComponent" ) ) self.assertIsNone( Gaffer.Metadata.value( script2["node"][p], "colorChooser:inline:colorFieldVisible" ) ) - self.assertIsNone( Gaffer.Metadata.value( script2["node"][p], "colorChooser:inline:dynamicColors" ) ) + self.assertIsNone( Gaffer.Metadata.value( script2["node"][p], "colorChooser:inline:dynamicSliderBackgrounds" ) ) def testSaveDefaultOptions( self ) : @@ -263,15 +263,15 @@ def testSaveDefaultOptions( self ) : self.assertEqual( self.__getStaticComponent( rgbaWidget ), "v" ) self.assertTrue( self.__getColorFieldVisibility( rgbWidget ) ) self.assertTrue( self.__getColorFieldVisibility( rgbaWidget ) ) - self.assertFalse( self.__getDynamicColors( rgbWidget ) ) - self.assertFalse( self.__getDynamicColors( rgbaWidget ) ) + self.assertFalse( self.__getDynamicSliderBackgrounds( rgbWidget ) ) + self.assertFalse( self.__getDynamicSliderBackgrounds( rgbaWidget ) ) # Modify `rgbWidget` self.__setVisibleComponents( rgbWidget, "rgbhsv" ) self.__setStaticComponent( rgbWidget, "g" ) self.__setColorFieldVisibility( rgbWidget, False ) - self.__setDynamicColors( rgbWidget, True ) + self.__setDynamicSliderBackgrounds( rgbWidget, True ) # Save defaults colorChooser = self.__colorChooserFromWidget( rgbWidget ) @@ -300,8 +300,8 @@ def testSaveDefaultOptions( self ) : self.assertEqual( self.__getStaticComponent( rgbaWidget ), "g" ) self.assertFalse( self.__getColorFieldVisibility( rgbWidget ) ) self.assertFalse( self.__getColorFieldVisibility( rgbaWidget ) ) - self.assertTrue( self.__getDynamicColors( rgbWidget ) ) - self.assertTrue( self.__getDynamicColors( rgbaWidget ) ) + self.assertTrue( self.__getDynamicSliderBackgrounds( rgbWidget ) ) + self.assertTrue( self.__getDynamicSliderBackgrounds( rgbaWidget ) ) if __name__ == "__main__" : unittest.main()