o
    oh                      @   sT   d dl mZ d dlmZ d dlmZmZ e ZG dd deZe	dkr(e  dS dS )    )Window)Clock)ThreadLockc                       sZ   e Zd ZdZdZdddddZdd	 Z fd
dZdd Zdd Z	dd Z
dd Z  ZS )ManagedWindowz
    A pyglet window with an event loop which executes automatically
    in a separate thread. Behavior is added by creating a subclass
    which overrides setup, update, and/or draw.
       iX  i  FT)widthheightvsync	resizablec                 K   s@   | ddrdS t| jfi || _t| jd| _| j  dS )z
        It is best not to override this function in the child
        class, unless you need to take additional arguments.
        Do any OpenGL initialization calls in setup().
        runfromdoctesterFN)target)getdictdefault_win_argswin_argsr   __event_loop__start)selfr    r   |/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/plotting/pygletplot/managed_window.py__init__   s
   zManagedWindow.__init__c              
      sF  t   z8zt jdi | j |   |   W n ty6 } ztdt	|  d| _
W Y d}~nd}~ww W t   nt   w t }| j|_| j
s| }t   z?z|   |   |   | | |   |   W n ty } ztdt	|  d| _
W Y d}~nd}~ww W t   nt   w | j
rLt   dS )zv
        The event loop thread function. Do not override or call
        directly (it is called by __init__).
        z Window initialization failed: %sTNz$Uncaught exception in event loop: %sr   )gl_lockacquiresuperr   r   	switch_tosetup	Exceptionprintstrhas_exitreleaser   	fps_limittickdispatch_eventsclearupdatedrawflipclose)r   r   eclockdt	__class__r   r   r   $   sF   
zManagedWindow.__event_loop__c                 C   s
   d| _ dS )z$
        Closes the window.
        TN)r    r   r   r   r   r)   I   s   
zManagedWindow.closec                 C      dS )z
        Called once before the event loop begins.
        Override this method in a child class. This
        is the best place to put things like OpenGL
        initialization calls.
        Nr   r/   r   r   r   r   O      zManagedWindow.setupc                 C   r0   )z
        Called before draw during each iteration of
        the event loop. dt is the elapsed time in
        seconds since the last update. OpenGL rendering
        calls are best put in draw() rather than here.
        Nr   )r   r,   r   r   r   r&   X   r1   zManagedWindow.updatec                 C   r0   )z
        Called after update during each iteration of
        the event loop. Put OpenGL rendering calls
        here.
        Nr   r/   r   r   r   r'   a   s   zManagedWindow.draw)__name__
__module____qualname____doc__r"   r   r   r   r)   r   r&   r'   __classcell__r   r   r-   r   r   	   s    %		r   __main__N)
pyglet.windowr   pyglet.clockr   	threadingr   r   r   r   r2   r   r   r   r   <module>   s    `
