<s> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class CompoundNumericPlugValueWidget ( GafferUI . PlugValueWidget ) : <EOL> def __init__ ( self , plug , parenting = None ) : <EOL> self . __row = GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:4> ) <EOL> GafferUI . PlugValueWidget . __init__ ( self , self . __row , plug , parenting = parenting ) <EOL> componentPlugs = plug . children ( ) <EOL> for p in componentPlugs : <EOL> w = GafferUI . NumericPlugValueWidget ( p ) <EOL> self . __row . append ( w ) <EOL> self . __applyVisibleDimensions ( ) <EOL> self . __keyPressConnection = self . keyPressSignal ( ) . connect ( Gaffer . WeakMethod ( self . __keyPress ) ) <EOL> def setPlug ( self , plug ) : <EOL> assert ( len ( plug ) == len ( self . getPlug ( ) ) ) <EOL> GafferUI . PlugValueWidget . setPlug ( self , plug ) <EOL> for index , plug in enumerate ( plug . children ( ) ) : <EOL> self . __row [ index ] . setPlug ( plug ) <EOL> self . __applyVisibleDimensions ( ) <EOL> def setHighlighted ( self , highlighted ) : <EOL> GafferUI . PlugValueWidget . setHighlighted ( self , highlighted ) <EOL> for i in range ( <NUM_LIT:0> , len ( self . getPlug ( ) ) ) : <EOL> self . __row [ i ] . setHighlighted ( highlighted ) <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> if isinstance ( w , GafferUI . PlugValueWidget ) : <EOL> w . setReadOnly ( readOnly ) <EOL> def childPlugValueWidget ( self , childPlug , lazy = True ) : <EOL> for i , p in enumerate ( self . getPlug ( ) . children ( ) ) : <EOL> if p . isSame ( childPlug ) : <EOL> return self . __row [ i ] <EOL> return None <EOL> def _updateFromPlug ( self ) : <EOL> pass <EOL> def _row ( self ) : <EOL> return self . __row <EOL> def _convertValue ( self , value ) : <EOL> result = GafferUI . PlugValueWidget . _convertValue ( self , value ) <EOL> if result is not None : <EOL> return result <EOL> if isinstance ( value , IECore . Data ) and hasattr ( value , "<STR_LIT:value>" ) : <EOL> value = value . value <EOL> if hasattr ( value , "<STR_LIT>" ) and isinstance ( value . dimensions ( ) , int ) : <EOL> with self . getContext ( ) : <EOL> result = self . getPlug ( ) . getValue ( ) <EOL> componentType = type ( result [ <NUM_LIT:0> ] ) <EOL> for i in range ( <NUM_LIT:0> , min ( result . dimensions ( ) , value . dimensions ( ) ) ) : <EOL> result [ i ] = componentType ( value [ i ] ) <EOL> return result <EOL> return None <EOL> def __keyPress ( self , widget , event ) : <EOL> if event . key == "<STR_LIT>" and event . modifiers & event . Modifiers . Control : <EOL> if self . getPlug ( ) . isGanged ( ) : <EOL> self . __ungang ( ) <EOL> elif self . getPlug ( ) . canGang ( ) : <EOL> self . __gang ( ) <EOL> return True <EOL> return False <EOL> def __gang ( self ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> self . getPlug ( ) . gang ( ) <EOL> def __ungang ( self ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> self . getPlug ( ) . ungang ( ) <EOL> @ staticmethod <EOL> def _popupMenu ( menuDefinition , plugValueWidget ) : <EOL> compoundNumericPlugValueWidget = None <EOL> if isinstance ( plugValueWidget , GafferUI . CompoundNumericPlugValueWidget ) : <EOL> compoundNumericPlugValueWidget = plugValueWidget <EOL> else : <EOL> plugWidget = plugValueWidget . ancestor ( GafferUI . PlugWidget ) <EOL> if plugWidget is not None and isinstance ( plugWidget . plugValueWidget ( ) , GafferUI . CompoundNumericPlugValueWidget ) : <EOL> compoundNumericPlugValueWidget = plugWidget . plugValueWidget ( ) <EOL> if compoundNumericPlugValueWidget is None : <EOL> return <EOL> if compoundNumericPlugValueWidget . getPlug ( ) . isGanged ( ) : <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> menuDefinition . append ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : Gaffer . WeakMethod ( compoundNumericPlugValueWidget . __ungang ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : not plugValueWidget . getReadOnly ( ) , <EOL> } ) <EOL> elif compoundNumericPlugValueWidget . getPlug ( ) . canGang ( ) : <EOL> menuDefinition . append ( "<STR_LIT>" , { "<STR_LIT>" : True } ) <EOL> menuDefinition . append ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : Gaffer . WeakMethod ( compoundNumericPlugValueWidget . __gang ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : not plugValueWidget . getReadOnly ( ) , <EOL> } ) <EOL> def __applyVisibleDimensions ( self ) : <EOL> actualDimensions = len ( self . getPlug ( ) ) <EOL> visibleDimensions = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> visibleDimensions = visibleDimensions if visibleDimensions is not None else actualDimensions <EOL> for i in range ( <NUM_LIT:0> , actualDimensions ) : <EOL> self . __row [ i ] . setVisible ( i < visibleDimensions ) <EOL> __popupMenuConnection = GafferUI . PlugValueWidget . popupMenuSignal ( ) . connect ( CompoundNumericPlugValueWidget . _popupMenu ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . V2fPlug , CompoundNumericPlugValueWidget ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . V3fPlug , CompoundNumericPlugValueWidget ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . V2iPlug , CompoundNumericPlugValueWidget ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . V3iPlug , CompoundNumericPlugValueWidget ) </s>
