<s> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class NameLabel ( GafferUI . Label ) : <EOL> def __init__ ( self , graphComponent , horizontalAlignment = GafferUI . Label . HorizontalAlignment . Left , verticalAlignment = GafferUI . Label . VerticalAlignment . Center , numComponents = <NUM_LIT:1> , formatter = None , parenting = None ) : <EOL> GafferUI . Label . __init__ ( self , "<STR_LIT>" , horizontalAlignment , verticalAlignment , parenting = parenting ) <EOL> self . __formatter = formatter if formatter is not None else self . defaultFormatter <EOL> self . __numComponents = numComponents <EOL> self . __connections = [ ] <EOL> self . __graphComponent = False <EOL> self . setGraphComponent ( graphComponent ) <EOL> self . __buttonPressConnection = self . buttonPressSignal ( ) . connect ( Gaffer . WeakMethod ( self . __buttonPress ) ) <EOL> self . __dragBeginConnection = self . dragBeginSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragBegin ) ) <EOL> self . __dragEndConnection = self . dragEndSignal ( ) . connect ( Gaffer . WeakMethod ( self . __dragEnd ) ) <EOL> def setText ( self , text ) : <EOL> GafferUI . Label . setText ( self , text ) <EOL> self . __connections = [ ] <EOL> def setGraphComponent ( self , graphComponent ) : <EOL> if graphComponent is not None and self . __graphComponent is not False : <EOL> if graphComponent . isSame ( self . __graphComponent ) : <EOL> return <EOL> elif self . __graphComponent is None : <EOL> return <EOL> self . __graphComponent = graphComponent <EOL> self . __setupConnections ( ) <EOL> self . __setText ( ) <EOL> def getGraphComponent ( self ) : <EOL> return self . __graphComponent <EOL> def setNumComponents ( self , numComponents ) : <EOL> assert ( numComponents > <NUM_LIT:0> ) <EOL> if numComponents == self . __numComponents : <EOL> return <EOL> self . __numComponents = numComponents <EOL> self . __setupConnections ( ) <EOL> self . __setText ( ) <EOL> def getNumComponents ( self ) : <EOL> return self . __numComponents <EOL> def setFormatter ( self , formatter ) : <EOL> self . __formatter = formatter <EOL> self . __setText ( ) <EOL> def getFormatter ( self ) : <EOL> return self . __formatter <EOL> @ staticmethod <EOL> def defaultFormatter ( graphComponents ) : <EOL> return "<STR_LIT:.>" . join ( IECore . CamelCase . toSpaced ( g . getName ( ) ) for g in graphComponents ) <EOL> def __setupConnections ( self , reuseUntil = None ) : <EOL> if self . __graphComponent is None : <EOL> self . __connections = [ ] <EOL> return <EOL> updatedConnections = [ ] <EOL> n = <NUM_LIT:0> <EOL> g = self . __graphComponent <EOL> reuse = reuseUntil is not None <EOL> while g is not None and n < self . __numComponents : <EOL> if reuse : <EOL> updatedConnections . extend ( self . __connections [ n * <NUM_LIT:2> : n * <NUM_LIT:2> + <NUM_LIT:2> ] ) <EOL> else : <EOL> updatedConnections . append ( g . nameChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __setText ) ) ) <EOL> if n < self . __numComponents - <NUM_LIT:1> : <EOL> updatedConnections . append ( g . parentChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __parentChanged ) ) ) <EOL> if g . isSame ( reuseUntil ) : <EOL> reuse = False <EOL> g = g . parent ( ) <EOL> n += <NUM_LIT:1> <EOL> self . __connections = updatedConnections <EOL> def __parentChanged ( self , child , oldParent ) : <EOL> self . __setText ( ) <EOL> self . __setupConnections ( reuseUntil = child ) <EOL> def __setText ( self , * unwantedArgs ) : <EOL> graphComponents = [ ] <EOL> n = <NUM_LIT:0> <EOL> g = self . __graphComponent <EOL> while g is not None and n < self . __numComponents : <EOL> graphComponents . append ( g ) <EOL> g = g . parent ( ) <EOL> n += <NUM_LIT:1> <EOL> graphComponents . reverse ( ) <EOL> GafferUI . Label . setText ( self , self . __formatter ( graphComponents ) ) <EOL> def __buttonPress ( self , widget , event ) : <EOL> return self . getGraphComponent ( ) is not None and event . buttons & ( event . Buttons . Left | event . Buttons . Middle ) <EOL> def __dragBegin ( self , widget , event ) : <EOL> if event . buttons & ( event . Buttons . Left | event . Buttons . Middle ) : <EOL> GafferUI . Pointer . setCurrent ( "<STR_LIT>" ) <EOL> return self . getGraphComponent ( ) <EOL> return None <EOL> def __dragEnd ( self , widget , event ) : <EOL> GafferUI . Pointer . setCurrent ( None ) </s>
