<s> from __future__ import with_statement <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class CompoundDataPlugValueWidget ( GafferUI . PlugValueWidget ) : <EOL> def __init__ ( self , plug , parenting = None ) : <EOL> self . __column = GafferUI . ListContainer ( spacing = <NUM_LIT:6> ) <EOL> GafferUI . PlugValueWidget . __init__ ( self , self . __column , plug , parenting = parenting ) <EOL> with self . __column : <EOL> self . __layout = GafferUI . PlugLayout ( plug ) <EOL> with GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal ) as self . __editRow : <EOL> GafferUI . Spacer ( IECore . V2i ( GafferUI . PlugWidget . labelWidth ( ) , <NUM_LIT:1> ) ) <EOL> GafferUI . MenuButton ( <EOL> image = "<STR_LIT>" , <EOL> hasFrame = False , <EOL> menu = GafferUI . Menu ( Gaffer . WeakMethod ( self . __addMenuDefinition ) ) <EOL> ) <EOL> GafferUI . Spacer ( IECore . V2i ( <NUM_LIT:1> ) , IECore . V2i ( <NUM_LIT> , <NUM_LIT:1> ) , parenting = { "<STR_LIT>" : True } ) <EOL> self . _updateFromPlug ( ) <EOL> def hasLabel ( self ) : <EOL> return True <EOL> def setPlug ( self , plug ) : <EOL> GafferUI . PlugValueWidget . setPlug ( self , plug ) <EOL> self . __layout = GafferUI . PlugLayout ( plug ) <EOL> self . __column [ <NUM_LIT:0> ] = self . __layout <EOL> def setReadOnly ( self , readOnly ) : <EOL> if readOnly == self . getReadOnly ( ) : <EOL> return <EOL> GafferUI . PlugValueWidget . setReadOnly ( self , readOnly ) <EOL> self . __layout . setReadOnly ( readOnly ) <EOL> def childPlugValueWidget ( self , childPlug , lazy = True ) : <EOL> return self . __layout . plugValueWidget ( childPlug , lazy ) <EOL> def _updateFromPlug ( self ) : <EOL> editable = True <EOL> if self . getPlug ( ) is not None : <EOL> editable = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> editable = editable if editable is not None else True <EOL> self . __editRow . setVisible ( editable ) <EOL> def __addMenuDefinition ( self ) : <EOL> result = IECore . MenuDefinition ( ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . BoolData ( False ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . FloatData ( <NUM_LIT:0> ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . IntData ( <NUM_LIT:0> ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . StringData ( "<STR_LIT>" ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . V2iData ( IECore . V2i ( <NUM_LIT:0> ) ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . V3iData ( IECore . V3i ( <NUM_LIT:0> ) ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . V2fData ( IECore . V2f ( <NUM_LIT:0> ) ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . V3fData ( IECore . V3f ( <NUM_LIT:0> ) ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . Color3fData ( IECore . Color3f ( <NUM_LIT:0> ) ) ) } ) <EOL> result . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __addItem ) , "<STR_LIT>" , IECore . Color4fData ( IECore . Color4f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) ) } ) <EOL> return result <EOL> def __addItem ( self , name , value ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode . staticTypeId ( ) ) ) : <EOL> self . getPlug ( ) . addOptionalMember ( name , value , enabled = True ) <EOL> class _MemberPlugValueWidget ( GafferUI . PlugValueWidget ) : <EOL> def __init__ ( self , childPlug ) : <EOL> self . __row = GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> ) <EOL> GafferUI . PlugValueWidget . __init__ ( self , self . __row , childPlug ) <EOL> if not childPlug . getFlags ( Gaffer . Plug . Flags . Dynamic ) : <EOL> nameWidget = GafferUI . LabelPlugValueWidget ( <EOL> childPlug , <EOL> horizontalAlignment = GafferUI . Label . HorizontalAlignment . Right , <EOL> verticalAlignment = GafferUI . Label . VerticalAlignment . Center , <EOL> ) <EOL> nameWidget . label ( ) . _qtWidget ( ) . setFixedWidth ( GafferUI . PlugWidget . labelWidth ( ) ) <EOL> nameWidget . label ( ) . _qtWidget ( ) . setFixedHeight ( <NUM_LIT:20> ) <EOL> else : <EOL> nameWidget = GafferUI . StringPlugValueWidget ( childPlug [ "<STR_LIT:name>" ] ) <EOL> nameWidget . textWidget ( ) . _qtWidget ( ) . setFixedWidth ( GafferUI . PlugWidget . labelWidth ( ) ) <EOL> self . __row . append ( nameWidget , <EOL> verticalAlignment = GafferUI . Label . VerticalAlignment . Top <EOL> ) <EOL> if "<STR_LIT>" in childPlug : <EOL> self . __row . append ( <EOL> GafferUI . BoolPlugValueWidget ( <EOL> childPlug [ "<STR_LIT>" ] , <EOL> displayMode = GafferUI . BoolWidget . DisplayMode . Switch <EOL> ) , <EOL> verticalAlignment = GafferUI . Label . VerticalAlignment . Top , <EOL> ) <EOL> self . __row . append ( GafferUI . PlugValueWidget . create ( childPlug [ "<STR_LIT:value>" ] ) , expand = True ) <EOL> self . _updateFromPlug ( ) <EOL> def setPlug ( self , plug ) : <EOL> GafferUI . PlugValueWidget . setPlug ( self , plug ) <EOL> if isinstance ( self . __row [ <NUM_LIT:0> ] , GafferUI . LabelPlugValueWidget ) : <EOL> self . __row [ <NUM_LIT:0> ] . setPlug ( plug ) <EOL> else : <EOL> self . __row [ <NUM_LIT:0> ] . setPlug ( plug [ "<STR_LIT:name>" ] ) <EOL> if "<STR_LIT>" in plug : <EOL> self . __row [ <NUM_LIT:1> ] . setPlug ( plug [ "<STR_LIT>" ] ) <EOL> self . __row [ - <NUM_LIT:1> ] . setPlug ( plug [ "<STR_LIT:value>" ] ) <EOL> def hasLabel ( self ) : <EOL> return True <EOL> def childPlugValueWidget ( self , childPlug , lazy = True ) : <EOL> for w in self . __row : <EOL> if w . getPlug ( ) . isSame ( childPlug ) : <EOL> return w <EOL> return None <EOL> def setReadOnly ( self , readOnly ) : <EOL> if readOnly == self . getReadOnly ( ) : <EOL> return <EOL> GafferUI . PlugValueWidget . setReadOnly ( self , readOnly ) <EOL> for w in self . __row : <EOL> w . setReadOnly ( readOnly ) <EOL> def _updateFromPlug ( self ) : <EOL> if "<STR_LIT>" in self . getPlug ( ) : <EOL> with self . getContext ( ) : <EOL> enabled = self . getPlug ( ) [ "<STR_LIT>" ] . getValue ( ) <EOL> if isinstance ( self . __row [ <NUM_LIT:0> ] , GafferUI . StringPlugValueWidget ) : <EOL> self . __row [ <NUM_LIT:0> ] . setEnabled ( enabled ) <EOL> self . __row [ - <NUM_LIT:1> ] . setEnabled ( enabled ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . CompoundDataPlug , CompoundDataPlugValueWidget ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . CompoundDataPlug . MemberPlug , _MemberPlugValueWidget ) <EOL> def __deletePlug ( plug ) : <EOL> with Gaffer . UndoContext ( plug . ancestor ( Gaffer . ScriptNode ) ) : <EOL> plug . parent ( ) . removeChild ( plug ) <EOL> def __plugPopupMenu ( menuDefinition , plugValueWidget ) : <EOL> plug = plugValueWidget . getPlug ( ) <EOL> memberPlug = plug if isinstance ( plug , Gaffer . CompoundDataPlug . MemberPlug ) else None <EOL> memberPlug = memberPlug if memberPlug is not None else plug . ancestor ( Gaffer . CompoundDataPlug . MemberPlug ) <EOL> if memberPlug is None : <EOL> return <EOL> if not memberPlug . getFlags ( Gaffer . Plug . Flags . Dynamic ) : <EOL> return <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( __deletePlug , memberPlug ) , "<STR_LIT>" : not plugValueWidget . getReadOnly ( ) } ) <EOL> __plugPopupMenuConnection = GafferUI . PlugValueWidget . popupMenuSignal ( ) . connect ( __plugPopupMenu ) </s>
