<s> import Gaffer <EOL> import GafferUI <EOL> QtCore = GafferUI . _qtImport ( "<STR_LIT>" ) <EOL> QtGui = GafferUI . _qtImport ( "<STR_LIT>" ) <EOL> class RampPlugValueWidget ( GafferUI . PlugValueWidget ) : <EOL> def __init__ ( self , plug , parenting = None ) : <EOL> column = GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Vertical , spacing = <NUM_LIT:4> ) <EOL> GafferUI . PlugValueWidget . __init__ ( self , column , plug , parenting = parenting ) <EOL> with column : <EOL> self . __splineWidget = GafferUI . SplineWidget ( ) <EOL> self . __splineWidget . setDrawMode ( self . __splineWidget . DrawMode . Ramp ) <EOL> self . __splineWidget . _qtWidget ( ) . setMinimumHeight ( <NUM_LIT:50> ) <EOL> self . __slider = GafferUI . Slider ( ) <EOL> self . __slider . setSizeEditable ( True ) <EOL> self . __slider . setMinimumSize ( <NUM_LIT:2> ) <EOL> self . __positionsChangedConnection = self . __slider . positionChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __positionsChanged ) ) <EOL> self . __indexRemovedConnection = self . __slider . indexRemovedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __indexRemoved ) ) <EOL> self . __selectedIndexChangedConnection = self . __slider . selectedIndexChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __selectedIndexChanged ) ) <EOL> self . __lastPositionChangedReason = None <EOL> self . __positionsMergeGroupId = <NUM_LIT:0> <EOL> with GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> ) : <EOL> self . __positionLabel = GafferUI . LabelPlugValueWidget ( plug . pointXPlug ( <NUM_LIT:0> ) ) <EOL> self . __positionField = GafferUI . NumericPlugValueWidget ( plug . pointXPlug ( <NUM_LIT:0> ) ) <EOL> self . __valueLabel = GafferUI . LabelPlugValueWidget ( plug . pointYPlug ( <NUM_LIT:0> ) ) <EOL> self . __valueField = GafferUI . ColorPlugValueWidget ( plug . pointYPlug ( <NUM_LIT:0> ) ) <EOL> self . setPlug ( plug ) <EOL> def setPlug ( self , plug ) : <EOL> GafferUI . PlugValueWidget . setPlug ( self , plug ) <EOL> self . __slider . setSelectedIndex ( <NUM_LIT:0> ) <EOL> def getToolTip ( self ) : <EOL> result = GafferUI . PlugValueWidget . getToolTip ( self ) <EOL> if self . getPlug ( ) is not None : <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> return result <EOL> def _updateFromPlug ( self ) : <EOL> plug = self . getPlug ( ) <EOL> with self . getContext ( ) : <EOL> self . __splineWidget . setSpline ( plug . getValue ( ) ) <EOL> positions = [ ] <EOL> for i in range ( <NUM_LIT:0> , plug . numPoints ( ) ) : <EOL> positions . append ( plug . pointXPlug ( i ) . getValue ( ) ) <EOL> with Gaffer . BlockedConnection ( self . __positionsChangedConnection ) : <EOL> self . __slider . setPositions ( positions ) <EOL> def __positionsChanged ( self , slider , reason ) : <EOL> if not slider . changesShouldBeMerged ( self . __lastPositionChangedReason , reason ) : <EOL> self . __positionsMergeGroupId += <NUM_LIT:1> <EOL> self . __lastPositionChangedReason = reason <EOL> plug = self . getPlug ( ) <EOL> with Gaffer . UndoContext ( <EOL> plug . ancestor ( Gaffer . ScriptNode ) , <EOL> mergeGroup = "<STR_LIT>" % ( id ( self , ) , self . __positionsMergeGroupId ) <EOL> ) : <EOL> if len ( slider . getPositions ( ) ) == plug . numPoints ( ) : <EOL> for index , position in enumerate ( slider . getPositions ( ) ) : <EOL> plug . pointXPlug ( index ) . setValue ( position ) <EOL> else : <EOL> numPoints = plug . numPoints ( ) <EOL> assert ( len ( slider . getPositions ( ) ) == numPoints + <NUM_LIT:1> ) <EOL> spline = plug . getValue ( ) <EOL> position = slider . getPositions ( ) [ numPoints ] <EOL> plug . addPoint ( ) <EOL> plug . pointXPlug ( numPoints ) . setValue ( position ) <EOL> plug . pointYPlug ( numPoints ) . setValue ( spline ( position ) ) <EOL> def __indexRemoved ( self , slider , index ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> self . getPlug ( ) . removePoint ( index ) <EOL> def __selectedIndexChanged ( self , slider ) : <EOL> index = slider . getSelectedIndex ( ) <EOL> if self . getPlug ( ) is not None and index is not None : <EOL> pointPlug = self . getPlug ( ) . pointPlug ( index ) <EOL> self . __positionLabel . setPlug ( pointPlug [ "<STR_LIT:x>" ] ) <EOL> self . __positionField . setPlug ( pointPlug [ "<STR_LIT:x>" ] ) <EOL> self . __valueLabel . setPlug ( pointPlug [ "<STR_LIT:y>" ] ) <EOL> self . __valueField . setPlug ( pointPlug [ "<STR_LIT:y>" ] ) <EOL> else : <EOL> self . __positionLabel . setPlug ( None ) <EOL> self . __positionField . setPlug ( None ) <EOL> self . __valueLabel . setPlug ( None ) <EOL> self . __valueField . setPlug ( None ) <EOL> self . __positionLabel . label ( ) . setText ( "<STR_LIT>" ) <EOL> self . __valueLabel . label ( ) . setText ( "<STR_LIT>" ) </s>
