<s> """<STR_LIT>""" <EOL> from copy import deepcopy <EOL> import weakref <EOL> from . glir import GlirQueue , BaseGlirParser , GlirParser , glir_logger <EOL> from . wrappers import BaseGlooFunctions <EOL> from . . import config <EOL> _default_dict = dict ( red_size = <NUM_LIT:8> , green_size = <NUM_LIT:8> , blue_size = <NUM_LIT:8> , alpha_size = <NUM_LIT:8> , <EOL> depth_size = <NUM_LIT> , stencil_size = <NUM_LIT:0> , double_buffer = True , <EOL> stereo = False , samples = <NUM_LIT:0> ) <EOL> canvasses = [ ] <EOL> def get_default_config ( ) : <EOL> """<STR_LIT>""" <EOL> return deepcopy ( _default_dict ) <EOL> def get_current_canvas ( ) : <EOL> """<STR_LIT>""" <EOL> cc = [ c ( ) for c in canvasses if c ( ) is not None ] <EOL> if cc : <EOL> return cc [ - <NUM_LIT:1> ] <EOL> else : <EOL> return None <EOL> def set_current_canvas ( canvas ) : <EOL> """<STR_LIT>""" <EOL> canvas . context . _do_CURRENT_command = True <EOL> if canvasses and canvasses [ - <NUM_LIT:1> ] ( ) is canvas : <EOL> return <EOL> cc = [ c ( ) for c in canvasses if c ( ) is not None ] <EOL> while canvas in cc : <EOL> cc . remove ( canvas ) <EOL> cc . append ( canvas ) <EOL> canvasses [ : ] = [ weakref . ref ( c ) for c in cc ] <EOL> def forget_canvas ( canvas ) : <EOL> """<STR_LIT>""" <EOL> cc = [ c ( ) for c in canvasses if c ( ) is not None ] <EOL> while canvas in cc : <EOL> cc . remove ( canvas ) <EOL> canvasses [ : ] = [ weakref . ref ( c ) for c in cc ] <EOL> class GLContext ( BaseGlooFunctions ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , config = None , shared = None ) : <EOL> self . _set_config ( config ) <EOL> self . _shared = shared if ( shared is not None ) else GLShared ( ) <EOL> assert isinstance ( self . _shared , GLShared ) <EOL> self . _glir = GlirQueue ( ) <EOL> self . _do_CURRENT_command = False <EOL> self . _last_viewport = None <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % id ( self ) <EOL> def _set_config ( self , config ) : <EOL> self . _config = deepcopy ( _default_dict ) <EOL> self . _config . update ( config or { } ) <EOL> for key , val in self . _config . items ( ) : <EOL> if key not in _default_dict : <EOL> raise KeyError ( '<STR_LIT>' % key ) <EOL> if not isinstance ( val , type ( _default_dict [ key ] ) ) : <EOL> raise TypeError ( '<STR_LIT>' % key ) <EOL> def create_shared ( self , name , ref ) : <EOL> """<STR_LIT>""" <EOL> if self . _shared is not None : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> self . _shared = GLShared ( name , ref ) <EOL> @ property <EOL> def config ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _config <EOL> @ property <EOL> def glir ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _glir <EOL> @ property <EOL> def shared ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _shared <EOL> @ property <EOL> def capabilities ( self ) : <EOL> """<STR_LIT>""" <EOL> return deepcopy ( self . shared . parser . capabilities ) <EOL> def flush_commands ( self , event = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _do_CURRENT_command : <EOL> self . _do_CURRENT_command = False <EOL> self . shared . parser . parse ( [ ( '<STR_LIT>' , <NUM_LIT:0> ) ] ) <EOL> self . glir . flush ( self . shared . parser ) <EOL> def set_viewport ( self , * args ) : <EOL> BaseGlooFunctions . set_viewport ( self , * args ) <EOL> self . _last_viewport = args <EOL> def get_viewport ( self ) : <EOL> return self . _last_viewport <EOL> class GLShared ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> glir_file = config [ '<STR_LIT>' ] <EOL> parser_cls = GlirParser <EOL> if glir_file : <EOL> parser_cls = glir_logger ( parser_cls , glir_file ) <EOL> self . _parser = parser_cls ( ) <EOL> self . _name = None <EOL> self . _refs = [ ] <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( str ( self . name ) , id ( self ) ) <EOL> @ property <EOL> def parser ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _parser <EOL> @ parser . setter <EOL> def parser ( self , parser ) : <EOL> assert isinstance ( parser , BaseGlirParser ) or parser is None <EOL> self . _parser = parser <EOL> def add_ref ( self , name , ref ) : <EOL> """<STR_LIT>""" <EOL> if self . _name is None : <EOL> self . _name = name <EOL> elif name != self . _name : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . _refs . append ( weakref . ref ( ref ) ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ property <EOL> def ref ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _refs = [ r for r in self . _refs if ( r ( ) is not None ) ] <EOL> ref = self . _refs [ <NUM_LIT:0> ] ( ) if self . _refs else None <EOL> if ref is not None : <EOL> return ref <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> class FakeCanvas ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . context = GLContext ( ) <EOL> set_current_canvas ( self ) <EOL> def flush ( self ) : <EOL> """<STR_LIT>""" <EOL> self . context . flush_commands ( ) </s>
