Skip to content

Commit

Permalink
fixup! ColorChooser : Maintain options state per-session
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Aug 23, 2024
1 parent 9ec28a6 commit 7803fb8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
18 changes: 9 additions & 9 deletions python/GafferUI/ColorChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ def __init__( self, color=imath.Color3f( 1 ), **kw ) :
self.__colorSwatch._qtWidget().setFixedHeight( 40 )

self.__colorChangedSignal = Gaffer.Signals.Signal2()
self.__visibleComponentsChangedSignal = Gaffer.Signals.Signal2()
self.__staticComponentChangedSignal = Gaffer.Signals.Signal2()
self.__colorFieldVisibleChangedSignal = Gaffer.Signals.Signal2()
self.__visibleComponentsChangedSignal = Gaffer.Signals.Signal1()
self.__staticComponentChangedSignal = Gaffer.Signals.Signal1()
self.__colorFieldVisibleChangedSignal = Gaffer.Signals.Signal1()

self.__updateUIFromColor()
self.__activateComponentIcons()
Expand Down Expand Up @@ -639,7 +639,7 @@ def setColorFieldStaticComponent( self, component ) :
if self.__colorField.getVisible() :
self.__activateComponentIcons()

self.__staticComponentChangedSignal( self, component )
self.__staticComponentChangedSignal( self )

def getColorFieldStaticComponent( self ) :

Expand All @@ -664,23 +664,23 @@ def colorChangedSignal( self ) :
return self.__colorChangedSignal

## A signal emitted whenever the visible components are changed. Slots
# should have the signature slot( ColorChooser, visibleComponents ).
# should have the signature slot( ColorChooser ).
# `visibleComponents` is a string representing the components currently
# visible.
def visibleComponentsChangedSignal( self ) :

return self.__visibleComponentsChangedSignal

## A signal emitted whenver the static component is changed. Slots
# should have the signature slot( ColorChooser, staticComponent ).
# should have the signature slot( ColorChooser ).
# `staticComponent` is a single character string representing the
# current static component.
def staticComponentChangedSignal( self ) :

return self.__staticComponentChangedSignal

## A signal emitted whenever the visibility of the color field changes.
# Slots should have the signature slot( ColorChooser, visible ).
# Slots should have the signature slot( ColorChooser ).
# `visible` is a boolean representing the current visibility.
def colorFieldVisibleChangedSignal( self ) :

Expand Down Expand Up @@ -1006,7 +1006,7 @@ def __setVisibleComponentsInternal( self, components ) :
self.__numericWidgets[c].setVisible( visible )
self.__sliders[c].setVisible( visible )

self.__visibleComponentsChangedSignal( self, components )
self.__visibleComponentsChangedSignal( self )

def __setColorFieldVisibleInternal( self, visible ) :

Expand All @@ -1020,4 +1020,4 @@ def __setColorFieldVisibleInternal( self, visible ) :
else :
self.__clearComponentIcons()

self.__colorFieldVisibleChangedSignal( self, visible )
self.__colorFieldVisibleChangedSignal( self )
29 changes: 16 additions & 13 deletions python/GafferUI/ColorChooserPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,15 @@ def __init__( self, plugs, **kw ) :
)

self.__colorChooser.visibleComponentsChangedSignal().connect(
functools.partial(
Gaffer.WeakMethod( self.__colorChooserOptionChanged ),
key = "visibleComponents"
),
functools.partial( Gaffer.WeakMethod( self.__colorChooserVisibleComponentsChanged ) ),
scoped = False
)
self.__colorChooser.staticComponentChangedSignal().connect(
functools.partial(
Gaffer.WeakMethod( self.__colorChooserOptionChanged ),
key = "staticComponent"
),
functools.partial( Gaffer.WeakMethod( self.__colorChooserStaticComponentChanged ) ),
scoped = False
)
self.__colorChooser.colorFieldVisibleChangedSignal().connect(
functools.partial(
Gaffer.WeakMethod( self.__colorChooserOptionChanged ),
key = "colorFieldVisible"
),
functools.partial( Gaffer.WeakMethod( self.__colorChooserColorFieldVisibleChanged ) ),
scoped = False
)

Expand Down Expand Up @@ -126,7 +117,7 @@ def __colorChanged( self, colorChooser, reason ) :
for plug in self.getPlugs() :
plug.setValue( self.__colorChooser.getColor() )

def __colorChooserOptionChanged( self, colorChooser, value, key ) :
def __colorChooserOptionChanged( self, value, key ) :

if Gaffer.Metadata.value( "colorChooser:inlineOptions", "userDefault" ) is None :
sessionOptions = Gaffer.Metadata.value( "colorChooser:inlineOptions", "sessionDefault" )
Expand All @@ -144,6 +135,18 @@ def __colorChooserOptionChanged( self, colorChooser, value, key ) :

plugOptions.update( { key: value } )

def __colorChooserVisibleComponentsChanged( self, colorChooser ) :

self.__colorChooserOptionChanged( colorChooser.getVisibleComponents(), "visibleComponents" )

def __colorChooserStaticComponentChanged( self, colorChooser ) :

self.__colorChooserOptionChanged( colorChooser.getColorFieldStaticComponent(), "staticComponent" )

def __colorChooserColorFieldVisibleChanged( self, colorChooser ) :

self.__colorChooserOptionChanged( colorChooser.getColorFieldVisible(), "colorFieldVisible" )

def __colorChooserOptions( self ) :

v = sole( Gaffer.Metadata.value( p, "colorChooser:inlineOptions" ) for p in self.getPlugs() )
Expand Down
29 changes: 16 additions & 13 deletions python/GafferUI/ColorSwatchPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,15 @@ def __init__( self, plugs, parentWindow ) :
self.__colorChangedConnection = self.colorChooser().colorChangedSignal().connect( Gaffer.WeakMethod( self.__colorChanged ), scoped = False )

self.colorChooser().visibleComponentsChangedSignal().connect(
functools.partial(
Gaffer.WeakMethod( self.__colorChooserOptionChanged ),
key = "visibleComponents"
),
functools.partial( Gaffer.WeakMethod( self.__colorChooserVisibleComponentsChanged ) ),
scoped = False
)
self.colorChooser().staticComponentChangedSignal().connect(
functools.partial(
Gaffer.WeakMethod( self.__colorChooserOptionChanged ),
key = "staticComponent"
),
functools.partial( Gaffer.WeakMethod( self.__colorChooserStaticComponentChanged ) ),
scoped = False
)
self.colorChooser().colorFieldVisibleChangedSignal().connect(
functools.partial(
Gaffer.WeakMethod( self.__colorChooserOptionChanged ),
key = "colorFieldVisible"
),
functools.partial( Gaffer.WeakMethod( self.__colorChooserColorFieldVisibleChanged ) ),
scoped = False
)

Expand Down Expand Up @@ -256,7 +247,7 @@ def __destroy( self, *unused ) :
# \todo Extract these two methods to share with `ColorChooserPlugValueWidget` which has
# an almost identical implementation.

def __colorChooserOptionChanged( self, colorChooser, value, key ) :
def __colorChooserOptionChanged( self, value, key ) :

if Gaffer.Metadata.value( "colorChooser:dialogueOptions", "userDefault" ) is None :
sessionOptions = Gaffer.Metadata.value( "colorChooser:dialogueOptions", "sessionDefault" )
Expand All @@ -274,6 +265,18 @@ def __colorChooserOptionChanged( self, colorChooser, value, key ) :

plugOptions.update( { key: value } )

def __colorChooserVisibleComponentsChanged( self, colorChooser ) :

self.__colorChooserOptionChanged( colorChooser.getVisibleComponents(), "visibleComponents" )

def __colorChooserStaticComponentChanged( self, colorChooser ) :

self.__colorChooserOptionChanged( colorChooser.getColorFieldStaticComponent(), "staticComponent" )

def __colorChooserColorFieldVisibleChanged( self, colorChooser ) :

self.__colorChooserOptionChanged( colorChooser.getColorFieldVisible(), "colorFieldVisible" )

def __colorChooserOptions( self ) :

v = sole( Gaffer.Metadata.value( p, "colorChooser:dialogueOptions" ) for p in self.__plugs )
Expand Down

0 comments on commit 7803fb8

Please sign in to comment.