Skip to content

Commit

Permalink
EditScopePlugValueWidget : Add lock icon to read-only EditScopes
Browse files Browse the repository at this point in the history
  • Loading branch information
murraystevenson committed Oct 31, 2024
1 parent 04b15d1 commit 0ce2c7c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
1.5.x.x (relative to 1.5.0.0)
=======

Improvements
------------

- EditScope : The EditScope menu now displays a lock icon next to read-only nodes.

Fixes
-----

Expand Down
43 changes: 33 additions & 10 deletions python/GafferUI/EditScopeUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def __init__( self, plug, **kw ) :
# run the default dropSignal handler from PlugValueWidget.
self.dropSignal().connectFront( Gaffer.WeakMethod( self.__drop ) )

self.__nodeMetadataChangedConnection = Gaffer.Metadata.nodeValueChangedSignal().connect(
Gaffer.WeakMethod( self.__nodeMetadataChanged ), scoped = True
)

self.__updatePlugInputChangedConnection()
self.__acquireContextTracker()

Expand All @@ -172,8 +176,11 @@ def getToolTip( self ) :
return "Edits will be made using the last relevant node found outside of an edit scope.\n\nTo make an edit in an edit scope, choose it from the menu."

unusableReason = self.__unusableReason( editScope )
readOnlyReason = self.__readOnlyReason( editScope )
if unusableReason :
return unusableReason
elif readOnlyReason :
return readOnlyReason
else :
return "Edits will be made in {}.".format( editScope.getName() )

Expand All @@ -189,12 +196,8 @@ def _updateFromValues( self, values, exception ) :
self.__editScopeNameChangedConnection = editScope.nameChangedSignal().connect(
Gaffer.WeakMethod( self.__editScopeNameChanged ), scoped = True
)
self.__editScopeMetadataChangedConnection = Gaffer.Metadata.nodeValueChangedSignal( editScope ).connect(
Gaffer.WeakMethod( self.__editScopeMetadataChanged ), scoped = True
)
else :
self.__editScopeNameChangedConnection = None
self.__editScopeMetadataChangedConnection = None

if self._qtWidget().property( "editScopeActive" ) != editScopeActive :
self._qtWidget().setProperty( "editScopeActive", GafferUI._Variant.toVariant( editScopeActive ) )
Expand Down Expand Up @@ -241,9 +244,13 @@ def __editScopeNameChanged( self, editScope, oldName ) :

self.__updateMenuButton()

def __editScopeMetadataChanged( self, editScope, key, reason ) :
def __nodeMetadataChanged( self, nodeTypeId, key, node ) :

if key == "nodeGadget:color" :
editScope = self.__editScope()
if (
Gaffer.MetadataAlgo.readOnlyAffectedByChange( editScope, nodeTypeId, key, node ) or
node == editScope and key == "nodeGadget:color"
) :
self.__updateMenuButton()

def __contextTrackerChanged( self, contextTracker ) :
Expand Down Expand Up @@ -342,7 +349,7 @@ def __buildMenu( self, path, currentEditScope ) :
"checkBox" : editScope == currentEditScope,
"icon" : self.__editScopeSwatch( editScope ),
"active" : not self.__unusableReason( editScope ),
"description" : self.__unusableReason( editScope ),
"description" : self.__unusableReason( editScope ) or self.__readOnlyReason( editScope ),
}
)
else :
Expand Down Expand Up @@ -437,9 +444,16 @@ def __navigationMenuDefinition( self ) :

def __editScopeSwatch( self, editScope ) :

return GafferUI.Image.createSwatch(
Gaffer.Metadata.value( editScope, "nodeGadget:color" ) or imath.Color3f( 1 )
)
color = Gaffer.Metadata.value( editScope, "nodeGadget:color" )

if Gaffer.MetadataAlgo.readOnly( editScope ) :
icon = GafferUI.Image( "menuLock.png" )
if color :
icon._tint( color )

return icon

return GafferUI.Image.createSwatch( color or imath.Color3f( 1 ) )

@staticmethod
def __userNodes( editScope ) :
Expand Down Expand Up @@ -530,6 +544,15 @@ def __unusableReason( self, editScope ) :
else :
return None

def __readOnlyReason( self, editScope ) :

if Gaffer.MetadataAlgo.readOnly( editScope ) :
return "{} is locked.".format(
Gaffer.MetadataAlgo.readOnlyReason( editScope ).relativeName( editScope.scriptNode() )
)

return None

# ProcessorWidget
# ===============

Expand Down
1 change: 1 addition & 0 deletions resources/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"menuChecked",
"menuIndicator",
"menuIndicatorDisabled",
"menuLock",
]
},

Expand Down
28 changes: 28 additions & 0 deletions resources/graphics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0ce2c7c

Please sign in to comment.