Skip to content

Commit

Permalink
EditScopePlugValueWidget : Remove "Downstream" menu section
Browse files Browse the repository at this point in the history
If we're not showing upstream nodes that aren't active, I don't see any justification for showing downstream nodes that can never be active. This also lets us slightly simplify the menu building logic.
  • Loading branch information
johnhaddon committed Jul 24, 2024
1 parent d8e5fa0 commit 59b94e0
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions python/GafferUI/EditScopeUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def __activeEditScopes( self ) :

return result

def __buildMenu( self, result, path, currentEditScope ) :
def __buildMenu( self, path, currentEditScope ) :

result = IECore.MenuDefinition()

Expand All @@ -328,8 +328,7 @@ def __buildMenu( self, result, path, currentEditScope ) :
singlesStack.extend( [ children[0] ] )

if currentEditScope is not None :
# Ignore the first entry, which is the menu category
node = currentEditScope.scriptNode().descendant( ".".join( childPath[1:] ) )
node = currentEditScope.scriptNode().descendant( ".".join( childPath[:] ) )
icon = "menuBreadCrumb.png" if node.isAncestorOf( currentEditScope ) else None
else :
icon = None
Expand All @@ -339,7 +338,6 @@ def __buildMenu( self, result, path, currentEditScope ) :
itemName,
{
"command" : functools.partial( Gaffer.WeakMethod( self.__connectEditScope ), editScope ),
"active" : path[0] != "Downstream",
"label" : itemName,
"checkBox" : editScope == currentEditScope,
"icon" : self.__editScopeSwatch( editScope ),
Expand All @@ -351,7 +349,7 @@ def __buildMenu( self, result, path, currentEditScope ) :
result.append(
itemName,
{
"subMenu" : functools.partial( Gaffer.WeakMethod( self.__buildMenu ), result, childPath, currentEditScope ),
"subMenu" : functools.partial( Gaffer.WeakMethod( self.__buildMenu ), childPath, currentEditScope ),
"icon" : icon
}
)
Expand All @@ -360,24 +358,18 @@ def __buildMenu( self, result, path, currentEditScope ) :

def __menuDefinition( self ) :

result = IECore.MenuDefinition()

currentEditScope = None
if self.getPlug().getInput() is not None :
currentEditScope = self.getPlug().getInput().parent()

activeEditScopes = self.__activeEditScopes()

node = self.__inputNode()
downstream = Gaffer.NodeAlgo.findAllDownstream( node, self.__editScopePredicate ) if node is not None else []

# Each child of the root will get its own section in the menu
# if it has children. The section will be preceded by a divider
# with its name in the divider label.
# Build a menu hierarchy to match the node hierarchy.
# This will be simplified where possible in `__buildMenu()`.

menuHierarchy = OrderedDict()
for editScope in reversed( activeEditScopes ) :

def addToMenuHierarchy( editScope, root ) :
ancestorNodes = []
currentNode = editScope
while currentNode.parent() != editScope.scriptNode() :
Expand All @@ -386,31 +378,12 @@ def addToMenuHierarchy( editScope, root ) :

ancestorNodes.reverse()

currentNode = menuHierarchy.setdefault( root, {} )
currentMenu = menuHierarchy
for n in ancestorNodes :
currentNode = currentNode.setdefault( n.getName(), {} )
currentNode[editScope.getName()] = editScope

for editScope in reversed( activeEditScopes ) :
addToMenuHierarchy( editScope, "Upstream" )

for editScope in sorted( downstream, key = lambda e : e.relativeName( e.scriptNode() ) ) :
addToMenuHierarchy( editScope, "Downstream" )

menuPath = Gaffer.DictPath( menuHierarchy, "/" )

for category in menuPath.children() :

if len( category.children() ) == 0 :
continue

result.append(
"/__{}Divider__".format( category[-1] ),
{ "divider" : True, "label" : category[-1] }
)

result.update( self.__buildMenu( result, category, currentEditScope ) )
currentMenu = currentMenu.setdefault( n.getName(), {} )
currentMenu[editScope.getName()] = editScope

result = self.__buildMenu( Gaffer.DictPath( menuHierarchy, "/" ), currentEditScope )

if self.__contextTracker.updatePending() :
result.append( "/__RefreshDivider__", { "divider" : True } )
Expand Down

0 comments on commit 59b94e0

Please sign in to comment.