<s> import os <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class FileIndexedIOPathPreview ( GafferUI . DeferredPathPreview ) : <EOL> def __init__ ( self , path ) : <EOL> tmpPath = Gaffer . DictPath ( { } , "<STR_LIT:/>" ) <EOL> with GafferUI . ListContainer ( borderWidth = <NUM_LIT:8> , spacing = <NUM_LIT:8> ) as column : <EOL> self . __pathWidget = GafferUI . PathWidget ( tmpPath ) <EOL> with GafferUI . SplitContainer ( GafferUI . ListContainer . Orientation . Horizontal ) : <EOL> self . __pathListing = GafferUI . PathListingWidget ( <EOL> tmpPath , <EOL> columns = [ <EOL> GafferUI . PathListingWidget . defaultNameColumn , <EOL> GafferUI . PathListingWidget . defaultIndexedIODataTypeColumn , <EOL> ] , <EOL> displayMode = GafferUI . PathListingWidget . DisplayMode . Tree , <EOL> ) <EOL> self . __pathPreview = GafferUI . DataPathPreview ( tmpPath ) <EOL> GafferUI . DeferredPathPreview . __init__ ( self , column , path ) <EOL> self . __prevPath = tmpPath <EOL> self . _updateFromPath ( ) <EOL> def isValid ( self ) : <EOL> if not isinstance ( self . getPath ( ) , Gaffer . FileSystemPath ) or not self . getPath ( ) . isLeaf ( ) : <EOL> return False <EOL> if os . path . splitext ( self . getPath ( ) [ - <NUM_LIT:1> ] ) [ <NUM_LIT:1> ] not in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return False <EOL> return True <EOL> def _load ( self ) : <EOL> return IECore . FileIndexedIO ( str ( self . getPath ( ) ) , IECore . IndexedIO . OpenMode . Read ) <EOL> def _deferredUpdate ( self , indexedIO ) : <EOL> self . __indexedIOPath = Gaffer . IndexedIOPath ( indexedIO , "<STR_LIT:/>" ) <EOL> self . __indexedIOPathChangedConnection = self . __indexedIOPath . pathChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __indexedIOPathChanged ) ) <EOL> self . __pathWidget . setPath ( self . __indexedIOPath ) <EOL> self . __pathPreview . setPath ( self . __indexedIOPath ) <EOL> listingPath = Gaffer . IndexedIOPath ( indexedIO , "<STR_LIT:/>" ) <EOL> self . __pathListing . setPath ( listingPath ) <EOL> self . __pathListingSelectionChangedConnection = self . __pathListing . selectionChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __pathListingSelectionChanged ) ) <EOL> def __indexedIOPathChanged ( self , path ) : <EOL> pathCopy = path . copy ( ) <EOL> pathCopy . truncateUntilValid ( ) <EOL> with Gaffer . BlockedConnection ( self . __pathListingSelectionChangedConnection ) : <EOL> self . __pathListing . setSelectedPaths ( [ pathCopy ] , expandNonLeaf = False ) <EOL> if len ( pathCopy ) > len ( self . __prevPath ) : <EOL> self . __pathListing . setPathExpanded ( pathCopy , True ) <EOL> else : <EOL> while len ( pathCopy ) < len ( self . __prevPath ) : <EOL> self . __pathListing . setPathExpanded ( self . __prevPath , False ) <EOL> del self . __prevPath [ - <NUM_LIT:1> ] <EOL> self . __prevPath = pathCopy <EOL> def __pathListingSelectionChanged ( self , pathListing ) : <EOL> selection = pathListing . getSelectedPaths ( ) <EOL> if len ( selection ) : <EOL> with Gaffer . BlockedConnection ( self . __indexedIOPathChangedConnection ) : <EOL> self . __indexedIOPath [ : ] = selection [ <NUM_LIT:0> ] [ : ] <EOL> GafferUI . PathPreviewWidget . registerType ( "<STR_LIT>" , FileIndexedIOPathPreview ) </s>
