Skip to content

Commit

Permalink
MatchPatternPathFilterWidget : dyn. placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl authored and johnhaddon committed Jun 27, 2023
1 parent 37c2b44 commit 3ba7aa3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Improvements

- DelightOptions : Added new options for modern 3Delight, as of version `2.9.39`.
- ShaderQuery and ShaderTweaks : Added a filter for shader parameter names in the shader browser (#5293).
- MatchPatternPathFilterWidget : Added the name of the property being filtered to the placeholder text.

Fixes
-----
Expand Down
30 changes: 21 additions & 9 deletions python/GafferUI/MatchPatternPathFilterWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__( self, pathFilter, **kw ) :
self.__row = GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal, spacing=2, borderWidth=0 )

GafferUI.PathFilterWidget.__init__( self, self.__row, pathFilter, **kw )
pathFilter.changedSignal().connect( Gaffer.WeakMethod( self.__updatePlaceholderText ), scoped = False )

with self.__row :

Expand All @@ -61,11 +62,11 @@ def __init__( self, pathFilter, **kw ) :
)

self.__patternWidget = GafferUI.TextWidget()
self.__patternWidget._qtWidget().setPlaceholderText( "Filter..." )

self.__patternWidget.editingFinishedSignal().connect( Gaffer.WeakMethod( self.__patternEditingFinished ), scoped = False )
self.__patternWidget.textChangedSignal().connect( Gaffer.WeakMethod( self.__patternTextChanged ), scoped = False )

self.__updatePlaceholderText( pathFilter )
self._updateFromPathFilter()

def _updateFromPathFilter( self ) :
Expand Down Expand Up @@ -134,14 +135,7 @@ def __updateFilterMatchPatterns( self ) :

def __propertyMenuDefinition( self ) :

propertiesAndLabels = (
( "name", "Name" ),
( "fileSystem:owner", "Owner" ),
)

with IECore.IgnoredExceptions( KeyError ) :
propertyFilters = self.pathFilter().userData()["UI"]["propertyFilters"]
propertiesAndLabels = [ ( k, v.value ) for k, v in propertyFilters.items() ]
propertiesAndLabels = [ ( k, v.value ) for k, v in self.__propertyFilters().items() ]

menuDefinition = IECore.MenuDefinition()
for property, label in propertiesAndLabels :
Expand All @@ -160,4 +154,22 @@ def __setPropertyName( self, property, checked ) :
with Gaffer.Signals.BlockedConnection( self._pathFilterChangedConnection() ) :
self.pathFilter().setPropertyName( property )

def __updatePlaceholderText( self, pathFilter ) :

propertyNameData = self.__propertyFilters().get( pathFilter.getPropertyName(), None )

self.__patternWidget._qtWidget().setPlaceholderText(
"Filter{}".format( ( " by " + propertyNameData.value + "..." ) if propertyNameData is not None else "..." )
)

def __propertyFilters( self ) :

result = { "name": IECore.StringData( "Name" ), "filesystem:owner": IECore.StringData( "Owner" ) }

with IECore.IgnoredExceptions( KeyError ) :
result = self.pathFilter().userData()["UI"]["propertyFilters"]

return result


GafferUI.PathFilterWidget.registerType( Gaffer.MatchPatternPathFilter, MatchPatternPathFilterWidget )

0 comments on commit 3ba7aa3

Please sign in to comment.