Skip to content

Commit

Permalink
RampPlugValueWidget : Reject edits to readOnly plugs
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldresser committed Oct 23, 2019
1 parent 9ab4325 commit 80860b4
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions python/GafferUI/RampPlugValueWidget.py
Original file line number Diff line number Diff line change
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

0 comments on commit 80860b4

Please sign in to comment.