From 4a8f20e50d83565f382fa1939e4876442153577a Mon Sep 17 00:00:00 2001
From: Murray Stevenson <50844517+murraystevenson@users.noreply.github.com>
Date: Tue, 28 May 2024 14:18:10 -0700
Subject: [PATCH] PlugPopup : Improve handling of textWidgets
Look for `textWidget()` attr rather than specific classes, so we can find `GafferSceneUI.SetExpressionPlugValueWidget`. Connect to `activatedSignal()` so we can close automatically when Ctrl+Enter is pressed in MultiLineTextWidgets.
---
python/GafferUI/PlugPopup.py | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/python/GafferUI/PlugPopup.py b/python/GafferUI/PlugPopup.py
index e26c2444e8a..00ec5938ed8 100644
--- a/python/GafferUI/PlugPopup.py
+++ b/python/GafferUI/PlugPopup.py
@@ -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 ) :
@@ -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 ) :
@@ -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 ) :