Skip to content

Commit

Permalink
HierarchyView : Add sceneListing() method
Browse files Browse the repository at this point in the history
This is intended to give clients access to the `columnContextMenuSignal()` to customise the context menu. Currently it returns a bare PathListingWidget which gives clients more privilege than is ideal (we don't want them to change the path!), but in future should return a more specialised SceneListing widget. That won't appear till Gaffer 1.5 though, and we want to allow the menu to be customised in 1.4. So for now we content ourselves with a little warning that folks shouldn't get addicted to anything other than the context menu signal.
  • Loading branch information
johnhaddon committed Aug 1, 2024
1 parent c0a07f4 commit 1ed69bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ API
---

- PathListingWidget : Added `columnContextMenuSignal()`, allowing multiple clients to collaborate on the creation of a column-specific context menu.
- HierarchyView : Added `sceneListing()` method, to allow the context menu to be customised.

Documentation
-------------
Expand Down
24 changes: 14 additions & 10 deletions python/GafferSceneUI/HierarchyView.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__( self, scriptNode, **kw ) :
self.__selectionChangedConnection = self.__pathListing.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__selectionChanged ), scoped = False )
self.__expansionChangedConnection = self.__pathListing.expansionChangedSignal().connect( Gaffer.WeakMethod( self.__expansionChanged ), scoped = False )

self.__pathListing.contextMenuSignal().connect( Gaffer.WeakMethod( self.__contextMenuSignal ), scoped = False )
self.__pathListing.columnContextMenuSignal().connect( Gaffer.WeakMethod( self.__columnContextMenuSignal ), scoped = False )
self.keyPressSignal().connect( Gaffer.WeakMethod( self.__keyPressSignal ), scoped = False )

self.__plug = None
Expand All @@ -100,6 +100,17 @@ def scene( self ) :

return self.__plug

## Returns the widget used for showing the main scene listing, with the
# intention that clients can add custom context menu items via
# `sceneListing.columnContextMenuSignal()`.
#
# > Caution : This currently returns a PathListingWidget, but in future
# > will probably return a more specialised widget with fewer privileges.
# > Please limit usage to `columnContextMenuSignal()`.
def sceneListing( self ) :

return self.__pathListing

def __repr__( self ) :

return "GafferSceneUI.HierarchyView( scriptNode )"
Expand Down Expand Up @@ -209,11 +220,9 @@ def __keyPressSignal( self, widget, event ) :

return False

def __contextMenuSignal( self, widget ) :

menuDefinition = IECore.MenuDefinition()
def __columnContextMenuSignal( self, column, pathListing, menuDefinition ) :

selection = self.__pathListing.getSelection()
selection = pathListing.getSelection()
menuDefinition.append(
"Copy Path%s" % ( "" if selection.size() == 1 else "s" ),
{
Expand All @@ -231,11 +240,6 @@ def __contextMenuSignal( self, widget ) :
}
)

self.__contextMenu = GafferUI.Menu( menuDefinition )
self.__contextMenu.popup( widget )

return True

def __copySelectedPaths( self, *unused ) :

if self.__plug is None :
Expand Down

0 comments on commit 1ed69bf

Please sign in to comment.