<s> import types <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> import GafferScene <EOL> Gaffer . Metadata . registerNode ( <EOL> GafferScene . PathFilter , <EOL> "<STR_LIT:description>" , <EOL> """<STR_LIT>""" , <EOL> plugs = { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT:description>" , <EOL> """<STR_LIT>""" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , True , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> ] , <EOL> } <EOL> ) <EOL> GafferUI . Pointer . registerPointer ( "<STR_LIT>" , GafferUI . Pointer ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> GafferUI . Pointer . registerPointer ( "<STR_LIT>" , GafferUI . Pointer ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> GafferUI . Pointer . registerPointer ( "<STR_LIT>" , GafferUI . Pointer ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> __DropMode = IECore . Enum . create ( "<STR_LIT:None>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> __originalDragPointer = None <EOL> def __pathsPlug ( node ) : <EOL> for plug in node . children ( Gaffer . Plug ) : <EOL> if Gaffer . Metadata . plugValue ( plug , "<STR_LIT>" ) : <EOL> return plug <EOL> return None <EOL> def __dropMode ( nodeGadget , event ) : <EOL> if __pathsPlug ( nodeGadget . node ( ) ) is None : <EOL> filter = None <EOL> if nodeGadget . node ( ) [ "<STR_LIT>" ] . getInput ( ) is not None : <EOL> filter = nodeGadget . node ( ) [ "<STR_LIT>" ] . source ( ) . node ( ) <EOL> if filter is None : <EOL> return __DropMode . Replace <EOL> elif not isinstance ( filter , GafferScene . PathFilter ) : <EOL> return __DropMode . None <EOL> if event . modifiers & event . Modifiers . Shift : <EOL> return __DropMode . Add <EOL> elif event . modifiers & event . Modifiers . Control : <EOL> return __DropMode . Remove <EOL> else : <EOL> return __DropMode . Replace <EOL> def __dragEnter ( nodeGadget , event ) : <EOL> if not isinstance ( event . data , IECore . StringVectorData ) : <EOL> return False <EOL> if not len ( event . data ) : <EOL> return False <EOL> if not event . data [ <NUM_LIT:0> ] . startswith ( "<STR_LIT:/>" ) : <EOL> return False <EOL> if __dropMode ( nodeGadget , event ) == __DropMode . None : <EOL> return False <EOL> global __originalDragPointer <EOL> __originalDragPointer = GafferUI . Pointer . getCurrent ( ) <EOL> return True <EOL> def __dragLeave ( nodeGadget , event ) : <EOL> global __originalDragPointer <EOL> GafferUI . Pointer . setCurrent ( __originalDragPointer ) <EOL> __originalDragPointer = None <EOL> return True <EOL> def __dragMove ( nodeGadget , event ) : <EOL> global __originalDragPointer <EOL> if __originalDragPointer is None : <EOL> return False <EOL> GafferUI . Pointer . setCurrent ( str ( __dropMode ( nodeGadget , event ) ) . lower ( ) + "<STR_LIT>" ) <EOL> return True <EOL> def __drop ( nodeGadget , event ) : <EOL> global __originalDragPointer <EOL> if __originalDragPointer is None : <EOL> return False <EOL> pathsPlug = __pathsPlug ( nodeGadget . node ( ) ) <EOL> if pathsPlug is None : <EOL> pathsPlug = __pathsPlug ( nodeGadget . node ( ) [ "<STR_LIT>" ] . source ( ) . node ( ) ) <EOL> dropMode = __dropMode ( nodeGadget , event ) <EOL> if dropMode == __DropMode . Replace : <EOL> paths = sorted ( event . data ) <EOL> elif dropMode == __DropMode . Add : <EOL> paths = set ( pathsPlug . getValue ( ) ) <EOL> paths . update ( event . data ) <EOL> paths = sorted ( paths ) <EOL> else : <EOL> paths = set ( pathsPlug . getValue ( ) ) <EOL> paths . difference_update ( event . data ) <EOL> paths = sorted ( paths ) <EOL> with Gaffer . UndoContext ( nodeGadget . node ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> if pathsPlug is None : <EOL> pathFilter = GafferScene . PathFilter ( ) <EOL> nodeGadget . node ( ) . parent ( ) . addChild ( pathFilter ) <EOL> nodeGadget . node ( ) [ "<STR_LIT>" ] . setInput ( pathFilter [ "<STR_LIT>" ] ) <EOL> graphGadget = nodeGadget . ancestor ( GafferUI . GraphGadget ) <EOL> graphGadget . getLayout ( ) . positionNode ( graphGadget , pathFilter ) <EOL> pathsPlug = pathFilter [ "<STR_LIT>" ] <EOL> pathsPlug . setValue ( IECore . StringVectorData ( paths ) ) <EOL> GafferUI . Pointer . setCurrent ( __originalDragPointer ) <EOL> __originalDragPointer = None <EOL> return True <EOL> def addObjectDropTarget ( nodeGadget ) : <EOL> nodeGadget . dragEnterSignal ( ) . connect ( __dragEnter , scoped = False ) <EOL> nodeGadget . dragLeaveSignal ( ) . connect ( __dragLeave , scoped = False ) <EOL> nodeGadget . dragMoveSignal ( ) . connect ( __dragMove , scoped = False ) <EOL> nodeGadget . dropSignal ( ) . connect ( __drop , scoped = False ) <EOL> def __nodeGadget ( pathFilter ) : <EOL> nodeGadget = GafferUI . StandardNodeGadget ( pathFilter ) <EOL> addObjectDropTarget ( nodeGadget ) <EOL> return nodeGadget <EOL> GafferUI . NodeGadget . registerNodeGadget ( GafferScene . PathFilter , __nodeGadget ) </s>
