<s> from . . shaders import Function <EOL> from . . transforms import NullTransform <EOL> from ... geometry import Rect <EOL> clip_frag = """<STR_LIT>""" <EOL> class Clipper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , bounds = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) , transform = None ) : <EOL> self . clip_shader = Function ( clip_frag ) <EOL> self . clip_expr = self . clip_shader ( ) <EOL> self . bounds = bounds <EOL> if transform is None : <EOL> transform = NullTransform ( ) <EOL> self . _transform = None <EOL> self . transform = transform <EOL> @ property <EOL> def bounds ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _bounds <EOL> @ bounds . setter <EOL> def bounds ( self , b ) : <EOL> self . _bounds = Rect ( b ) . normalized ( ) <EOL> b = self . _bounds <EOL> self . clip_shader [ '<STR_LIT>' ] = ( b . left , b . right , b . bottom , b . top ) <EOL> @ property <EOL> def transform ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _transform <EOL> @ transform . setter <EOL> def transform ( self , tr ) : <EOL> if tr is self . _transform : <EOL> return <EOL> self . _transform = tr <EOL> self . clip_shader [ '<STR_LIT>' ] = tr <EOL> def _attach ( self , visual ) : <EOL> try : <EOL> hook = visual . _get_hook ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except KeyError : <EOL> raise NotImplementedError ( "<STR_LIT>" % <EOL> visual ) <EOL> hook . add ( self . clip_expr , position = <NUM_LIT:1> ) <EOL> def _detach ( self , visual ) : <EOL> visual . _get_hook ( '<STR_LIT>' , '<STR_LIT>' ) . remove ( self . clip_expr ) </s>
