<s> import re <EOL> import time <EOL> import fnmatch <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class InfoPathFilterWidget ( GafferUI . PathFilterWidget ) : <EOL> def __init__ ( self , pathFilter , parenting = None ) : <EOL> self . __row = GafferUI . ListContainer ( GafferUI . ListContainer . Orientation . Horizontal , spacing = <NUM_LIT:2> , borderWidth = <NUM_LIT:0> ) <EOL> GafferUI . PathFilterWidget . __init__ ( self , self . __row , pathFilter , parenting = parenting ) <EOL> with self . __row : <EOL> filterButton = GafferUI . Button ( image = "<STR_LIT>" , hasFrame = False ) <EOL> self . __filterButtonClickedConnection = filterButton . clickedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __buttonClicked ) ) <EOL> self . __filterText = GafferUI . TextWidget ( ) <EOL> if hasattr ( self . __filterText . _qtWidget ( ) , "<STR_LIT>" ) : <EOL> self . __filterText . _qtWidget ( ) . setPlaceholderText ( "<STR_LIT>" ) <EOL> self . __filterEditingFinishedConnection = self . __filterText . editingFinishedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __filterEditingFinished ) ) <EOL> self . __filterTextChangedConnection = self . __filterText . textChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __filterTextChanged ) ) <EOL> def _updateFromPathFilter ( self ) : <EOL> pass <EOL> def __filterEditingFinished ( self , textWidget ) : <EOL> assert ( textWidget is self . __filterText ) <EOL> self . __updateFilter ( ) <EOL> def __filterTextChanged ( self , textWidget ) : <EOL> assert ( textWidget is self . __filterText ) <EOL> if self . __filterText . getText ( ) == "<STR_LIT>" : <EOL> self . __updateFilter ( ) <EOL> def __updateFilter ( self , newInfoKey = None ) : <EOL> infoKey , matcher = self . pathFilter ( ) . getMatcher ( ) <EOL> if newInfoKey is not None : <EOL> infoKey = newInfoKey <EOL> t = self . __filterText . getText ( ) <EOL> if t == "<STR_LIT>" : <EOL> matcher = None <EOL> else : <EOL> if "<STR_LIT:?>" not in t and "<STR_LIT:*>" not in t : <EOL> t = "<STR_LIT:*>" + t + "<STR_LIT:*>" <EOL> stringifier = str <EOL> if infoKey == "<STR_LIT>" : <EOL> stringifier = time . ctime <EOL> regex = re . compile ( fnmatch . translate ( t ) ) <EOL> matcher = lambda v : regex . match ( stringifier ( v ) ) is not None <EOL> self . pathFilter ( ) . setMatcher ( infoKey , matcher ) <EOL> def __buttonClicked ( self , button ) : <EOL> infoFields = ( <EOL> ( "<STR_LIT:name>" , "<STR_LIT:Name>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ) <EOL> menuDefinition = IECore . MenuDefinition ( ) <EOL> for key , label in infoFields : <EOL> menuDefinition . append ( "<STR_LIT:/>" + label , { "<STR_LIT>" : IECore . curry ( Gaffer . WeakMethod ( self . __setInfoKey ) , self . pathFilter ( ) , key ) , "<STR_LIT>" : key == self . pathFilter ( ) . getMatcher ( ) [ <NUM_LIT:0> ] } ) <EOL> self . __menu = GafferUI . Menu ( menuDefinition ) <EOL> self . __menu . popup ( ) <EOL> def __setInfoKey ( self , filter , infoKey , checked ) : <EOL> self . __updateFilter ( newInfoKey = infoKey ) <EOL> GafferUI . PathFilterWidget . registerType ( Gaffer . InfoPathFilter , InfoPathFilterWidget ) </s>
