<s> from __future__ import print_function , division <EOL> from pyglet . gl import * <EOL> from pyglet . window import Window <EOL> from pyglet . clock import Clock <EOL> from threading import Thread , Lock <EOL> gl_lock = Lock ( ) <EOL> class ManagedWindow ( Window ) : <EOL> """<STR_LIT>""" <EOL> fps_limit = <NUM_LIT:30> <EOL> default_win_args = dict ( width = <NUM_LIT> , <EOL> height = <NUM_LIT> , <EOL> vsync = False , <EOL> resizable = True ) <EOL> def __init__ ( self , ** win_args ) : <EOL> """<STR_LIT>""" <EOL> if win_args . get ( '<STR_LIT>' , False ) : <EOL> return <EOL> self . win_args = dict ( self . default_win_args , ** win_args ) <EOL> self . Thread = Thread ( target = self . __event_loop__ ) <EOL> self . Thread . start ( ) <EOL> def __event_loop__ ( self , ** win_args ) : <EOL> """<STR_LIT>""" <EOL> gl_lock . acquire ( ) <EOL> try : <EOL> try : <EOL> super ( ManagedWindow , self ) . __init__ ( ** self . win_args ) <EOL> self . switch_to ( ) <EOL> self . setup ( ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" % ( str ( e ) ) ) <EOL> self . has_exit = True <EOL> finally : <EOL> gl_lock . release ( ) <EOL> clock = Clock ( ) <EOL> clock . set_fps_limit ( self . fps_limit ) <EOL> while not self . has_exit : <EOL> dt = clock . tick ( ) <EOL> gl_lock . acquire ( ) <EOL> try : <EOL> try : <EOL> self . switch_to ( ) <EOL> self . dispatch_events ( ) <EOL> self . clear ( ) <EOL> self . update ( dt ) <EOL> self . draw ( ) <EOL> self . flip ( ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" % str ( e ) ) <EOL> self . has_exit = True <EOL> finally : <EOL> gl_lock . release ( ) <EOL> super ( ManagedWindow , self ) . close ( ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . has_exit = True <EOL> def setup ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def update ( self , dt ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def draw ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> ManagedWindow ( ) </s>
