Skip to content

Commit

Permalink
PlugPopup : Improve handling of textWidgets
Browse files Browse the repository at this point in the history
Look for `textWidget()` attr rather than specific classes, so we can find `GafferSceneUI.SetExpressionPlugValueWidget`. Connect to `activatedSignal()` so we can close automatically when <kbd>Ctrl</kbd>+<kbd>Enter</kbd> is pressed in MultiLineTextWidgets.
  • Loading branch information
murraystevenson authored and johnhaddon committed May 29, 2024
1 parent 45ab8c4 commit 4a8f20e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions python/GafferUI/PlugPopup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__( self, plugs, title = None, warning = None, **kw ) :
colorPlugValueWidget.setColorChooserVisible( True )

self.visibilityChangedSignal().connect( Gaffer.WeakMethod( self.__visibilityChanged ), scoped = False )
self.focusChangedSignal().connect( Gaffer.WeakMethod( self.__focusChanged ), scoped = False )

def popup( self, center = None ) :

Expand Down Expand Up @@ -154,6 +155,19 @@ def __visibilityChanged( self, unused ) :
if gafferWidget is not None and self.isAncestorOf( gafferWidget ) :
gafferWidget._qtWidget().clearFocus()

def __focusChanged( self, oldWidget, newWidget ) :

if self.__plugValueWidget.isAncestorOf( newWidget ) and hasattr( newWidget, "activatedSignal" ) :
self.__widgetActivatedConnection = newWidget.activatedSignal().connect(
Gaffer.WeakMethod( self.__activated ), scoped = True
)
else :
self.__widgetActivatedConnection = None

def __activated( self, unused ) :

self.close()

@classmethod
def __firstTextWidget( cls, plugValueWidget ) :

Expand All @@ -165,13 +179,11 @@ def widgetUsable( w ) :

widget = None

if isinstance( plugValueWidget, GafferUI.StringPlugValueWidget ) :
widget = plugValueWidget.textWidget()
elif isinstance( plugValueWidget, GafferUI.NumericPlugValueWidget ) :
if isinstance( plugValueWidget, GafferUI.NumericPlugValueWidget ) :
widget = plugValueWidget.numericWidget()
elif isinstance( plugValueWidget, GafferUI.PathPlugValueWidget ) :
widget = plugValueWidget.pathWidget()
elif isinstance( plugValueWidget, GafferUI.MultiLineStringPlugValueWidget ) :
elif hasattr( plugValueWidget, "textWidget" ) :
widget = plugValueWidget.textWidget()

if widget is not None and widgetUsable( widget ) :
Expand Down

0 comments on commit 4a8f20e

Please sign in to comment.