Skip to content

Commit

Permalink
PlugPopup : Add original / current color swatches
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Nov 5, 2024
1 parent c5d6d2e commit 774eea8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Improvements
- Added `inactiveIds` plug for selecting primitive variables to disable some instances.
- Added support for 64 bit integer ids (matching what is loaded from USD).
- DeletePoints : Added modes for deleting points based on a list of ids.
- Light Editor, Attribute Editor, Spreadsheet : Add original and current color swatches to color popups.

Fixes
-----
Expand Down
2 changes: 1 addition & 1 deletion python/GafferUI/ColorChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def getColor( self ) :

def setSwatchesVisible( self, visible ) :

self.__swatchRow.setVisible( False )
self.__swatchRow.setVisible( visible )

def getSwatchesVisible( self ) :

Expand Down
16 changes: 16 additions & 0 deletions python/GafferUI/ColorChooserPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ def __init__( self, plugs, **kw ) :
self.__lastChangedReason = None
self.__mergeGroupId = 0

def setInitialColor( self, color ) :

self.__colorChooser.setInitialColor( color )

def getInitialColor( self ) :

return self.__colorChooser.getInitialColor()

def setSwatchesVisible( self, visible ) :

self.__colorChooser.setSwatchesVisible( visible )

def getSwatchesVisible( self ) :

return self.__colorChooser.getVisible()

def _updateFromValues( self, values, exception ) :

# ColorChooser only supports one colour, and doesn't have
Expand Down
16 changes: 16 additions & 0 deletions python/GafferUI/ColorPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ def getColorChooserVisible( self ) :

return self.__colorChooser.getVisible() if self.__colorChooser is not None else False

def setInitialColor( self, color ) :

self.__colorChooser.setInitialColor( color )

def getInitialColor( self ) :

return self.__colorChooser.getInitialColor()

def setSwatchesVisible( self, visible ) :

self.__colorChooser.setSwatchesVisible( visible )

def getSwatchesVisible( self ) :

return self.__colorChooser.getVisible()

def setPlugs( self, plugs ) :

GafferUI.PlugValueWidget.setPlugs( self, plugs )
Expand Down
26 changes: 26 additions & 0 deletions python/GafferUI/PlugPopup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#
##########################################################################

import imath

import Gaffer
import GafferUI

Expand Down Expand Up @@ -122,6 +124,30 @@ def popup( self, center = None, parent = None ) :

GafferUI.PopupWindow.popup( self, center, parent )

colorPlugValueWidget = self.__colorPlugValueWidget( self.__plugValueWidget )
if colorPlugValueWidget is not None and len( self.__plugValueWidget.getPlugs() ) > 0 :
colors = [
p.getValue() for p in self.__plugValueWidget.getPlugs() if (
isinstance( p, Gaffer.Color3fPlug ) or isinstance( p, Gaffer.Color4fPlug )
)
]
if len( colors ) == 0 :
for c in self.__plugValueWidget.getPlugs() :
colors += [ p.getValue() for p in Gaffer.Color3fPlug.RecursiveRange( c ) ]
if len( colors ) == 0 :
for c in self.__plugValueWidget.getPlugs() :
colors += [ p.getValue() for p in Gaffer.Color4fPlug.RecursiveRange( c ) ]

assert( len( colors ) > 0 )
assert(
all(
isinstance( c, imath.Color3f ) for c in colors
) or all( isinstance( c, imath.Color4f ) for c in colors )
)

colorPlugValueWidget.setInitialColor( sum( colors ) / len( colors ) )
colorPlugValueWidget.setSwatchesVisible( True )

# Attempt to focus the first text widget. This is done after making
# the window visible, as we check child widget visibility to avoid
# attempting to focus hidden widgets.
Expand Down

0 comments on commit 774eea8

Please sign in to comment.