<s> import weakref <EOL> import functools <EOL> import types <EOL> import re <EOL> import collections <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class UIEditor ( GafferUI . NodeSetEditor ) : <EOL> def __init__ ( self , scriptNode , parenting = None ) : <EOL> self . __frame = GafferUI . Frame ( borderWidth = <NUM_LIT:4> , borderStyle = GafferUI . Frame . BorderStyle . None ) <EOL> GafferUI . NodeSetEditor . __init__ ( self , self . __frame , scriptNode , parenting = parenting ) <EOL> self . __nodeMetadataWidgets = [ ] <EOL> self . __plugMetadataWidgets = [ ] <EOL> with self . __frame : <EOL> self . __tabbedContainer = GafferUI . TabbedContainer ( ) <EOL> with self . __tabbedContainer : <EOL> with GafferUI . ListContainer ( spacing = <NUM_LIT:4> , borderWidth = <NUM_LIT:8> , parenting = { "<STR_LIT:label>" : "<STR_LIT>" } ) as self . __nodeTab : <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT:Name>" ) <EOL> self . __nodeNameWidget = GafferUI . NameWidget ( None ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" , parenting = { "<STR_LIT>" : GafferUI . ListContainer . VerticalAlignment . Top } ) <EOL> self . __nodeMetadataWidgets . append ( <EOL> _MultiLineStringMetadataWidget ( key = "<STR_LIT:description>" ) <EOL> ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __nodeMetadataWidgets . append ( <EOL> _ColorSwatchMetadataWidget ( key = "<STR_LIT>" ) <EOL> ) <EOL> with GafferUI . SplitContainer ( orientation = GafferUI . SplitContainer . Orientation . Horizontal , borderWidth = <NUM_LIT:8> , parenting = { "<STR_LIT:label>" : "<STR_LIT>" } ) as self . __plugTab : <EOL> self . __plugListing = _PlugListing ( ) <EOL> self . __plugListingSelectionChangedConnection = self . __plugListing . selectionChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __plugListingSelectionChanged ) ) <EOL> with GafferUI . TabbedContainer ( ) as self . __plugAndSectionEditorsContainer : <EOL> self . __plugEditor = _PlugEditor ( ) <EOL> self . __sectionEditor = _SectionEditor ( ) <EOL> self . __sectionEditorNameChangedConnection = self . __sectionEditor . nameChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __sectionEditorNameChanged ) ) <EOL> self . __plugAndSectionEditorsContainer . setTabsVisible ( False ) <EOL> self . __plugTab . setSizes ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . __node = None <EOL> self . __selectedPlug = None <EOL> self . __updateFromSetInternal ( lazy = False ) <EOL> def setSelection ( self , selection ) : <EOL> self . __plugListing . setSelection ( selection ) <EOL> def getSelection ( self ) : <EOL> return self . __plugListing . getSelection ( ) <EOL> def nodeEditor ( self ) : <EOL> return self . __nodeTab <EOL> def plugEditor ( self ) : <EOL> return self . __plugTab <EOL> @ classmethod <EOL> def appendNodeContextMenuDefinitions ( cls , nodeGraph , node , menuDefinition ) : <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( cls . __setColor , node = node ) } ) <EOL> @ classmethod <EOL> def appendNodeEditorToolMenuDefinitions ( cls , nodeEditor , node , menuDefinition ) : <EOL> menuDefinition . append ( <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : functools . partial ( GafferUI . UIEditor . acquire , node ) , <EOL> "<STR_LIT>" : isinstance ( node , Gaffer . Box ) or nodeEditor . nodeUI ( ) . plugValueWidget ( node [ "<STR_LIT:user>" ] ) is not None <EOL> } <EOL> ) <EOL> def _updateFromSet ( self ) : <EOL> GafferUI . NodeSetEditor . _updateFromSet ( self ) <EOL> self . __updateFromSetInternal ( ) <EOL> def __updateFromSetInternal ( self , lazy = True ) : <EOL> node = self . _lastAddedNode ( ) <EOL> if lazy and node == self . __node : <EOL> return <EOL> self . __node = node <EOL> self . __nodeNameWidget . setGraphComponent ( self . __node ) <EOL> self . __nodeTab . setEnabled ( self . __node is not None ) <EOL> if self . __node is None : <EOL> self . __plugListing . setPlugParent ( None ) <EOL> self . __sectionEditor . setPlugParent ( None ) <EOL> else : <EOL> plugParent = self . __node [ "<STR_LIT:user>" ] <EOL> if isinstance ( self . __node , Gaffer . Box ) : <EOL> plugParent = self . __node <EOL> self . __plugListing . setPlugParent ( plugParent ) <EOL> self . __sectionEditor . setPlugParent ( plugParent ) <EOL> for widget in self . __nodeMetadataWidgets : <EOL> widget . setTarget ( self . __node ) <EOL> self . setSelection ( None ) <EOL> def __plugListingSelectionChanged ( self , listing ) : <EOL> selection = listing . getSelection ( ) <EOL> if selection is None or isinstance ( selection , Gaffer . Plug ) : <EOL> self . __plugEditor . setPlug ( selection ) <EOL> self . __plugAndSectionEditorsContainer . setCurrent ( self . __plugEditor ) <EOL> elif isinstance ( selection , basestring ) : <EOL> self . __plugEditor . setPlug ( None ) <EOL> self . __sectionEditor . setSection ( selection ) <EOL> self . __plugAndSectionEditorsContainer . setCurrent ( self . __sectionEditor ) <EOL> def __sectionEditorNameChanged ( self , sectionEditor , oldName , newName ) : <EOL> self . __plugListing . setSelection ( newName ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> @ classmethod <EOL> def __setColor ( cls , menu , node ) : <EOL> color = Gaffer . Metadata . nodeValue ( node , "<STR_LIT>" ) or IECore . Color3f ( <NUM_LIT:1> ) <EOL> dialogue = GafferUI . ColorChooserDialogue ( color = color , useDisplayTransform = False ) <EOL> color = dialogue . waitForColor ( parentWindow = menu . ancestor ( GafferUI . Window ) ) <EOL> if color is not None : <EOL> with Gaffer . UndoContext ( node . ancestor ( Gaffer . ScriptNode ) ) : <EOL> Gaffer . Metadata . registerNodeValue ( node , "<STR_LIT>" , color ) <EOL> GafferUI . EditorWidget . registerType ( "<STR_LIT>" , UIEditor ) <EOL> def __editPlugUI ( node , plug ) : <EOL> editor = GafferUI . UIEditor . acquire ( node ) <EOL> editor . setSelection ( plug ) <EOL> editor . plugEditor ( ) . reveal ( ) <EOL> def __plugPopupMenu ( menuDefinition , plugValueWidget ) : <EOL> plug = plugValueWidget . getPlug ( ) <EOL> node = plug . node ( ) <EOL> if node is None : <EOL> return <EOL> if isinstance ( node , Gaffer . Box ) : <EOL> if not plug . parent ( ) . isSame ( node ) : <EOL> return <EOL> else : <EOL> if not plug . parent ( ) . isSame ( node [ "<STR_LIT:user>" ] ) : <EOL> return <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( __editPlugUI , node , plug ) , "<STR_LIT>" : not plugValueWidget . getReadOnly ( ) } ) <EOL> __plugPopupMenuConnection = GafferUI . PlugValueWidget . popupMenuSignal ( ) . connect ( __plugPopupMenu ) <EOL> class _Label ( GafferUI . Label ) : <EOL> def __init__ ( self , * args , ** kw ) : <EOL> GafferUI . Label . __init__ ( <EOL> self , <EOL> horizontalAlignment = GafferUI . Label . HorizontalAlignment . Right , <EOL> * args , ** kw <EOL> ) <EOL> self . _qtWidget ( ) . setFixedWidth ( <NUM_LIT> ) <EOL> class _Row ( GafferUI . ListContainer ) : <EOL> def __init__ ( self , * args , ** kw ) : <EOL> GafferUI . ListContainer . __init__ ( self , GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> , * args , ** kw ) <EOL> class _MetadataWidget ( GafferUI . Widget ) : <EOL> def __init__ ( self , topLevelWidget , key , target = None , parenting = None ) : <EOL> GafferUI . Widget . __init__ ( self , topLevelWidget , parenting = parenting ) <EOL> self . __key = key <EOL> self . __target = None <EOL> self . setTarget ( target ) <EOL> def setTarget ( self , target ) : <EOL> assert ( isinstance ( target , ( Gaffer . Node , Gaffer . Plug , type ( None ) ) ) ) <EOL> self . __target = target <EOL> self . setEnabled ( self . __target is not None ) <EOL> if isinstance ( self . __target , Gaffer . Node ) : <EOL> self . __metadataChangedConnection = Gaffer . Metadata . nodeValueChangedSignal ( ) . connect ( <EOL> Gaffer . WeakMethod ( self . __nodeMetadataChanged ) <EOL> ) <EOL> elif isinstance ( self . __target , Gaffer . Plug ) : <EOL> self . __metadataChangedConnection = Gaffer . Metadata . plugValueChangedSignal ( ) . connect ( <EOL> Gaffer . WeakMethod ( self . __plugMetadataChanged ) <EOL> ) <EOL> else : <EOL> self . __metadataChangedConnection = None <EOL> self . __update ( ) <EOL> def getTarget ( self ) : <EOL> return self . __target <EOL> def setKey ( self , key ) : <EOL> if key == self . __key : <EOL> return <EOL> self . __key = key <EOL> self . __update ( ) <EOL> def getKey ( self , key ) : <EOL> return self . __key <EOL> def _updateFromValue ( self , value ) : <EOL> raise NotImplementedError <EOL> def _updateFromWidget ( self , value ) : <EOL> if self . __target is None : <EOL> return <EOL> with Gaffer . UndoContext ( self . __target . ancestor ( Gaffer . ScriptNode ) ) : <EOL> _registerMetadata ( self . __target , self . __key , value ) <EOL> def _deregisterValue ( self ) : <EOL> if self . __target is None : <EOL> return <EOL> with Gaffer . UndoContext ( self . __target . ancestor ( Gaffer . ScriptNode ) ) : <EOL> _deregisterMetadata ( self . __target , self . __key ) <EOL> def __update ( self ) : <EOL> if isinstance ( self . __target , Gaffer . Node ) : <EOL> self . _updateFromValue ( Gaffer . Metadata . nodeValue ( self . __target , self . __key ) ) <EOL> elif isinstance ( self . __target , Gaffer . Plug ) : <EOL> self . _updateFromValue ( Gaffer . Metadata . plugValue ( self . __target , self . __key ) ) <EOL> else : <EOL> self . _updateFromValue ( None ) <EOL> def __nodeMetadataChanged ( self , nodeTypeId , key , node ) : <EOL> if self . __key != key : <EOL> return <EOL> if node is not None and not node . isSame ( self . __target ) : <EOL> return <EOL> if not self . __target . isInstanceOf ( nodeTypeId ) : <EOL> return <EOL> self . __update ( ) <EOL> def __plugMetadataChanged ( self , nodeTypeId , plugPath , key , plug ) : <EOL> if self . __key != key : <EOL> return <EOL> if plug is not None and not plug . isSame ( self . __target ) : <EOL> return <EOL> if not self . __target . node ( ) . isInstanceOf ( nodeTypeId ) : <EOL> return <EOL> if not Gaffer . match ( self . __target . relativeName ( self . __target . node ( ) ) , plugPath ) : <EOL> return <EOL> self . __update ( ) <EOL> class _BoolMetadataWidget ( _MetadataWidget ) : <EOL> def __init__ ( self , key , target = None , parenting = None ) : <EOL> self . __boolWidget = GafferUI . BoolWidget ( ) <EOL> _MetadataWidget . __init__ ( self , self . __boolWidget , key , target , parenting = parenting ) <EOL> self . __stateChangedConnection = self . __boolWidget . stateChangedSignal ( ) . connect ( <EOL> Gaffer . WeakMethod ( self . __stateChanged ) <EOL> ) <EOL> def _updateFromValue ( self , value ) : <EOL> self . __boolWidget . setState ( value if value is not None else False ) <EOL> def __stateChanged ( self , * unused ) : <EOL> self . _updateFromWidget ( self . __boolWidget . getState ( ) ) <EOL> class _StringMetadataWidget ( _MetadataWidget ) : <EOL> def __init__ ( self , key , target = None , acceptEmptyString = True , parenting = None ) : <EOL> self . __textWidget = GafferUI . TextWidget ( ) <EOL> _MetadataWidget . __init__ ( self , self . __textWidget , key , target , parenting = None ) <EOL> self . __acceptEmptyString = acceptEmptyString <EOL> self . __editingFinishedConnection = self . __textWidget . editingFinishedSignal ( ) . connect ( <EOL> Gaffer . WeakMethod ( self . __editingFinished ) <EOL> ) <EOL> def textWidget ( self ) : <EOL> return self . __textWidget <EOL> def _updateFromValue ( self , value ) : <EOL> self . __textWidget . setText ( value if value is not None else "<STR_LIT>" ) <EOL> def __editingFinished ( self , * unused ) : <EOL> text = self . __textWidget . getText ( ) <EOL> if text or self . __acceptEmptyString : <EOL> self . _updateFromWidget ( text ) <EOL> else : <EOL> self . _deregisterValue ( ) <EOL> class _MultiLineStringMetadataWidget ( _MetadataWidget ) : <EOL> def __init__ ( self , key , target = None , parenting = None ) : <EOL> self . __textWidget = GafferUI . MultiLineTextWidget ( ) <EOL> _MetadataWidget . __init__ ( self , self . __textWidget , key , target , parenting = None ) <EOL> self . __editingFinishedConnection = self . __textWidget . editingFinishedSignal ( ) . connect ( <EOL> Gaffer . WeakMethod ( self . __editingFinished ) <EOL> ) <EOL> def textWidget ( self ) : <EOL> return self . __textWidget <EOL> def _updateFromValue ( self , value ) : <EOL> self . __textWidget . setText ( value if value is not None else "<STR_LIT>" ) <EOL> def __editingFinished ( self , * unused ) : <EOL> self . _updateFromWidget ( self . __textWidget . getText ( ) ) <EOL> class _ColorSwatchMetadataWidget ( _MetadataWidget ) : <EOL> def __init__ ( self , key , target = None , parenting = None ) : <EOL> self . __swatch = GafferUI . ColorSwatch ( useDisplayTransform = False ) <EOL> _MetadataWidget . __init__ ( self , self . __swatch , key , target , parenting = parenting ) <EOL> self . __swatch . _qtWidget ( ) . setFixedHeight ( <NUM_LIT> ) <EOL> self . __swatch . _qtWidget ( ) . setMaximumWidth ( <NUM_LIT> ) <EOL> self . __value = None <EOL> self . __buttonReleaseConnection = self . __swatch . buttonReleaseSignal ( ) . connect ( Gaffer . WeakMethod ( self . __buttonRelease ) ) <EOL> def _updateFromValue ( self , value ) : <EOL> if value is not None : <EOL> self . __swatch . setColor ( value ) <EOL> else : <EOL> self . __swatch . setColor ( IECore . Color4f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . __value = value <EOL> def __buttonRelease ( self , swatch , event ) : <EOL> if event . button != event . Buttons . Left : <EOL> return False <EOL> color = self . __value if self . __value is not None else IECore . Color3f ( <NUM_LIT:1> ) <EOL> dialogue = GafferUI . ColorChooserDialogue ( color = color , useDisplayTransform = False ) <EOL> color = dialogue . waitForColor ( parentWindow = self . ancestor ( GafferUI . Window ) ) <EOL> if color is not None : <EOL> self . _updateFromWidget ( color ) <EOL> class _MenuMetadataWidget ( _MetadataWidget ) : <EOL> def __init__ ( self , key , labelsAndValues , target = None , parenting = None ) : <EOL> self . __menuButton = GafferUI . MenuButton ( <EOL> menu = GafferUI . Menu ( Gaffer . WeakMethod ( self . __menuDefinition ) ) <EOL> ) <EOL> self . __labelsAndValues = labelsAndValues <EOL> self . __currentValue = None <EOL> _MetadataWidget . __init__ ( self , self . __menuButton , key , target , parenting = parenting ) <EOL> def _updateFromValue ( self , value ) : <EOL> self . __currentValue = value <EOL> buttonText = str ( value ) <EOL> for label , value in self . __labelsAndValues : <EOL> if value == self . __currentValue : <EOL> buttonText = label <EOL> break <EOL> self . __menuButton . setText ( buttonText ) <EOL> def __menuDefinition ( self ) : <EOL> result = IECore . MenuDefinition ( ) <EOL> for label , value in self . __labelsAndValues : <EOL> result . append ( <EOL> "<STR_LIT:/>" + label , <EOL> { <EOL> "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __setValue ) , value = value ) , <EOL> "<STR_LIT>" : value == self . __currentValue <EOL> } <EOL> ) <EOL> return result <EOL> def __setValue ( self , unused , value ) : <EOL> self . _updateFromWidget ( value ) <EOL> class _LayoutItem ( object ) : <EOL> def __init__ ( self ) : <EOL> self . __parent = None <EOL> self . __children = [ ] <EOL> def parent ( self ) : <EOL> if self . __parent is None : <EOL> return None <EOL> else : <EOL> return self . __parent ( ) <EOL> def child ( self , name ) : <EOL> for c in self . __children : <EOL> if c . name ( ) == name : <EOL> return c <EOL> return None <EOL> def isAncestorOf ( self , item ) : <EOL> while item is not None : <EOL> parent = item . parent ( ) <EOL> if parent is self : <EOL> return True <EOL> item = parent <EOL> return False <EOL> def append ( self , child ) : <EOL> self . insert ( len ( self ) , child ) <EOL> def insert ( self , index , child ) : <EOL> assert ( child . parent ( ) is None ) <EOL> self . __children . insert ( index , child ) <EOL> child . __parent = weakref . ref ( self ) <EOL> def remove ( self , child ) : <EOL> assert ( child . parent ( ) is self ) <EOL> self . __children . remove ( child ) <EOL> child . __parent = None <EOL> def index ( self , child ) : <EOL> return self . __children . index ( child ) <EOL> def name ( self ) : <EOL> raise NotImplementedError <EOL> def fullName ( self ) : <EOL> result = "<STR_LIT>" <EOL> item = self <EOL> while item . parent ( ) is not None : <EOL> if result : <EOL> result = item . name ( ) + "<STR_LIT:.>" + result <EOL> else : <EOL> result = item . name ( ) <EOL> item = item . parent ( ) <EOL> return result <EOL> def __len__ ( self ) : <EOL> return len ( self . __children ) <EOL> def __getitem__ ( self , index ) : <EOL> return self . __children [ index ] <EOL> class _SectionLayoutItem ( _LayoutItem ) : <EOL> def __init__ ( self , sectionName ) : <EOL> _LayoutItem . __init__ ( self ) <EOL> self . __sectionName = sectionName <EOL> def name ( self ) : <EOL> return self . __sectionName <EOL> class _PlugLayoutItem ( _LayoutItem ) : <EOL> def __init__ ( self , plug ) : <EOL> _LayoutItem . __init__ ( self ) <EOL> self . plug = plug <EOL> self . __name = plug . getName ( ) <EOL> def name ( self ) : <EOL> return self . __name <EOL> class _PlugListing ( GafferUI . Widget ) : <EOL> class __LayoutPath ( Gaffer . Path ) : <EOL> def __init__ ( self , rootItem , path , root = "<STR_LIT:/>" , filter = None ) : <EOL> Gaffer . Path . __init__ ( self , path , root , filter ) <EOL> self . __rootItem = rootItem <EOL> def rootItem ( self ) : <EOL> return self . __rootItem <EOL> def item ( self ) : <EOL> result = self . __rootItem <EOL> for name in self : <EOL> result = result . child ( name ) <EOL> if result is None : <EOL> return None <EOL> return result <EOL> def copy ( self ) : <EOL> return self . __class__ ( self . __rootItem , self [ : ] , self . root ( ) , self . getFilter ( ) ) <EOL> def isLeaf ( self ) : <EOL> return not isinstance ( self . item ( ) , _SectionLayoutItem ) <EOL> def isValid ( self ) : <EOL> return self . item ( ) is not None <EOL> def _children ( self ) : <EOL> item = self . item ( ) <EOL> if item is None : <EOL> return [ ] <EOL> result = [ <EOL> self . __class__ ( self . __rootItem , self [ : ] + [ c . name ( ) ] , self . root ( ) , self . getFilter ( ) ) <EOL> for c in item <EOL> ] <EOL> if len ( result ) == <NUM_LIT:0> and isinstance ( item , _SectionLayoutItem ) : <EOL> result . append ( self . __class__ ( self . __rootItem , self [ : ] + [ "<STR_LIT:U+0020>" ] , self . root ( ) , self . getFilter ( ) ) ) <EOL> return result <EOL> def __init__ ( self , parenting = None ) : <EOL> column = GafferUI . ListContainer ( spacing = <NUM_LIT:4> ) <EOL> GafferUI . Widget . __init__ ( self , column , parenting = parenting ) <EOL> with column : <EOL> self . __pathListing = GafferUI . PathListingWidget ( <EOL> self . __LayoutPath ( _SectionLayoutItem ( "<STR_LIT>" ) , "<STR_LIT:/>" ) , <EOL> columns = ( GafferUI . PathListingWidget . defaultNameColumn , ) , <EOL> displayMode = GafferUI . PathListingWidget . DisplayMode . Tree , <EOL> ) <EOL> self . __pathListing . setDragPointer ( "<STR_LIT>" ) <EOL> self . __pathListing . setSortable ( False ) <EOL> self . __pathListing . setHeaderVisible ( False ) <EOL> with GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> ) : <EOL> GafferUI . MenuButton ( <EOL> image = "<STR_LIT>" , <EOL> hasFrame = False , <EOL> menu = GafferUI . Menu ( <EOL> definition = Gaffer . WeakMethod ( self . __addMenuDefinition ) <EOL> ) <EOL> ) <EOL> self . __deleteButton = GafferUI . Button ( image = "<STR_LIT>" , hasFrame = False ) <EOL> self . __deleteButtonClickedConnection = self . __deleteButton . clickedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __deleteButtonClicked ) ) <EOL> self . __parent = None <EOL> self . __dragItem = None <EOL> self . __selectionChangedSignal = Gaffer . Signal1 ( ) <EOL> self . __dragEnterConnection = self . __pathListing . dragEnterSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragEnter ) ) <EOL> self . __dragMoveConnection = self . __pathListing . dragMoveSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragMove ) ) <EOL> self . __dragEndConnection = self . __pathListing . dragEndSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragEnd ) ) <EOL> self . __selectionChangedConnection = self . __pathListing . selectionChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __selectionChanged ) ) <EOL> self . __keyPressConnection = self . keyPressSignal ( ) . connect ( Gaffer . WeakMethod ( self . __keyPress ) ) <EOL> self . __nodeMetadataChangedConnection = Gaffer . Metadata . nodeValueChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __nodeMetadataChanged ) ) <EOL> self . __plugMetadataChangedConnection = Gaffer . Metadata . plugValueChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __plugMetadataChanged ) ) <EOL> def setPlugParent ( self , parent ) : <EOL> assert ( isinstance ( parent , ( Gaffer . Plug , Gaffer . Node , types . NoneType ) ) ) <EOL> self . __parent = parent <EOL> self . __childAddedConnection = None <EOL> self . __childRemovedConnection = None <EOL> self . __childNameChangedConnections = { } <EOL> if self . __parent is not None : <EOL> self . __childAddedConnection = self . __parent . childAddedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __childAddedOrRemoved ) ) <EOL> self . __childRemovedConnection = self . __parent . childRemovedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __childAddedOrRemoved ) ) <EOL> for child in self . __parent . children ( ) : <EOL> self . __updateChildNameChangedConnection ( child ) <EOL> self . __updatePath ( ) <EOL> def getPlugParent ( self ) : <EOL> return self . __parent <EOL> def setSelection ( self , selection ) : <EOL> self . __updatePathLazily . flush ( self ) <EOL> def findPlugPath ( path , plug ) : <EOL> item = path . item ( ) <EOL> if isinstance ( item , _PlugLayoutItem ) and item . plug . isSame ( plug ) : <EOL> return path <EOL> else : <EOL> for child in path . children ( ) : <EOL> r = findPlugPath ( child , plug ) <EOL> if r is not None : <EOL> return r <EOL> return None <EOL> if isinstance ( selection , Gaffer . Plug ) : <EOL> path = findPlugPath ( self . __pathListing . getPath ( ) , selection ) <EOL> if path is None : <EOL> self . __pathListing . setSelectedPaths ( [ ] ) <EOL> else : <EOL> self . __pathListing . setSelectedPaths ( [ path ] ) <EOL> elif isinstance ( selection , basestring ) : <EOL> path = self . __pathListing . getPath ( ) . copy ( ) <EOL> path [ : ] = selection . split ( "<STR_LIT:.>" ) <EOL> self . __pathListing . setSelectedPaths ( [ path ] ) <EOL> else : <EOL> assert ( selection is None ) <EOL> self . __pathListing . setSelectedPaths ( [ ] ) <EOL> def getSelection ( self ) : <EOL> item = self . __selectedItem ( ) <EOL> if item is None : <EOL> return None <EOL> elif isinstance ( item , _PlugLayoutItem ) : <EOL> return item . plug <EOL> elif isinstance ( item , _SectionLayoutItem ) : <EOL> return item . fullName ( ) <EOL> else : <EOL> return None <EOL> def selectionChangedSignal ( self ) : <EOL> return self . __selectionChangedSignal <EOL> def __updatePath ( self ) : <EOL> if self . __parent is None : <EOL> self . __pathListing . setPath ( self . __LayoutPath ( _SectionLayoutItem ( "<STR_LIT>" ) , "<STR_LIT:/>" ) ) <EOL> return <EOL> def section ( rootLayoutItem , sectionPath ) : <EOL> sectionItem = rootLayoutItem <EOL> if sectionPath != "<STR_LIT>" : <EOL> for sectionName in sectionPath . split ( "<STR_LIT:.>" ) : <EOL> childSectionItem = sectionItem . child ( sectionName ) <EOL> if childSectionItem is None : <EOL> childSectionItem = _SectionLayoutItem ( sectionName ) <EOL> sectionItem . append ( childSectionItem ) <EOL> sectionItem = childSectionItem <EOL> return sectionItem <EOL> layout = _SectionLayoutItem ( "<STR_LIT>" ) <EOL> for sectionPath in GafferUI . PlugLayout . layoutSections ( self . __parent ) : <EOL> if sectionPath == "<STR_LIT>" and isinstance ( self . __parent , Gaffer . Node ) : <EOL> continue <EOL> sectionItem = section ( layout , sectionPath ) <EOL> for plug in GafferUI . PlugLayout . layoutOrder ( self . __parent , section = sectionPath ) : <EOL> sectionItem . append ( _PlugLayoutItem ( plug ) ) <EOL> emptySections = _metadata ( self . getPlugParent ( ) , "<STR_LIT>" ) <EOL> emptySectionIndices = _metadata ( self . getPlugParent ( ) , "<STR_LIT>" ) <EOL> if emptySections and emptySectionIndices : <EOL> for sectionPath , sectionIndex in zip ( emptySections , emptySectionIndices ) : <EOL> parentPath , unused , sectionName = sectionPath . rpartition ( "<STR_LIT:.>" ) <EOL> parentSection = section ( layout , parentPath ) <EOL> if parentSection . child ( sectionName ) is None : <EOL> parentSection . insert ( sectionIndex , _SectionLayoutItem ( sectionName ) ) <EOL> if len ( layout ) == <NUM_LIT:0> and isinstance ( self . __parent , Gaffer . Node ) : <EOL> layout . append ( _SectionLayoutItem ( "<STR_LIT>" ) ) <EOL> expandedPaths = self . __pathListing . getExpandedPaths ( ) <EOL> self . __pathListing . setPath ( self . __LayoutPath ( layout , "<STR_LIT:/>" ) ) <EOL> self . __pathListing . setExpandedPaths ( expandedPaths ) <EOL> @ GafferUI . LazyMethod ( ) <EOL> def __updatePathLazily ( self ) : <EOL> self . __updatePath ( ) <EOL> def __updateMetadata ( self ) : <EOL> emptySections = IECore . StringVectorData ( ) <EOL> emptySectionIndices = IECore . IntVectorData ( ) <EOL> def walk ( layoutItem , path = "<STR_LIT>" , index = <NUM_LIT:0> ) : <EOL> for childItem in layoutItem : <EOL> if isinstance ( childItem , _PlugLayoutItem ) : <EOL> Gaffer . Metadata . registerPlugValue ( childItem . plug , "<STR_LIT>" , path ) <EOL> Gaffer . Metadata . registerPlugValue ( childItem . plug , "<STR_LIT>" , index ) <EOL> index += <NUM_LIT:1> <EOL> elif isinstance ( childItem , _SectionLayoutItem ) : <EOL> childPath = path + "<STR_LIT:.>" + childItem . name ( ) if path else childItem . name ( ) <EOL> if len ( childItem ) : <EOL> index = walk ( childItem , childPath , index ) <EOL> else : <EOL> emptySections . append ( childPath ) <EOL> emptySectionIndices . append ( layoutItem . index ( childItem ) ) <EOL> return index <EOL> with Gaffer . BlockedConnection ( self . __plugMetadataChangedConnection ) : <EOL> walk ( self . __pathListing . getPath ( ) . copy ( ) . setFromString ( "<STR_LIT:/>" ) . item ( ) ) <EOL> _registerMetadata ( self . getPlugParent ( ) , "<STR_LIT>" , emptySections ) <EOL> _registerMetadata ( self . getPlugParent ( ) , "<STR_LIT>" , emptySectionIndices ) <EOL> def __childAddedOrRemoved ( self , parent , child ) : <EOL> assert ( parent . isSame ( self . __parent ) ) <EOL> self . __updateChildNameChangedConnection ( child ) <EOL> self . __updatePathLazily ( ) <EOL> def __childNameChanged ( self , child ) : <EOL> selection = self . getSelection ( ) <EOL> self . __updatePath ( ) <EOL> if isinstance ( selection , Gaffer . Plug ) and child . isSame ( selection ) : <EOL> self . setSelection ( selection ) <EOL> def __updateChildNameChangedConnection ( self , child ) : <EOL> if self . __parent . isSame ( child . parent ( ) ) : <EOL> if child not in self . __childNameChangedConnections : <EOL> self . __childNameChangedConnections [ child ] = child . nameChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __childNameChanged ) ) <EOL> else : <EOL> if child in self . __childNameChangedConnections : <EOL> del self . __childNameChangedConnections [ child ] <EOL> def __dragEnter ( self , listing , event ) : <EOL> if event . sourceWidget is not self . __pathListing : <EOL> return False <EOL> if not isinstance ( event . data , IECore . StringVectorData ) : <EOL> return False <EOL> dragPath = self . __pathListing . getPath ( ) . copy ( ) . setFromString ( event . data [ <NUM_LIT:0> ] ) <EOL> self . __dragItem = dragPath . item ( ) <EOL> self . __pathListing . setPathExpanded ( dragPath , False ) <EOL> return True <EOL> def __dragMove ( self , listing , event ) : <EOL> if self . __dragItem is None : <EOL> return False <EOL> targetPath = self . __pathListing . pathAt ( event . line . p0 ) <EOL> if targetPath is not None : <EOL> targetItem = targetPath . item ( ) <EOL> if targetItem is not None : <EOL> if isinstance ( targetItem , _SectionLayoutItem ) and self . __pathListing . getPathExpanded ( targetPath ) and targetItem . parent ( ) is self . __dragItem . parent ( ) : <EOL> newParent = targetItem <EOL> newIndex = <NUM_LIT:0> <EOL> else : <EOL> newParent = targetItem . parent ( ) <EOL> newIndex = newParent . index ( targetItem ) <EOL> else : <EOL> newParent = targetPath . copy ( ) . truncateUntilValid ( ) . item ( ) <EOL> newIndex = <NUM_LIT:0> <EOL> else : <EOL> newParent = self . __pathListing . getPath ( ) . rootItem ( ) <EOL> newIndex = <NUM_LIT:0> if event . line . p0 . y < <NUM_LIT:1> else len ( newParent ) <EOL> if newParent is self . __dragItem or self . __dragItem . isAncestorOf ( newParent ) : <EOL> return True <EOL> firstNonPlugIndex = next ( <EOL> ( x [ <NUM_LIT:0> ] for x in enumerate ( newParent ) if not isinstance ( x [ <NUM_LIT:1> ] , _PlugLayoutItem ) ) , <EOL> len ( newParent ) <EOL> ) <EOL> if self . __dragItem . parent ( ) is newParent and newParent . index ( self . __dragItem ) < firstNonPlugIndex : <EOL> firstNonPlugIndex -= <NUM_LIT:1> <EOL> if isinstance ( self . __dragItem , _PlugLayoutItem ) : <EOL> if newIndex > firstNonPlugIndex : <EOL> return True <EOL> else : <EOL> if newIndex < firstNonPlugIndex : <EOL> newIndex = max ( newIndex , firstNonPlugIndex ) <EOL> self . __dragItem . parent ( ) . remove ( self . __dragItem ) <EOL> newParent . insert ( newIndex , self . __dragItem ) <EOL> self . __pathListing . getPath ( ) . pathChangedSignal ( ) ( self . __pathListing . getPath ( ) ) <EOL> selection = self . __pathListing . getPath ( ) . copy ( ) <EOL> selection [ : ] = self . __dragItem . fullName ( ) . split ( "<STR_LIT:.>" ) <EOL> self . __pathListing . setSelectedPaths ( [ selection ] , scrollToFirst = False , expandNonLeaf = False ) <EOL> return True <EOL> def __dragEnd ( self , listing , event ) : <EOL> if self . __dragItem is None : <EOL> return False <EOL> with Gaffer . UndoContext ( self . __parent . ancestor ( Gaffer . ScriptNode ) ) : <EOL> self . __updateMetadata ( ) <EOL> self . __dragItem = None <EOL> return True <EOL> def __selectionChanged ( self , pathListing ) : <EOL> self . __deleteButton . setEnabled ( bool ( pathListing . getSelectedPaths ( ) ) ) <EOL> self . __selectionChangedSignal ( self ) <EOL> def __deleteButtonClicked ( self , button ) : <EOL> self . __deleteSelected ( ) <EOL> def __nodeMetadataChanged ( self , nodeTypeId , key , node ) : <EOL> if self . __parent is None : <EOL> return <EOL> if node is not None and not self . __parent . isSame ( node ) : <EOL> return <EOL> if not self . __parent . isInstanceOf ( nodeTypeId ) : <EOL> return <EOL> if key in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . __updatePathLazily ( ) <EOL> def __plugMetadataChanged ( self , nodeTypeId , plugPath , key , plug ) : <EOL> if self . __parent is None : <EOL> return <EOL> if plug is not None and not self . __parent . isSame ( plug ) and not self . __parent . isSame ( plug . parent ( ) ) : <EOL> return <EOL> node = self . __parent . node ( ) if isinstance ( self . __parent , Gaffer . Plug ) else self . __parent <EOL> if not node . isInstanceOf ( nodeTypeId ) : <EOL> return <EOL> if key in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . __updatePathLazily ( ) <EOL> def __keyPress ( self , widget , event ) : <EOL> assert ( widget is self ) <EOL> if event . key == "<STR_LIT>" or event . key == "<STR_LIT>" : <EOL> self . __deleteSelected ( ) <EOL> return True <EOL> return False <EOL> def __addMenuDefinition ( self ) : <EOL> m = IECore . MenuDefinition ( ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . BoolPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . FloatPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . IntPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . StringPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . V2iPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . V3iPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . V2fPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . V3fPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . Color3fPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __addPlug ) , Gaffer . Color4fPlug ) } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> m . append ( "<STR_LIT>" , { "<STR_LIT>" : Gaffer . WeakMethod ( self . __addSection ) } ) <EOL> return m <EOL> def __addPlug ( self , plugType ) : <EOL> plug = plugType ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> _registerMetadata ( plug , "<STR_LIT>" , "<STR_LIT>" ) <EOL> parentItem = self . __selectedItem ( ) <EOL> if parentItem is not None : <EOL> while not isinstance ( parentItem , _SectionLayoutItem ) : <EOL> parentItem = parentItem . parent ( ) <EOL> else : <EOL> parentItem = self . __pathListing . getPath ( ) . rootItem ( ) <EOL> parentItem = next ( <EOL> ( c for c in parentItem if isinstance ( c , _SectionLayoutItem ) ) , <EOL> parentItem <EOL> ) <EOL> _registerMetadata ( plug , "<STR_LIT>" , parentItem . fullName ( ) ) <EOL> with Gaffer . UndoContext ( self . __parent . ancestor ( Gaffer . ScriptNode ) ) : <EOL> self . getPlugParent ( ) . addChild ( plug ) <EOL> self . __updatePathLazily . flush ( self ) <EOL> self . setSelection ( plug ) <EOL> def __addSection ( self ) : <EOL> rootItem = self . __pathListing . getPath ( ) . rootItem ( ) <EOL> existingSectionNames = set ( c . name ( ) for c in rootItem if isinstance ( c , _SectionLayoutItem ) ) <EOL> name = "<STR_LIT>" <EOL> index = <NUM_LIT:1> <EOL> while name in existingSectionNames : <EOL> name = "<STR_LIT>" % index <EOL> index += <NUM_LIT:1> <EOL> rootItem . append ( _SectionLayoutItem ( name ) ) <EOL> self . __pathListing . getPath ( ) . pathChangedSignal ( ) ( self . __pathListing . getPath ( ) ) <EOL> with Gaffer . UndoContext ( self . __parent . ancestor ( Gaffer . ScriptNode ) ) : <EOL> self . __updateMetadata ( ) <EOL> self . __pathListing . setSelectedPaths ( <EOL> self . __pathListing . getPath ( ) . copy ( ) . setFromString ( "<STR_LIT:/>" + name ) <EOL> ) <EOL> def __selectedItem ( self ) : <EOL> selectedPaths = self . __pathListing . getSelectedPaths ( ) <EOL> if not len ( selectedPaths ) : <EOL> return None <EOL> assert ( len ( selectedPaths ) == <NUM_LIT:1> ) <EOL> return selectedPaths [ <NUM_LIT:0> ] . item ( ) <EOL> def __deleteSelected ( self ) : <EOL> selectedItem = self . __selectedItem ( ) <EOL> if selectedItem is None : <EOL> return <EOL> selectedItem . parent ( ) . remove ( selectedItem ) <EOL> def deletePlugsWalk ( item ) : <EOL> if isinstance ( item , _PlugLayoutItem ) : <EOL> item . plug . parent ( ) . removeChild ( item . plug ) <EOL> else : <EOL> for childItem in item : <EOL> deletePlugsWalk ( childItem ) <EOL> with Gaffer . UndoContext ( self . __parent . ancestor ( Gaffer . ScriptNode ) ) : <EOL> deletePlugsWalk ( selectedItem ) <EOL> self . __updateMetadata ( ) <EOL> class _PresetsEditor ( GafferUI . Widget ) : <EOL> def __init__ ( self , parenting = None ) : <EOL> row = GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:8> ) <EOL> GafferUI . Widget . __init__ ( self , row , parenting = parenting ) <EOL> with row : <EOL> with GafferUI . ListContainer ( spacing = <NUM_LIT:4> ) : <EOL> self . __pathListing = GafferUI . PathListingWidget ( <EOL> Gaffer . DictPath ( collections . OrderedDict ( ) , "<STR_LIT:/>" ) , <EOL> columns = ( GafferUI . PathListingWidget . defaultNameColumn , ) , <EOL> ) <EOL> self . __pathListing . setDragPointer ( "<STR_LIT>" ) <EOL> self . __pathListing . setSortable ( False ) <EOL> self . __pathListing . setHeaderVisible ( False ) <EOL> self . __pathListing . _qtWidget ( ) . setFixedWidth ( <NUM_LIT:200> ) <EOL> self . __pathListing . _qtWidget ( ) . setFixedHeight ( <NUM_LIT:200> ) <EOL> self . __pathListingSelectionChangedConnection = self . __pathListing . selectionChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __selectionChanged ) ) <EOL> self . __dragEnterConnection = self . __pathListing . dragEnterSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragEnter ) ) <EOL> self . __dragMoveConnection = self . __pathListing . dragMoveSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragMove ) ) <EOL> self . __dragEndConnection = self . __pathListing . dragEndSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragEnd ) ) <EOL> with GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> ) : <EOL> self . __addButton = GafferUI . Button ( image = "<STR_LIT>" , hasFrame = False ) <EOL> self . __addButtonClickedConnection = self . __addButton . clickedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __addButtonClicked ) ) <EOL> self . __deleteButton = GafferUI . Button ( image = "<STR_LIT>" , hasFrame = False ) <EOL> self . __deleteButtonClickedConnection = self . __deleteButton . clickedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __deleteButtonClicked ) ) <EOL> with GafferUI . ListContainer ( spacing = <NUM_LIT:4> ) as self . __editingColumn : <EOL> GafferUI . Label ( "<STR_LIT:Name>" ) <EOL> self . __nameWidget = GafferUI . TextWidget ( ) <EOL> self . __nameEditingFinishedConnection = self . __nameWidget . editingFinishedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __nameEditingFinished ) ) <EOL> GafferUI . Spacer ( IECore . V2i ( <NUM_LIT:4> ) , maximumSize = IECore . V2i ( <NUM_LIT:4> ) ) <EOL> GafferUI . Label ( "<STR_LIT>" ) <EOL> self . __valueNode = Gaffer . Node ( "<STR_LIT>" ) <EOL> self . __valuePlugSetConnection = self . __valueNode . plugSetSignal ( ) . connect ( Gaffer . WeakMethod ( self . __valuePlugSet ) ) <EOL> def setPlug ( self , plug ) : <EOL> self . __plug = plug <EOL> self . __plugMetadataChangedConnection = None <EOL> del self . __editingColumn [ <NUM_LIT:4> : ] <EOL> plugValueWidget = None <EOL> if self . __plug is not None : <EOL> self . __plugMetadataChangedConnection = Gaffer . Metadata . plugValueChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __plugMetadataChanged ) ) <EOL> self . __valueNode [ "<STR_LIT>" ] = plug . createCounterpart ( "<STR_LIT>" , plug . Direction . In ) <EOL> if hasattr ( self . __plug , "<STR_LIT>" ) : <EOL> plugValueWidget = GafferUI . PlugValueWidget . create ( self . __valueNode [ "<STR_LIT>" ] , useTypeOnly = True ) <EOL> self . __editingColumn . append ( plugValueWidget if plugValueWidget is not None else GafferUI . TextWidget ( ) ) <EOL> self . __editingColumn . append ( GafferUI . Spacer ( IECore . V2i ( <NUM_LIT:0> ) , parenting = { "<STR_LIT>" : True } ) ) <EOL> self . __updatePath ( ) <EOL> self . __addButton . setEnabled ( hasattr ( self . __plug , "<STR_LIT>" ) ) <EOL> def getPlug ( self ) : <EOL> return self . __plug <EOL> def __updatePath ( self ) : <EOL> d = self . __pathListing . getPath ( ) . dict ( ) <EOL> d . clear ( ) <EOL> if self . __plug is not None : <EOL> for name in _registeredMetadata ( self . __plug , instanceOnly = True , persistentOnly = True ) : <EOL> if name . startswith ( "<STR_LIT>" ) : <EOL> d [ name [ <NUM_LIT:7> : ] ] = _metadata ( self . __plug , name ) <EOL> self . __pathListing . getPath ( ) . pathChangedSignal ( ) ( self . __pathListing . getPath ( ) ) <EOL> def __plugMetadataChanged ( self , nodeTypeId , plugPath , key , plug ) : <EOL> if plug is None or not plug . isSame ( self . __plug ) : <EOL> return <EOL> if key . startswith ( "<STR_LIT>" ) : <EOL> self . __updatePath ( ) <EOL> def __selectionChanged ( self , listing ) : <EOL> selectedPaths = listing . getSelectedPaths ( ) <EOL> self . __nameWidget . setText ( selectedPaths [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] if selectedPaths else "<STR_LIT>" ) <EOL> if selectedPaths : <EOL> with Gaffer . BlockedConnection ( self . __valuePlugSetConnection ) : <EOL> self . __valueNode [ "<STR_LIT>" ] . setValue ( <EOL> Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" + selectedPaths [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> ) <EOL> self . __editingColumn . setEnabled ( bool ( selectedPaths ) ) <EOL> self . __deleteButton . setEnabled ( bool ( selectedPaths ) ) <EOL> def __dragEnter ( self , listing , event ) : <EOL> if event . sourceWidget is not self . __pathListing : <EOL> return False <EOL> if not isinstance ( event . data , IECore . StringVectorData ) : <EOL> return False <EOL> return True <EOL> def __dragMove ( self , listing , event ) : <EOL> d = self . __pathListing . getPath ( ) . dict ( ) <EOL> srcPath = self . __pathListing . getPath ( ) . copy ( ) . setFromString ( event . data [ <NUM_LIT:0> ] ) <EOL> srcIndex = d . keys ( ) . index ( srcPath [ <NUM_LIT:0> ] ) <EOL> targetPath = self . __pathListing . pathAt ( event . line . p0 ) <EOL> if targetPath is not None : <EOL> targetIndex = d . keys ( ) . index ( targetPath [ <NUM_LIT:0> ] ) <EOL> else : <EOL> targetIndex = <NUM_LIT:0> if event . line . p0 . y < <NUM_LIT:1> else len ( d ) <EOL> if srcIndex == targetIndex : <EOL> return True <EOL> items = d . items ( ) <EOL> item = items [ srcIndex ] <EOL> del items [ srcIndex ] <EOL> items . insert ( targetIndex , item ) <EOL> d . clear ( ) <EOL> d . update ( items ) <EOL> self . __pathListing . getPath ( ) . pathChangedSignal ( ) ( self . __pathListing . getPath ( ) ) <EOL> return True <EOL> def __dragEnd ( self , listing , event ) : <EOL> d = self . __pathListing . getPath ( ) . dict ( ) <EOL> with Gaffer . BlockedConnection ( self . __plugMetadataChangedConnection ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> for item in d . items ( ) : <EOL> Gaffer . Metadata . deregisterPlugValue ( self . getPlug ( ) , "<STR_LIT>" + item [ <NUM_LIT:0> ] ) <EOL> for item in d . items ( ) : <EOL> Gaffer . Metadata . registerPlugValue ( self . getPlug ( ) , "<STR_LIT>" + item [ <NUM_LIT:0> ] , item [ <NUM_LIT:1> ] ) <EOL> self . __updatePath ( ) <EOL> return True <EOL> def __addButtonClicked ( self , button ) : <EOL> existingNames = [ p [ <NUM_LIT:0> ] for p in self . __pathListing . getPath ( ) . children ( ) ] <EOL> name = "<STR_LIT>" <EOL> index = <NUM_LIT:1> <EOL> while name in existingNames : <EOL> name = "<STR_LIT>" % index <EOL> index += <NUM_LIT:1> <EOL> with Gaffer . UndoContext ( self . __plug . ancestor ( Gaffer . ScriptNode ) ) : <EOL> Gaffer . Metadata . registerPlugValue ( self . __plug , "<STR_LIT>" + name , self . __plug . getValue ( ) ) <EOL> self . __pathListing . setSelectedPaths ( <EOL> self . __pathListing . getPath ( ) . copy ( ) . setFromString ( "<STR_LIT:/>" + name ) <EOL> ) <EOL> self . __nameWidget . grabFocus ( ) <EOL> self . __nameWidget . setSelection ( <NUM_LIT:0> , len ( name ) ) <EOL> return True <EOL> def __deleteButtonClicked ( self , button ) : <EOL> paths = self . __pathListing . getPath ( ) . children ( ) <EOL> selectedPreset = self . __pathListing . getSelectedPaths ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> selectedIndex = [ p [ <NUM_LIT:0> ] for p in paths ] . index ( selectedPreset ) <EOL> with Gaffer . UndoContext ( self . __plug . ancestor ( Gaffer . ScriptNode ) ) : <EOL> Gaffer . Metadata . deregisterPlugValue ( self . __plug , "<STR_LIT>" + selectedPreset ) <EOL> del paths [ selectedIndex ] <EOL> if len ( paths ) : <EOL> self . __pathListing . setSelectedPaths ( [ paths [ min ( selectedIndex , len ( paths ) - <NUM_LIT:1> ) ] ] ) <EOL> return True <EOL> def __nameEditingFinished ( self , nameWidget ) : <EOL> selectedPaths = self . __pathListing . getSelectedPaths ( ) <EOL> if not len ( selectedPaths ) : <EOL> return True <EOL> oldName = selectedPaths [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> newName = nameWidget . getText ( ) <EOL> items = self . __pathListing . getPath ( ) . dict ( ) . items ( ) <EOL> with Gaffer . BlockedConnection ( self . __plugMetadataChangedConnection ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> for item in items : <EOL> Gaffer . Metadata . deregisterPlugValue ( self . getPlug ( ) , "<STR_LIT>" + item [ <NUM_LIT:0> ] ) <EOL> for item in items : <EOL> Gaffer . Metadata . registerPlugValue ( self . getPlug ( ) , "<STR_LIT>" + ( item [ <NUM_LIT:0> ] if item [ <NUM_LIT:0> ] != oldName else newName ) , item [ <NUM_LIT:1> ] ) <EOL> self . __updatePath ( ) <EOL> self . __pathListing . setSelectedPaths ( [ self . __pathListing . getPath ( ) . copy ( ) . setFromString ( "<STR_LIT:/>" + newName ) ] ) <EOL> return True <EOL> def __valuePlugSet ( self , plug ) : <EOL> if not plug . isSame ( self . __valueNode [ "<STR_LIT>" ] ) : <EOL> return <EOL> selectedPaths = self . __pathListing . getSelectedPaths ( ) <EOL> preset = selectedPaths [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> Gaffer . Metadata . registerPlugValue ( self . getPlug ( ) , "<STR_LIT>" + preset , plug . getValue ( ) ) <EOL> class _PlugEditor ( GafferUI . Widget ) : <EOL> def __init__ ( self , parenting = None ) : <EOL> scrolledContainer = GafferUI . ScrolledContainer ( horizontalMode = GafferUI . ScrolledContainer . ScrollMode . Never , borderWidth = <NUM_LIT:8> ) <EOL> GafferUI . Widget . __init__ ( self , scrolledContainer , parenting = parenting ) <EOL> self . __metadataWidgets = { } <EOL> scrolledContainer . setChild ( GafferUI . ListContainer ( spacing = <NUM_LIT:4> ) ) <EOL> with scrolledContainer . getChild ( ) : <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT:Name>" ) <EOL> self . __nameWidget = GafferUI . NameWidget ( None ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __metadataWidgets [ "<STR_LIT:label>" ] = _StringMetadataWidget ( key = "<STR_LIT:label>" , acceptEmptyString = False ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" , parenting = { "<STR_LIT>" : GafferUI . ListContainer . VerticalAlignment . Top } ) <EOL> self . __metadataWidgets [ "<STR_LIT:description>" ] = _MultiLineStringMetadataWidget ( key = "<STR_LIT:description>" ) <EOL> self . __metadataWidgets [ "<STR_LIT:description>" ] . textWidget ( ) . setFixedLineHeight ( <NUM_LIT:10> ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __widgetMenu = GafferUI . MenuButton ( <EOL> menu = GafferUI . Menu ( Gaffer . WeakMethod ( self . __widgetMenuDefinition ) ) <EOL> ) <EOL> with GafferUI . Collapsible ( "<STR_LIT>" , collapsed = True ) : <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __presetsEditor = _PresetsEditor ( ) <EOL> with GafferUI . Collapsible ( "<STR_LIT>" , collapsed = True ) : <EOL> with GafferUI . ListContainer ( spacing = <NUM_LIT:4> ) : <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __metadataWidgets [ "<STR_LIT>" ] = _BoolMetadataWidget ( key = "<STR_LIT>" ) <EOL> for m in self . __metadataDefinitions : <EOL> with _Row ( ) : <EOL> _Label ( m . label ) <EOL> self . __metadataWidgets [ m . key ] = m . metadataWidgetType ( key = m . key ) <EOL> with GafferUI . Collapsible ( "<STR_LIT>" , collapsed = True ) : <EOL> with GafferUI . ListContainer ( spacing = <NUM_LIT:4> ) as self . __nodeGraphSection : <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __gadgetMenu = GafferUI . MenuButton ( <EOL> menu = GafferUI . Menu ( Gaffer . WeakMethod ( self . __gadgetMenuDefinition ) ) <EOL> ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __metadataWidgets [ "<STR_LIT>" ] = _MenuMetadataWidget ( <EOL> key = "<STR_LIT>" , <EOL> labelsAndValues = [ <EOL> ( "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:left>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:right>" ) , <EOL> ] <EOL> ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __metadataWidgets [ "<STR_LIT>" ] = _ColorSwatchMetadataWidget ( key = "<STR_LIT>" ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" ) <EOL> self . __metadataWidgets [ "<STR_LIT>" ] = _ColorSwatchMetadataWidget ( key = "<STR_LIT>" ) <EOL> GafferUI . Spacer ( IECore . V2i ( <NUM_LIT:0> ) , parenting = { "<STR_LIT>" : True } ) <EOL> self . __plugMetadataChangedConnection = Gaffer . Metadata . plugValueChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __plugMetadataChanged ) ) <EOL> self . __plug = None <EOL> def setPlug ( self , plug ) : <EOL> self . __plug = plug <EOL> self . __nameWidget . setGraphComponent ( self . __plug ) <EOL> for widget in self . __metadataWidgets . values ( ) : <EOL> widget . setTarget ( self . __plug ) <EOL> self . __updateWidgetMenuText ( ) <EOL> self . __updateWidgetSettings ( ) <EOL> self . __updateGadgetMenuText ( ) <EOL> self . __presetsEditor . setPlug ( plug ) <EOL> self . __nodeGraphSection . setEnabled ( self . __plug is not None and self . __plug . parent ( ) . isSame ( self . __plug . node ( ) ) ) <EOL> self . setEnabled ( self . __plug is not None ) <EOL> def getPlug ( self ) : <EOL> return self . __plug <EOL> def __plugMetadataChanged ( self , nodeTypeId , plugPath , key , plug ) : <EOL> if self . getPlug ( ) is None : <EOL> return <EOL> if plug is not None and not plug . isSame ( self . getPlug ( ) ) : <EOL> return <EOL> if not self . getPlug ( ) . node ( ) . isInstanceOf ( nodeTypeId ) : <EOL> return <EOL> if key == "<STR_LIT>" : <EOL> self . __updateWidgetMenuText ( ) <EOL> self . __updateWidgetSettings ( ) <EOL> elif key == "<STR_LIT>" : <EOL> self . __updateGadgetMenuText ( ) <EOL> def __updateWidgetMenuText ( self ) : <EOL> if self . getPlug ( ) is None : <EOL> self . __widgetMenu . setText ( "<STR_LIT>" ) <EOL> return <EOL> metadata = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> for w in self . __widgetDefinitions : <EOL> if w . metadata == metadata : <EOL> self . __widgetMenu . setText ( w . label ) <EOL> return <EOL> self . __widgetMenu . setText ( metadata ) <EOL> def __updateWidgetSettings ( self ) : <EOL> widgetType = None <EOL> if self . getPlug ( ) is not None : <EOL> widgetType = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> for m in self . __metadataDefinitions : <EOL> widget = self . __metadataWidgets [ m . key ] <EOL> widget . parent ( ) . setEnabled ( m . plugValueWidgetType == widgetType ) <EOL> self . __metadataWidgets [ "<STR_LIT>" ] . parent ( ) . setEnabled ( <EOL> self . getPlug ( ) is not None and self . getPlug ( ) . direction ( ) == Gaffer . Plug . Direction . In <EOL> ) <EOL> def __widgetMenuDefinition ( self ) : <EOL> result = IECore . MenuDefinition ( ) <EOL> if self . getPlug ( ) is None : <EOL> return result <EOL> metadata = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> for w in self . __widgetDefinitions : <EOL> if not isinstance ( self . getPlug ( ) , w . plugType ) : <EOL> continue <EOL> result . append ( <EOL> "<STR_LIT:/>" + w . label , <EOL> { <EOL> "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __registerOrDeregisterMetadata ) , key = "<STR_LIT>" , value = w . metadata ) , <EOL> "<STR_LIT>" : metadata == w . metadata , <EOL> } <EOL> ) <EOL> return result <EOL> def __updateGadgetMenuText ( self ) : <EOL> if self . getPlug ( ) is None : <EOL> self . __gadgetMenu . setText ( "<STR_LIT>" ) <EOL> return <EOL> metadata = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> metadata = None if metadata == "<STR_LIT>" else metadata <EOL> for g in self . __gadgetDefinitions : <EOL> if g . metadata == metadata : <EOL> self . __gadgetMenu . setText ( g . label ) <EOL> return <EOL> self . __gadgetMenu . setText ( metadata ) <EOL> def __gadgetMenuDefinition ( self ) : <EOL> result = IECore . MenuDefinition ( ) <EOL> if self . getPlug ( ) is None : <EOL> return result <EOL> metadata = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> for g in self . __gadgetDefinitions : <EOL> if not isinstance ( self . getPlug ( ) , g . plugType ) : <EOL> continue <EOL> result . append ( <EOL> "<STR_LIT:/>" + g . label , <EOL> { <EOL> "<STR_LIT>" : functools . partial ( Gaffer . WeakMethod ( self . __registerOrDeregisterMetadata ) , key = "<STR_LIT>" , value = g . metadata ) , <EOL> "<STR_LIT>" : metadata == g . metadata , <EOL> } <EOL> ) <EOL> return result <EOL> def __registerOrDeregisterMetadata ( self , unused , key , value ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> if value is not None : <EOL> Gaffer . Metadata . registerPlugValue ( self . getPlug ( ) , key , value ) <EOL> else : <EOL> Gaffer . Metadata . deregisterPlugValue ( self . getPlug ( ) , key ) <EOL> __WidgetDefinition = collections . namedtuple ( "<STR_LIT>" , ( "<STR_LIT:label>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> __widgetDefinitions = ( <EOL> __WidgetDefinition ( "<STR_LIT>" , Gaffer . Plug , None ) , <EOL> __WidgetDefinition ( "<STR_LIT>" , Gaffer . IntPlug , "<STR_LIT>" ) , <EOL> __WidgetDefinition ( "<STR_LIT>" , Gaffer . StringPlug , "<STR_LIT>" ) , <EOL> __WidgetDefinition ( "<STR_LIT>" , Gaffer . StringPlug , "<STR_LIT>" ) , <EOL> __WidgetDefinition ( "<STR_LIT>" , Gaffer . ValuePlug , "<STR_LIT>" ) , <EOL> __WidgetDefinition ( "<STR_LIT>" , Gaffer . Plug , "<STR_LIT>" ) , <EOL> __WidgetDefinition ( "<STR_LIT:None>" , Gaffer . Plug , "<STR_LIT>" ) , <EOL> ) <EOL> __MetadataDefinition = collections . namedtuple ( "<STR_LIT>" , ( "<STR_LIT:key>" , "<STR_LIT:label>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> __metadataDefinitions = ( <EOL> __MetadataDefinition ( "<STR_LIT>" , "<STR_LIT>" , _StringMetadataWidget , "<STR_LIT>" ) , <EOL> __MetadataDefinition ( "<STR_LIT>" , "<STR_LIT>" , _StringMetadataWidget , "<STR_LIT>" ) , <EOL> __MetadataDefinition ( "<STR_LIT>" , "<STR_LIT>" , _BoolMetadataWidget , "<STR_LIT>" ) , <EOL> __MetadataDefinition ( "<STR_LIT>" , "<STR_LIT>" , _BoolMetadataWidget , "<STR_LIT>" ) , <EOL> __MetadataDefinition ( "<STR_LIT>" , "<STR_LIT>" , _BoolMetadataWidget , "<STR_LIT>" ) , <EOL> __MetadataDefinition ( "<STR_LIT>" , "<STR_LIT>" , _BoolMetadataWidget , "<STR_LIT>" ) , <EOL> ) <EOL> __GadgetDefinition = collections . namedtuple ( "<STR_LIT>" , ( "<STR_LIT:label>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> __gadgetDefinitions = ( <EOL> __GadgetDefinition ( "<STR_LIT>" , Gaffer . Plug , None ) , <EOL> __GadgetDefinition ( "<STR_LIT>" , Gaffer . ArrayPlug , "<STR_LIT>" ) , <EOL> __GadgetDefinition ( "<STR_LIT:None>" , Gaffer . Plug , "<STR_LIT>" ) , <EOL> ) <EOL> class _SectionEditor ( GafferUI . Widget ) : <EOL> def __init__ ( self , parenting = None ) : <EOL> column = GafferUI . ListContainer ( spacing = <NUM_LIT:4> , borderWidth = <NUM_LIT:8> ) <EOL> GafferUI . Widget . __init__ ( self , column , parenting = parenting ) <EOL> with column : <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT:Name>" ) <EOL> self . __nameWidget = GafferUI . TextWidget ( ) <EOL> self . __nameWidgetEditingFinishedConnection = self . __nameWidget . editingFinishedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __nameWidgetEditingFinished ) ) <EOL> with _Row ( ) : <EOL> _Label ( "<STR_LIT>" , parenting = { "<STR_LIT>" : GafferUI . ListContainer . VerticalAlignment . Top } ) <EOL> self . __summaryMetadataWidget = _MultiLineStringMetadataWidget ( key = "<STR_LIT>" ) <EOL> self . __section = "<STR_LIT>" <EOL> self . __plugParent = None <EOL> self . __nameChangedSignal = Gaffer . Signal3 ( ) <EOL> def setPlugParent ( self , plugParent ) : <EOL> self . __plugParent = plugParent <EOL> self . __summaryMetadataWidget . setTarget ( self . __plugParent ) <EOL> def getPlugParent ( self ) : <EOL> return self . __plugParent <EOL> def setSection ( self , section ) : <EOL> assert ( isinstance ( section , basestring ) ) <EOL> self . __section = section <EOL> self . __nameWidget . setText ( section . rpartition ( "<STR_LIT:.>" ) [ - <NUM_LIT:1> ] ) <EOL> self . __summaryMetadataWidget . setKey ( "<STR_LIT>" + self . __section + "<STR_LIT>" ) <EOL> def getSection ( self ) : <EOL> return self . __section <EOL> def nameChangedSignal ( self ) : <EOL> return self . __nameChangedSignal <EOL> def __nameWidgetEditingFinished ( self , nameWidget ) : <EOL> if nameWidget . getText ( ) == "<STR_LIT>" : <EOL> self . setSection ( self . __section ) <EOL> return <EOL> oldSectionPath = self . __section . split ( "<STR_LIT:.>" ) <EOL> newSectionPath = oldSectionPath [ : ] <EOL> newSectionPath [ - <NUM_LIT:1> ] = nameWidget . getText ( ) . replace ( "<STR_LIT:.>" , "<STR_LIT>" ) <EOL> if oldSectionPath == newSectionPath : <EOL> return <EOL> def newSection ( oldSection ) : <EOL> s = oldSection . split ( "<STR_LIT:.>" ) <EOL> if s [ : len ( oldSectionPath ) ] == oldSectionPath : <EOL> s [ : len ( oldSectionPath ) ] = newSectionPath <EOL> return "<STR_LIT:.>" . join ( s ) <EOL> else : <EOL> return oldSection <EOL> with Gaffer . UndoContext ( self . __plugParent . ancestor ( Gaffer . ScriptNode ) ) : <EOL> for plug in self . __plugParent . children ( Gaffer . Plug ) : <EOL> s = _metadata ( plug , "<STR_LIT>" ) <EOL> if s is not None : <EOL> _registerMetadata ( plug , "<STR_LIT>" , newSection ( s ) ) <EOL> emptySections = _metadata ( self . getPlugParent ( ) , "<STR_LIT>" ) <EOL> if emptySections : <EOL> for i in range ( <NUM_LIT:0> , len ( emptySections ) ) : <EOL> emptySections [ i ] = newSection ( emptySections [ i ] ) <EOL> _registerMetadata ( self . getPlugParent ( ) , "<STR_LIT>" , emptySections ) <EOL> for name in _registeredMetadata ( self . getPlugParent ( ) , instanceOnly = True , persistentOnly = True ) : <EOL> m = re . match ( "<STR_LIT>" , name ) <EOL> if m : <EOL> if newSection ( m . group ( <NUM_LIT:2> ) ) != m . group ( <NUM_LIT:2> ) : <EOL> _registerMetadata ( <EOL> self . getPlugParent ( ) , <EOL> m . group ( <NUM_LIT:1> ) + newSection ( m . group ( <NUM_LIT:2> ) ) + m . group ( <NUM_LIT:3> ) , <EOL> _metadata ( self . getPlugParent ( ) , name ) <EOL> ) <EOL> _deregisterMetadata ( self . getPlugParent ( ) , name ) <EOL> self . setSection ( "<STR_LIT:.>" . join ( newSectionPath ) ) <EOL> self . nameChangedSignal ( ) ( self , "<STR_LIT:.>" . join ( oldSectionPath ) , "<STR_LIT:.>" . join ( newSectionPath ) ) <EOL> def _registerMetadata ( target , name , value ) : <EOL> if isinstance ( target , Gaffer . Node ) : <EOL> Gaffer . Metadata . registerNodeValue ( target , name , value ) <EOL> else : <EOL> Gaffer . Metadata . registerPlugValue ( target , name , value ) <EOL> def _registeredMetadata ( target , inherit = True , instanceOnly = False , persistentOnly = False ) : <EOL> if isinstance ( target , Gaffer . Node ) : <EOL> return Gaffer . Metadata . registeredNodeValues ( target , inherit , instanceOnly , persistentOnly ) <EOL> else : <EOL> return Gaffer . Metadata . registeredPlugValues ( target , inherit , instanceOnly , persistentOnly ) <EOL> def _metadata ( target , name ) : <EOL> if isinstance ( target , Gaffer . Node ) : <EOL> return Gaffer . Metadata . nodeValue ( target , name ) <EOL> else : <EOL> return Gaffer . Metadata . plugValue ( target , name ) <EOL> def _deregisterMetadata ( target , name ) : <EOL> if isinstance ( target , Gaffer . Node ) : <EOL> return Gaffer . Metadata . deregisterNodeValue ( target , name ) <EOL> else : <EOL> return Gaffer . Metadata . deregisterPlugValue ( target , name ) </s>
