<s> import functools <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class NodeEditor ( GafferUI . NodeSetEditor ) : <EOL> def __init__ ( self , scriptNode , parenting = None ) : <EOL> self . __column = GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Vertical ) <EOL> GafferUI . NodeSetEditor . __init__ ( self , self . __column , scriptNode , parenting = parenting ) <EOL> self . __nodeUI = None <EOL> self . __nameWidget = None <EOL> self . __readOnly = False <EOL> self . _updateFromSet ( ) <EOL> def nodeUI ( self ) : <EOL> self . _doPendingUpdate ( ) <EOL> return self . __nodeUI <EOL> def setReadOnly ( self , readOnly ) : <EOL> if readOnly == self . __readOnly : <EOL> return <EOL> self . __readOnly = readOnly <EOL> if self . __nodeUI is not None : <EOL> self . __nodeUI . setReadOnly ( readOnly ) <EOL> self . __nameWidget . setEditable ( not readOnly ) <EOL> def getReadOnly ( self ) : <EOL> return self . __readOnly <EOL> __toolMenuSignal = Gaffer . Signal3 ( ) <EOL> @ classmethod <EOL> def toolMenuSignal ( cls ) : <EOL> return cls . __toolMenuSignal <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def _updateFromSet ( self ) : <EOL> GafferUI . NodeSetEditor . _updateFromSet ( self ) <EOL> del self . __column [ : ] <EOL> self . __nodeUI = None <EOL> self . __nameWidget = None <EOL> node = self . _lastAddedNode ( ) <EOL> if not node : <EOL> return <EOL> with self . __column : <EOL> with GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , borderWidth = <NUM_LIT:8> , spacing = <NUM_LIT:4> ) : <EOL> GafferUI . Label ( "<STR_LIT>" ) <EOL> self . __nameWidget = GafferUI . NameWidget ( node ) <EOL> self . __nameWidget . setEditable ( not self . getReadOnly ( ) ) <EOL> with GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> ) as infoSection : <EOL> GafferUI . Label ( "<STR_LIT>" + node . typeName ( ) . rpartition ( "<STR_LIT::>" ) [ - <NUM_LIT:1> ] + "<STR_LIT>" ) <EOL> button = GafferUI . Button ( image = "<STR_LIT>" , hasFrame = False ) <EOL> url = Gaffer . Metadata . nodeValue ( node , "<STR_LIT>" ) <EOL> if url : <EOL> button . clickedSignal ( ) . connect ( <EOL> lambda button : GafferUI . showURL ( url ) , <EOL> scoped = False <EOL> ) <EOL> toolTip = "<STR_LIT>" + node . typeName ( ) . rpartition ( "<STR_LIT::>" ) [ <NUM_LIT:2> ] + "<STR_LIT>" <EOL> description = Gaffer . Metadata . nodeDescription ( node ) <EOL> if description : <EOL> toolTip += "<STR_LIT>" + description <EOL> infoSection . setToolTip ( toolTip ) <EOL> GafferUI . MenuButton ( <EOL> image = "<STR_LIT>" , <EOL> hasFrame = False , <EOL> menu = GafferUI . Menu ( Gaffer . WeakMethod ( self . __menuDefinition ) ) <EOL> ) <EOL> frame = GafferUI . Frame ( borderStyle = GafferUI . Frame . BorderStyle . None , borderWidth = <NUM_LIT:0> ) <EOL> self . __column . append ( frame , expand = True ) <EOL> self . __nodeUI = GafferUI . NodeUI . create ( node ) <EOL> self . __nodeUI . setReadOnly ( self . getReadOnly ( ) ) <EOL> frame . setChild ( self . __nodeUI ) <EOL> def _titleFormat ( self ) : <EOL> return GafferUI . NodeSetEditor . _titleFormat ( self , _maxNodes = <NUM_LIT:1> , _reverseNodes = True , _ellipsis = False ) <EOL> def __menuDefinition ( self ) : <EOL> result = IECore . MenuDefinition ( ) <EOL> url = Gaffer . Metadata . nodeValue ( self . nodeUI ( ) . node ( ) , "<STR_LIT>" ) <EOL> result . append ( <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : bool ( url ) , <EOL> "<STR_LIT>" : functools . partial ( GafferUI . showURL , url ) , <EOL> } <EOL> ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> result . append ( <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : Gaffer . WeakMethod ( self . __revertToDefaults ) , <EOL> } <EOL> ) <EOL> self . toolMenuSignal ( ) ( self , self . nodeUI ( ) . node ( ) , result ) <EOL> return result <EOL> def __revertToDefaults ( self ) : <EOL> def applyDefaults ( graphComponent ) : <EOL> if isinstance ( graphComponent , Gaffer . Plug ) : <EOL> plug = graphComponent <EOL> if plug . direction ( ) == plug . Direction . Out : <EOL> return <EOL> if plug . isSame ( plug . node ( ) [ "<STR_LIT:user>" ] ) : <EOL> return <EOL> elif plug . getName ( ) . startswith ( "<STR_LIT>" ) : <EOL> return <EOL> if isinstance ( plug , Gaffer . ValuePlug ) : <EOL> if plug . settable ( ) : <EOL> plug . setToDefault ( ) <EOL> return <EOL> for c in graphComponent . children ( Gaffer . Plug ) : <EOL> applyDefaults ( c ) <EOL> node = self . nodeUI ( ) . node ( ) <EOL> with Gaffer . UndoContext ( node . ancestor ( Gaffer . ScriptNode ) ) : <EOL> applyDefaults ( node ) <EOL> Gaffer . NodeAlgo . applyUserDefaults ( node ) <EOL> GafferUI . EditorWidget . registerType ( "<STR_LIT>" , NodeEditor ) </s>
