From 77300d4c5fbbda9c49ce0a55964ad9f0fe0fdb50 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 17 Sep 2024 17:50:41 +0100 Subject: [PATCH] NameWidget : Improve validator - Allow ':', since that has been allowed at the API level since 1.3.0.0. - Automatically convert all invalid characters to `_`. This allows anything to be copy-pasted into the field, whereas before anything with an invalid character was rejected. --- Changes.md | 5 +++++ python/GafferUI/NameWidget.py | 9 ++++----- src/Gaffer/GraphComponent.cpp | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Changes.md b/Changes.md index cb5d0e40d44..76ea79976a9 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,11 @@ 1.4.x.x (relative to 1.4.12.0) ======= +Improvements +------------ + +- NodeEditor, NameWidget : Invalid characters are automatically converted to `_` when renaming a node or plug, and `:` is no longer treated as invalid. + Fixes ----- diff --git a/python/GafferUI/NameWidget.py b/python/GafferUI/NameWidget.py index 950070522d9..ca0289dbdff 100644 --- a/python/GafferUI/NameWidget.py +++ b/python/GafferUI/NameWidget.py @@ -125,18 +125,17 @@ def __plugMetadataChanged( self, plug, key, reason ) : class _Validator( QtGui.QValidator ) : + __invalidCharacters = re.compile( "[^A-Za-z_:0-9]" ) + def __init__( self, parent ) : QtGui.QValidator.__init__( self, parent ) def validate( self, input, pos ) : - input = input.replace( " ", "_" ) + input = self.__invalidCharacters.sub( "_", input ) if len( input ) : - if re.match( "^(?!__)[A-Za-z_]+[A-Za-z_0-9]*$", input ) : - result = QtGui.QValidator.Acceptable - else : - result = QtGui.QValidator.Invalid + result = QtGui.QValidator.Acceptable else : result = QtGui.QValidator.Intermediate diff --git a/src/Gaffer/GraphComponent.cpp b/src/Gaffer/GraphComponent.cpp index 86d258c5779..e16b9a338bf 100644 --- a/src/Gaffer/GraphComponent.cpp +++ b/src/Gaffer/GraphComponent.cpp @@ -69,6 +69,7 @@ namespace /// \todo Relax restrictions to only disallow '.' and `/'? We originally had /// these strict requirements because we accessed GraphComponent children /// as attributes in Python, but that approach has long since gone. +/// When doing this, also update the validator in NameWidget. bool validName( const std::string &name ) { if( name.empty() )