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 Sep 24, 2024
1 parent 84d9019 commit db3c6d8
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 @@ -567,9 +567,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 @@ -636,7 +636,7 @@ def setColorFieldStaticComponent( self, component ) :
if self.__colorField.getVisible() :
self.__activateComponentIcons()

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

def getColorFieldStaticComponent( self ) :

Expand All @@ -661,23 +661,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 @@ -1003,7 +1003,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 @@ -1017,4 +1017,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,22 +69,13 @@ def __init__( self, plugs, **kw ) :
)

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

self.__lastChangedReason = None
Expand Down Expand Up @@ -123,7 +114,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 @@ -141,6 +132,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,22 +138,13 @@ def __init__( self, plugs, parentWindow ) :
self.__colorChangedConnection = self.colorChooser().colorChangedSignal().connect( Gaffer.WeakMethod( self.__colorChanged ) )

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

self.confirmButton.clickedSignal().connect( Gaffer.WeakMethod( self.__buttonClicked ) )
Expand Down Expand Up @@ -253,7 +244,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 @@ -271,6 +262,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 db3c6d8

Please sign in to comment.