Skip to content

Commit

Permalink
Merge pull request #3417 from danieldresser-ie/readOnlyRampWidget
Browse files Browse the repository at this point in the history
Support Ramp Widget For Read-Only Plugs
  • Loading branch information
johnhaddon committed Oct 24, 2019
2 parents 97cf031 + 80860b4 commit 78d4434
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
37 changes: 31 additions & 6 deletions python/GafferUI/RampPlugValueWidget.py
Expand Up @@ -146,6 +146,7 @@ def __positionsChanged( self, slider, reason ) :
self.__positionsMergeGroupId += 1
self.__lastPositionChangedReason = reason

rejected = False
plug = self.getPlug()
with Gaffer.UndoScope(
plug.ancestor( Gaffer.ScriptNode ),
Expand All @@ -155,22 +156,46 @@ def __positionsChanged( self, slider, reason ) :
if len( slider.getPositions() ) == plug.numPoints() :
# the user has moved an existing point on the slider
for index, position in enumerate( slider.getPositions() ) :
plug.pointXPlug( index ).setValue( position )
if plug.pointXPlug( index ).getValue() != position :
curPlug = plug.pointXPlug( index )
if curPlug.settable() and not Gaffer.MetadataAlgo.readOnly( curPlug ):
curPlug.setValue( position )
else:
rejected = True
else :
# a new position was added on the end by the user clicking
# on an empty area of the slider.
numPoints = plug.numPoints()
assert( len( slider.getPositions() ) == numPoints + 1 )
spline = plug.getValue().spline()
position = slider.getPositions()[numPoints]
plug.addPoint()
plug.pointXPlug( numPoints ).setValue( position )
plug.pointYPlug( numPoints ).setValue( spline( position ) )
if not ( plug.getInput() or plug.direction() == Gaffer.Plug.Direction.Out
or Gaffer.MetadataAlgo.readOnly( plug )
):
plug.addPoint()
plug.pointXPlug( numPoints ).setValue( position )
plug.pointYPlug( numPoints ).setValue( spline( position ) )
else:
rejected = True

if rejected:
self._updateFromPlug()

def __indexRemoved( self, slider, index ) :

with Gaffer.UndoScope( self.getPlug().ancestor( Gaffer.ScriptNode ) ) :
self.getPlug().removePoint( index )
plug = self.getPlug()
rejected = False
with Gaffer.UndoScope( plug.ancestor( Gaffer.ScriptNode ) ) :
if not ( plug.getInput() or plug.direction() == Gaffer.Plug.Direction.Out
or Gaffer.MetadataAlgo.readOnly( plug )
):
self.getPlug().removePoint( index )
else:
rejected = True

if rejected:
self._updateFromPlug()


def __selectedIndexChanged( self, slider ) :

Expand Down
2 changes: 1 addition & 1 deletion python/GafferUI/Slider.py
Expand Up @@ -333,7 +333,7 @@ def __buttonPress( self, widget, event ) :
positions = self.getPositions()[:]
positions.append( float( event.line.p0.x ) / self.size().x )
self._setPositionsInternal( positions, self.PositionChangedReason.IndexAdded )
self.setSelectedIndex( len( positions ) - 1 )
self.setSelectedIndex( len( self.getPositions() ) - 1 )

return True

Expand Down
3 changes: 0 additions & 3 deletions python/GafferUI/SplinePlugValueWidget.py
Expand Up @@ -86,9 +86,6 @@ def __buttonPress( self, button, event ) :

if event.buttons & event.Buttons.Left :

if not self._editable() :
return False

_SplinePlugValueDialogue.acquire( self.getPlug() )
return True

Expand Down

0 comments on commit 78d4434

Please sign in to comment.