Skip to content

Commit

Permalink
Merge pull request #6046 from johnhaddon/nameWidgetValidator
Browse files Browse the repository at this point in the history
NameWidget : Improve validator
  • Loading branch information
ericmehl committed Sep 18, 2024
2 parents f383398 + 77300d4 commit cbd8e39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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
-----

Expand Down
9 changes: 4 additions & 5 deletions python/GafferUI/NameWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Gaffer/GraphComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down

0 comments on commit cbd8e39

Please sign in to comment.