<s> import IECore <EOL> import Gaffer <EOL> import GafferTest <EOL> import GafferUI <EOL> import GafferUITest <EOL> class BoxUITest ( GafferUITest . TestCase ) : <EOL> class NodulePositionNode ( GafferTest . AddNode ) : <EOL> def __init__ ( self , name = "<STR_LIT>" ) : <EOL> GafferTest . AddNode . __init__ ( self , name ) <EOL> IECore . registerRunTimeTyped ( NodulePositionNode ) <EOL> Gaffer . Metadata . registerPlugValue ( NodulePositionNode , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:left>" ) <EOL> Gaffer . Metadata . registerPlugValue ( NodulePositionNode , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:right>" ) <EOL> Gaffer . Metadata . registerPlugValue ( NodulePositionNode , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def testNodulePositions ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> g = GafferUI . GraphGadget ( s ) <EOL> s [ "<STR_LIT:a>" ] = GafferTest . AddNode ( ) <EOL> s [ "<STR_LIT:n>" ] = self . NodulePositionNode ( ) <EOL> s [ "<STR_LIT:r>" ] = GafferTest . AddNode ( ) <EOL> s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:a>" ] [ "<STR_LIT>" ] ) <EOL> s [ "<STR_LIT:r>" ] [ "<STR_LIT>" ] . setInput ( s [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> box = Gaffer . Box . create ( s , Gaffer . StandardSet ( [ s [ "<STR_LIT:n>" ] ] ) ) <EOL> boxGadget = g . nodeGadget ( box ) <EOL> self . assertEqual ( boxGadget . noduleTangent ( boxGadget . nodule ( box [ "<STR_LIT>" ] ) ) , IECore . V3f ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( boxGadget . noduleTangent ( boxGadget . nodule ( box [ "<STR_LIT>" ] ) ) , IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> s2 = Gaffer . ScriptNode ( ) <EOL> g2 = GafferUI . GraphGadget ( s2 ) <EOL> s2 . execute ( s . serialise ( ) ) <EOL> box2 = s2 [ box . getName ( ) ] <EOL> boxGadget2 = g2 . nodeGadget ( box2 ) <EOL> self . assertEqual ( boxGadget2 . noduleTangent ( boxGadget2 . nodule ( box2 [ "<STR_LIT>" ] ) ) , IECore . V3f ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( boxGadget2 . noduleTangent ( boxGadget2 . nodule ( box2 [ "<STR_LIT>" ] ) ) , IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def testNodulePositionsForPromotedPlugs ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> g = GafferUI . GraphGadget ( s ) <EOL> s [ "<STR_LIT:b>" ] = Gaffer . Box ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] = self . NodulePositionNode ( ) <EOL> boxGadget = g . nodeGadget ( s [ "<STR_LIT:b>" ] ) <EOL> p1 = s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> p2 = s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( boxGadget . noduleTangent ( boxGadget . nodule ( p1 ) ) , IECore . V3f ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( boxGadget . noduleTangent ( boxGadget . nodule ( p2 ) ) , IECore . V3f ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def testDisabledNodulesForPromotedPlugs ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> g = GafferUI . GraphGadget ( s ) <EOL> s [ "<STR_LIT:b>" ] = Gaffer . Box ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] = self . NodulePositionNode ( ) <EOL> boxGadget = g . nodeGadget ( s [ "<STR_LIT:b>" ] ) <EOL> p = s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( boxGadget . nodule ( p ) , None ) <EOL> def testRenamingPlugs ( self ) : <EOL> box = Gaffer . Box ( ) <EOL> box [ "<STR_LIT:user>" ] [ "<STR_LIT:a>" ] = Gaffer . IntPlug ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> ui = GafferUI . NodeUI . create ( box ) <EOL> w = ui . plugValueWidget ( box [ "<STR_LIT:user>" ] [ "<STR_LIT:a>" ] , lazy = False ) <EOL> self . assertTrue ( w is not None ) <EOL> box [ "<STR_LIT:user>" ] [ "<STR_LIT:a>" ] . setName ( "<STR_LIT:b>" ) <EOL> w2 = ui . plugValueWidget ( box [ "<STR_LIT:user>" ] [ "<STR_LIT:b>" ] , lazy = False ) <EOL> self . assertTrue ( w2 is not None ) <EOL> self . assertTrue ( w2 is w ) <EOL> def testUIForNonMatchingPromotedPlugTypes ( self ) : <EOL> box = Gaffer . Box ( ) <EOL> box [ "<STR_LIT:user>" ] [ "<STR_LIT:b>" ] = Gaffer . BoolPlug ( ) <EOL> box [ "<STR_LIT>" ] = Gaffer . Node ( ) <EOL> box [ "<STR_LIT>" ] [ "<STR_LIT:i>" ] = Gaffer . IntPlug ( ) <EOL> box [ "<STR_LIT>" ] [ "<STR_LIT:i>" ] . setInput ( box [ "<STR_LIT:user>" ] [ "<STR_LIT:b>" ] ) <EOL> ui = GafferUI . NodeUI . create ( box ) <EOL> w = ui . plugValueWidget ( box [ "<STR_LIT:user>" ] [ "<STR_LIT:b>" ] , lazy = False ) <EOL> self . assertTrue ( isinstance ( w , GafferUI . BoolPlugValueWidget ) ) <EOL> def testUIForOutputPlugTypes ( self ) : <EOL> box = Gaffer . Box ( ) <EOL> box [ "<STR_LIT>" ] = Gaffer . Random ( ) <EOL> p = box . promotePlug ( box [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> nodeUI = GafferUI . NodeUI . create ( box [ "<STR_LIT>" ] ) <EOL> boxUI = GafferUI . NodeUI . create ( box ) <EOL> nodeWidget = nodeUI . plugValueWidget ( box [ "<STR_LIT>" ] [ "<STR_LIT>" ] , lazy = False ) <EOL> boxWidget = boxUI . plugValueWidget ( p , lazy = False ) <EOL> self . assertTrue ( type ( boxWidget ) is type ( nodeWidget ) ) <EOL> def testDisabledNodulesAfterCutAndPaste ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> g = GafferUI . GraphGadget ( s ) <EOL> s [ "<STR_LIT:b>" ] = Gaffer . Box ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] = self . NodulePositionNode ( ) <EOL> g = GafferUI . GraphGadget ( s ) <EOL> s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> p = s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT>" ] ) <EOL> p . setName ( "<STR_LIT:p>" ) <EOL> self . assertEqual ( g . nodeGadget ( s [ "<STR_LIT:b>" ] ) . nodule ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:p>" ] ) , None ) <EOL> s . execute ( s . serialise ( filter = Gaffer . StandardSet ( [ s [ "<STR_LIT:b>" ] ] ) ) ) <EOL> self . assertEqual ( g . nodeGadget ( s [ "<STR_LIT>" ] ) . nodule ( s [ "<STR_LIT>" ] [ "<STR_LIT:p>" ] ) , None ) <EOL> def testPromotionIgnoresLayoutSection ( self ) : <EOL> s = Gaffer . ScriptNode ( ) <EOL> s [ "<STR_LIT:b>" ] = Gaffer . Box ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] = Gaffer . Node ( ) <EOL> s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:p>" ] = Gaffer . IntPlug ( flags = Gaffer . Plug . Flags . Default | Gaffer . Plug . Flags . Dynamic ) <EOL> Gaffer . Metadata . registerPlugValue ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:p>" ] , "<STR_LIT>" , "<STR_LIT>" ) <EOL> p = s [ "<STR_LIT:b>" ] . promotePlug ( s [ "<STR_LIT:b>" ] [ "<STR_LIT:n>" ] [ "<STR_LIT:user>" ] [ "<STR_LIT:p>" ] ) <EOL> self . assertNotEqual ( Gaffer . Metadata . plugValue ( p , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
