diff --git a/Changes.md b/Changes.md index c50fc51896..931acac957 100644 --- a/Changes.md +++ b/Changes.md @@ -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 ------------- diff --git a/python/GafferSceneUI/HierarchyView.py b/python/GafferSceneUI/HierarchyView.py index dd2d11040d..47c3495152 100644 --- a/python/GafferSceneUI/HierarchyView.py +++ b/python/GafferSceneUI/HierarchyView.py @@ -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 @@ -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 )" @@ -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" ), { @@ -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 :