
    kj1              	          d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
mZ ddlZddlmZ ddlmZmZ ddlmZ ddlmZmZmZmZ dd	lmZ d
ZddgZg dZg dZg dZeez   Z  ej!        e"          Z#de$ddfdZ% G d d          Z&	 d-dee         deej'                 ddfdZ(defdZ)dej'        fdZ*d.de+de,e         fdZ-d/dee+         de,e         fdZ.de/e+         fdZ0defdZ1	 d-de,e         d ee         d!e
ddfd"Z2	 d-de,e         d ee         d!e
defd#Z3d$eddfd%Z4dej5        fd&Z6	 d-d!ee
         d'eej5                 dej7        fd(Z8d)ee+         dee9         fd*Z:d)e+de;e$e$f         fd+Z<d)e+de=fd,Z>dS )0zF
General helper functions aiding in the boostrapping of this library.
    N)Path)AnyOptional)settings)
BaseWindowWindowConfig)Timer)AZERTYQWERTYKeyMapKeyMapFactory)import_stringz3.1.1__pycache__base)glfwheadlesspygame2pygletpyqt5pyside2sdl2tk)yesontruety1)noofffalsefn0levelreturnc                 \   | dS t           j        sdt           _        t                               |            t	          j                    }|                    t          j                   |                    t	          j        d                     t           	                    |           dS dS )zGSet up basic logging

    Args:
        level (int): The log level
    NFz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)
loggerhandlers	propagatesetLevelloggingStreamHandlerDEBUGsetFormatter	Formatter
addHandler)r%   chs     S/home/agentuser/manim-venv/lib/python3.11/site-packages/moderngl_window/__init__.pysetup_basic_loggingr4   2   s     } ?  "$$
GM"""
)*`aabbb"     c                   R    e Zd ZU dZdZee         ed<   dZee	j
                 ed<   dS )ContextRefsz'Namespace for window/context referencesNWINDOWCONTEXT)__name__
__module____qualname____doc__r8   r   r   __annotations__r9   modernglContext r5   r3   r7   r7   E   sE         11#'FHZ '''*.GXh&'.....r5   r7   windowctxc                 `    | t           _        |t           _        || j        t           _        dS dS )a&  
    Register the active window and context.
    If only a window is supplied the context is taken from the window.
    Only a context can also be passed in.

    Keyword Args:
        window (window): The window to activate
        ctx (moderngl.Context): The moderngl context to activate
    N)r7   r8   r9   rC   )rB   rC   s     r3   activate_contextrE   L   s0      KK
{$j {r5   c                  P    t           j        rt           j        S t          d          )zObtain the active window3No active window and context. Call activate_window.)r7   r8   
ValueErrorrA   r5   r3   rB   rB   ^   s%     "!!
J
K
KKr5   c                  P    t           j        rt           j        S t          d          )zObtain the active contextrG   )r7   r9   rH   rA   r5   r3   rC   rC   f   s%     #""
J
K
KKr5    c                 Z    t                               d|            t          |           }|S )a'  
    Attempt to obtain a window class using the full dotted
    python path. This can be used to import custom or modified
    window classes.

    Args:
        window (str): Name of the window

    Returns:
        A reference to the requested window class. Raises exception if not found.
    z#Attempting to load window class: %s)r(   infor   )rB   wins     r3   get_window_clsrN   n   s-     KK5v>>>


C
 Jr5   c                     t           j                            d          p| } | d} t          d                    |                     S )a  
    Attempt to obtain a window class in the moderngl_window package
    using short window names such as ``pyglet`` or ``glfw``.

    Args:
        window (str): Name of the window

    Returns:
        A reference to the requested window class. Raises exception if not found.
    MODERNGL_WINDOWNr   z!moderngl_window.context.{}.Window)osenvirongetrN   formatrB   s    r3   get_local_window_clsrV      sD     Z^^-..8&F~=DDVLLMMMr5   c                      	 d t          t                    j                            d                                          D             S # t
          $ r
 t          cY S w xY w)za
    Find available window packages
    Returns:
        A list of available window packages
    c                 x    g | ]7}|                                 r!|j        d          t          v*|j        d          8S ))is_dirpartsIGNORE_DIRS).0paths     r3   
<listcomp>z'find_window_classes.<locals>.<listcomp>   sK     
 
 
{{}}
 "&B{!B!B JrN!B!B!Br5   context)r   __file__parentjoinpathiterdir	ExceptionWINDOW_CLASSESrA   r5   r3   find_window_classesrg      st    
 
X-66yAAIIKK
 
 
 	

    s   AA
 
AAc                      t          t          j        d                   }  | di t          j        }t          |t                    sJ t          |           d            t          |           |S )z
    Creates a window using configured values in :py:attr:`moderngl_window.conf.Settings.WINDOW`.
    This will also activate the window/context.

    Returns:
        The Window instance
    classz< is not derived from moderngl_window.context.base.BaseWindowrU   rA   )r   r   r8   
isinstancer   typerE   )
window_clsrB   s     r3   create_window_from_settingsrm      s     xw788JZ**(/**F
  U U
v,,TTTU U  F####Mr5   
config_clstimerargsc                 H    t          | ||          }t          |           dS )z
    Run an WindowConfig entering a blocking main loop

    Args:
        config_cls: The WindowConfig class to render
    Keyword Args:
        timer: A custom timer instance
        args: Override sys.args
    )ro   rp   N)create_window_config_instancerun_window_config_instance)rn   ro   rp   configs       r3   run_window_configru      s,     +:UNNNFv&&&&&r5   c                    t          | j                   t                      }|                     |           t	          ||          }|| _        t          |j                  }|j        p| j	        }t          |d         |j        z            t          |d         |j        z            f}|j        }|| j        } || j        || j        p|j        |j        |j        n| j        | j        | j        | j        |j        |j        n| j        |j        |j        n| j        ||nd|j        | j                  }|                                 t1          |           |t3                      } | |j        ||          }	t7          j        |	          |_        |                                 |                                 |	S )	a  
    Create and initialize a instance of a WindowConfig class.
    Quite a bit of boilerplate is required to create a WindowConfig instance
    and this function aims to simplify that.

    Args:
        window_config: The WindowConfig class to create an instance of
    Keyword Args:
        kwargs: Arguments to pass to the WindowConfig constructor
    Returns:
        An instance of the WindowConfig class
    rp   parserr      NT)titlesize
fullscreen	resizablevisible
gl_versionaspect_ratiovsyncsamplescursorbackendcontext_creation_funcrU   )rC   wndro   ) r4   	log_levelcreate_parseradd_arguments
parse_argsargvrV   rB   r{   window_sizeint	size_multr   rz   r|   r}   r~   r   r   r   r   r   init_mgl_contextprint_context_inforE   r	   rC   weakrefref_configswap_buffersset_default_viewport)
rn   ro   rp   rx   valuesrl   r{   show_cursorrB   rt   s
             r3   rr   rr      s    
,---__FV$$$T&111FJO%fm44J ;0*0DtAw))**CQ&:J0J,K,KKD -K 'Z(=F,='-'7'C6##I]"(,$l6fllJ<L"(."<*BT)5{{4(9  F F####}ZFJF%@@@F [((FN
 
!!!Mr5   rt   c                    | j         }| j        }|                                 |j        s|                                \  }}|j        s4| j        dk    r)d| j        z  }||z
  }|dk    rt          j        |           | j	         |j
        | j	          |                                 |                    ||           |j        s|                                 |j        |                                \  }}|                                 |dk    r5t                               d                    ||j                             dS dS )z
    Run an WindowConfig instance entering a blocking main loop.

    Args:
        window_config: The WindowConfig instance
    r         ?Nz Duration: {0:.2f}s @ {1:.2f} FPS)r   ro   start
is_closing
next_framer~   hidden_window_framerate_limittimesleepclear_colorclearuserenderr   stopdestroyr(   rL   rT   fps_average)	rt   rB   ro   current_timedeltaexpected_delta_time
sleep_time_durations	            r3   rs   rs     sQ    ZFLE	KKMMM "#..00e ~ 	'&"F"J"J"%(L"L,u4JA~~
:&&&)FL&,-- 	

lE***  	"!!!'  "* **,,KAx
NN!||6==hHYZZ[[[[[ |r5   c                  |   t          j                    } |                     ddt                      d           |                     dddd	           |                     d
dt          d           |                     ddt          dd           |                     ddt          dd           |                     ddt
          d           |                     ddt          d           |                     dt          d           |                     dt          d d!           |                     d"d#$           | S )%zCCreate an argparser parsing the standard arguments for WindowConfigz-wndz--windowzName for the window type to use)choiceshelpz-fsz--fullscreen
store_truez"Open the window in fullscreen mode)actionr   z-vsz--vsynczEnable or disable vsync)rk   r   z-rz--resizableNzEnable/disable window resize)rk   defaultr   z-hdz--hiddenFzStart the window in hidden modez-sz	--samplesz>Specify the desired number of samples to use for multisamplingz-cz--cursorz-Enable or disable displaying the mouse cursorz--sizezWindow sizez--size_multr   z>Multiplier for the window size making it easy scale the windowz	--backendzKSpecify context backend. This is mostly used to enable EGL in headless mode)r   )argparseArgumentParseradd_argumentrg   
valid_boolr   valid_window_sizevalid_window_size_multiplier)rx   s    r3   r   r   2  s   $&&F
#%%.	     1	     &	     +     .     M	     <	         
 )M	     Z     Mr5   rx   c                 t    |pt                      }|                    | pt          j        dd                   S )zParse arguments from sys.argv

    Passing in your own argparser can be user to extend the parser.

    Keyword Args:
        args: override for sys.argv
        parser: Supply your own argparser instance
    ry   N)r   r   sysr   rw   s     r3   r   r   t  s5     &}FT1SXabb\222r5   valuec                     | dS |                                  } | t          v rdS | t          v rdS t          j        dt
                     )zValidator for bool valuesNTFz!Boolean value expected. Options: )lowerOPTIONS_TRUEOPTIONS_FALSEr   ArgumentTypeErrorOPTIONS_ALL)r   s    r3   r   r     sS    }tKKMMEtu

$%V%V%V
W
WWr5   c                     	 |                      d          \  }}t          |          t          |          fS # t          $ r Y nw xY wt          j        d          )zk
    Validator for window size parameter.

    Valid format is "[int]x[int]". For example "1920x1080".
    xz2Valid size format: int]x[int]. Example '1920x1080')splitr   rH   r   r   )r   widthheights      r3   r   r     sm    C((v5zz3v;;&&    
$<  s   58 
AAc                 |    	 t          |           }|dk    r|S n# t          $ r Y nw xY wt          j        d          )zUValidates window size multiplier

    Must be an integer or float greater than 0
    r   zMust be a positive int or float)floatrH   r   r   )r   vals     r3   r   r     s_    
Ell77J     
$)  s    
'')NN)rJ   )N)?r=   r   r,   rQ   r   r   r   pathlibr   typingr   r   r?   moderngl_window.confr   moderngl_window.context.baser   r   moderngl_window.timers.clockr	   moderngl_window.utils.keymapsr
   r   r   r   $moderngl_window.utils.module_loadingr   __version__r\   rf   r   r   r   	getLoggerr:   r(   r   r4   r7   r@   rE   rB   rC   strrk   rN   rV   listrg   rm   ru   rr   rs   r   r   	Namespacer   boolr   tupler   r   r   rA   r5   r3   <module>r      s^      				 



                          ) ) ) ) ) ) A A A A A A A A . . . . . . O O O O O O O O O O O O > > > > > > 
	 	 	 433555]* 
	8	$	$s t    &/ / / / / / / / LP) )Z ).6x7G.H)	) ) ) )$L
 L L L LLX L L L L 3 Z(8    *N N# N$z:J N N N N$T#Y    $Z    , PT' '\"'+3E?'IL'	' ' ' '" PT< <\"<+3E?<IL<< < < <~$\| $\ $\ $\ $\ $\N?x. ? ? ? ?F MQ3 3
3-3(01H(I33 3 3 3$Xhsm X X X X XS U38_    "       r5   