Skip to content

Commit

Permalink
fixup! SelectionToolUI : Custom dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Mar 21, 2024
1 parent 5aa08c4 commit f16556d
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions python/GafferSceneUI/SelectionToolUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,12 @@ def _updateFromValues( self, values, exception ) :
if exception is not None :
self.__menuButton.setText( "" )
else :
modifiers = dict(
zip(
GafferSceneUI.SelectionTool.registeredSelectModes(),
GafferSceneUI.SelectionTool.registeredSelectModeLabels()
)
)
modes = GafferSceneUI.SelectionTool.registeredSelectModes()

assert( len( values ) == 1 )
label = modifiers.get( values[0], None )

if label is not None :
self.__menuButton.setText( "Any" if label == "Any" else label.partition( "/" )[-1] )
if values[0] in modes :
self.__menuButton.setText( values[0].partition( "/" )[-1] )
else :
self.__menuButton.setText( "Invalid" )

Expand All @@ -148,33 +142,25 @@ def __menuDefinition( self ) :

result = IECore.MenuDefinition()

modifiers = dict(
zip(
GafferSceneUI.SelectionTool.registeredSelectModes(),
GafferSceneUI.SelectionTool.registeredSelectModeLabels()
)
)
modes = GafferSceneUI.SelectionTool.registeredSelectModes()

modifierCategories = set()
categories = set()

with self.getContext() :
currentValue = self.getPlug().getValue()

for modifierName, modifierLabel in modifiers.items() :
category, sep, label = modifierLabel.partition( "/" )

if category == "Any" :
label = "Any"
for mode in modes :
category, sep, label = mode.partition( "/" )

if category != "Any" and category not in modifierCategories :
if category != "" and category not in categories :
result.append( f"/__{category}Dividier", { "divider" : True, "label" : category } )
modifierCategories.add( category )
categories.add( category )

result.append(
f"/{label}",
{
"command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), modifierName ),
"checkBox" : modifierName == currentValue
"command" : functools.partial( Gaffer.WeakMethod( self.__setValue ), mode ),
"checkBox" : mode == currentValue
}
)

Expand Down

0 comments on commit f16556d

Please sign in to comment.