Skip to content

Commit

Permalink
SpreadsheetUI : Disallow paste to cells with inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomc-cinesite committed Dec 3, 2020
1 parent 1441260 commit 3df33fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
32 changes: 23 additions & 9 deletions python/GafferUI/SpreadsheetUI/_ClipboardAlgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,8 @@ def _get( cls, plug ) :
@classmethod
def _canSet( cls, data, plug ) :

# Ensure we consider child plugs, eg: components of a V3fPlug
if Gaffer.MetadataAlgo.readOnly( plug ) :
if not cls._canSetKeyOrValue( plug ) :
return False
for p in Gaffer.Plug.RecursiveRange( plug ) :
if Gaffer.MetadataAlgo.getReadOnly( p ) :
return False

plugData = ValueAdaptor.get( plug )

Expand Down Expand Up @@ -334,6 +330,21 @@ def _set( cls, data, plug, atTime ) :
for childName, childData in data.items() :
cls._set( childData, plug[ childName ], atTime )

@staticmethod
def _canSetKeyOrValue( plug ) :

def connectedButNotAnimated( p ) :
return p.getInput() is not None and not Gaffer.Animation.isAnimated( p )

# Ensure we consider child plugs, eg: components of a V3fPlug
if Gaffer.MetadataAlgo.readOnly( plug ) or connectedButNotAnimated( plug ) :
return False
for p in Gaffer.Plug.RecursiveRange( plug ) :
if Gaffer.MetadataAlgo.getReadOnly( p ) or connectedButNotAnimated( p ) :
return False

return True

@staticmethod
def _setOrKeyValue( plug, value, atTime ) :

Expand Down Expand Up @@ -439,8 +450,11 @@ class FloatPlugValueAdaptor( ValueAdaptor ) :
@classmethod
def _canSet( cls, data, plug ) :

# FloatPlug.setValue will take care of this for us
return isinstance( data, ( IECore.FloatData, IECore.IntData ) )
# FloatPlug.setValue will take care conversion for us
if isinstance( data, ( IECore.FloatData, IECore.IntData ) ) :
return cls._canSetKeyOrValue( plug )

return ValueAdaptor._canSet( data, plug )

ValueAdaptor.registerAdaptor( Gaffer.FloatPlug, FloatPlugValueAdaptor )

Expand All @@ -451,7 +465,7 @@ def _canSet( cls, data, plug ) :

if isinstance( data, IECore.StringVectorData ) :
if len( data ) < 2 :
return True
return cls._canSetKeyOrValue( plug )

return ValueAdaptor._canSet( data, plug )

Expand All @@ -474,7 +488,7 @@ class StringVectorDataPlugValueAdaptor( ValueAdaptor ) :
def _canSet( cls, data, plug ) :

if isinstance( data, IECore.StringData ) :
return True
return cls._canSetKeyOrValue( plug )

return ValueAdaptor._canSet( data, plug )

Expand Down
13 changes: 13 additions & 0 deletions python/GafferUITest/SpreadsheetUITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,5 +752,18 @@ def testPasteBasicValues( self ) :
self.assertEqual( row["cells"][0]["value"].getValue(), 3 )
self.assertEqual( row["cells"][1]["value"]["value"].getValue(), 3 )

def testCantPasteWithConnections( self ) :

s = Gaffer.Spreadsheet()
s["rows"].addColumn( Gaffer.IntPlug() )
s["rows"].addRow()

self.assertTrue( _ClipboardAlgo.canPasteCells( IECore.IntData( 1 ), [ s["rows"][1]["cells"].children() ] ) )

p = Gaffer.IntPlug()
s["rows"][1]["cells"][0]["value"].setInput( p )

self.assertFalse( _ClipboardAlgo.canPasteCells( IECore.IntData( 1 ), [ s["rows"][1]["cells"].children() ] ) )

if __name__ == "__main__":
unittest.main()

0 comments on commit 3df33fc

Please sign in to comment.