
    ^jL-                    R   d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
mZmZ erd dlmZ d dlmZ  eed          oej        Z G d d	          Z G d
 dej                  Ze                    d           e                    d           e                    d           dS )    )annotationsN)TYPE_CHECKINGAnyCallable)appclockevent)EventDispatcher)
BaseWindowis_pyglet_doc_runc                  \    e Zd ZdZddZddZddZddZddZddZ	dddZ
d dZddZdS )!PlatformEventLoopzSAbstract class, implementation depends on platform.

    .. versionadded:: 1.2
    returnNonec                f    t          j                    | _        t          j                    | _        d S N)queueQueue_event_queue	threadingEvent_is_runningselfs    J/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/app/base.py__init__zPlatformEventLoop.__init__   s&    !KMM$?,,    boolc                4    | j                                         S )zIf the event loop is currently processing.

        ``True`` if running, or ``False`` if it is blocked or not activated.
        )r   is_setr   s    r   
is_runningzPlatformEventLoop.is_running   s    
 &&(((r   
dispatcherr
   r	   strargsr   c                h    | j                             |||f           |                                  dS )a  Post an event into the main application thread.

        The event is queued internally until the :py:meth:`run` method's thread
        is able to dispatch the event.  This method can be safely called
        from any thread.

        If the method is called from the :py:meth:`run` method's thread (for
        example, from within an event handler), the event may be dispatched
        within the same runloop iteration or the next one; the choice is
        nondeterministic.
        N)r   putnotify)r   r"   r	   r$   s       r   
post_eventzPlatformEventLoop.post_event!   s3     	z5$7888r   c                    	 	 | j                             d          \  }}} |j        |g|R   n!# t          j        $ r Y dS t
          $ r Y nw xY wP)zzImmediately dispatch all pending events.

        Normally this is called automatically by the runloop iteration.
        TFN)r   getdispatch_eventr   EmptyReferenceError)r   r"   evntr$   s       r   dispatch_posted_eventsz(PlatformEventLoop.dispatch_posted_events0   s    
	)-):)>)>u)E)E&
D$)
)$666666;   !   	s   ,0 A	AAc                     t          d          )a  Notify the event loop that something needs processing.

        If the event loop is blocked, it will unblock and perform an iteration
        immediately.  If the event loop is running, another iteration is
        scheduled for immediate execution afterward.
        abstractNotImplementedErrorr   s    r   r'   zPlatformEventLoop.notify?   s     "*---r   c                    d S r    r   s    r   startzPlatformEventLoop.startH       r   NtimeoutNone | floatc                     t          d          )Nr1   r2   r   r8   s     r   stepzPlatformEventLoop.stepK   s    !*---r   funcr   intervalfloatc                    d S r   r5   )r   r=   r>   s      r   	set_timerzPlatformEventLoop.set_timerN   r7   r   c                    d S r   r5   r   s    r   stopzPlatformEventLoop.stopQ   r7   r   r   r   r   r   )r"   r
   r	   r#   r$   r   r   r   r   )r8   r9   r   r   )r=   r   r>   r?   r   r   )__name__
__module____qualname____doc__r   r!   r(   r/   r'   r6   r<   rA   rC   r5   r   r   r   r      s         - - - -) ) ) )      . . . .   . . . . .        r   r   c                      e Zd ZdZdZdZd dZed!d	            Zd"d#dZ	d dZ
ed d            Zd dZd$dZed%d            Zej        d&d            Zd dZd'dZd(dZerd(dZd dZd dZdS dS ))	EventLoopa  The main run loop of the application.

    Calling `run` begins the application event loop, which processes
    operating system events, calls :py:func:`pyglet.clock.tick` to call
    scheduled functions and calls :py:meth:`pyglet.window.Window.on_draw` and
    :py:meth:`pyglet.window.Window.flip` to update window contents.

    Applications can subclass :py:class:`EventLoop` and override certain methods
    to integrate another framework's run loop, or to customise processing
    in some other way.  You should not in general override :py:meth:`run`, as
    this method contains platform-specific code that ensures the application
    remains responsive to the user while keeping CPU usage to a minimum.
    NFr   r   c                    t          j                    | _        t          j                    | _        d| _        d | _        d S )NF)r   	Condition_has_exit_conditionr   get_defaultr!   	_intervalr   s    r   r   zEventLoop.__init__g   s5    #,#6#8#8 &((
r   dtr?   c                N    t           j        D ]}|                    |            d S r   )r   windowsdraw)rQ   windows     r   _redraw_windowszEventLoop._redraw_windowsm   s0     k 	 	FKKOOOO	 	r   ?r>   float | Nonec                   || _         |nF|dk    r | j                            | j                   n | j                            | j        |           d| _        ddlm} d|_        t          j
        D ]*}|                                 |                                 +t          j        }|                                 |                     d           d| _        | j        s0|                                 }|                    |           | j        0d| _        |                     d           |                                 dS )a  Begin processing events, scheduled functions and window updates.

        This method enters into the main event loop and, if the ``interval``
        argument is not changed, schedules calling the :py:meth:`pyglet.window.Window.draw`
        method. You can change the ``interval`` argument to suit your needs.

        Args:
            interval:
                Windows redraw interval, in seconds (framerate).
                If ``interval == 0``, windows will redraw as fast as possible.
                This can saturate a CPU core, so do not do this unless GPU bound.
                If ``interval is None``, pyglet will not schedule calls to the
                :py:meth:`pyglet.window.Window.draw` method. Users must schedule
                this themselves for each Window (or call it on-demand). This allows
                setting a custom framerate per window, or changing framerate during
                runtime (see example in the documentation).

        This method returns when :py:attr:`has_exit` is set to True. IE: when
        :py:meth:`exit` is called.

        Developers are discouraged from overriding the ``run`` method, as the
        implementation is platform-specific.
        Nr   F)Windowon_enterTon_exit)rP   r   schedulerV   schedule_intervalhas_exitpyglet.windowrZ   _enable_event_queuer   rS   	switch_todispatch_pending_eventsplatform_event_loopr6   r+   r!   idler<   rC   )r   r>   rZ   rU   rd   r8   s         r   runzEventLoop.runs   sQ   0 "]]J 45555J(()=xHHH((((((%*" k 	- 	-F**,,,,!5!!###J'''- 	.iikkG$$W--- - 	.  I&&&  """""r   c                x    |                                  }t          j                            | j        |           dS )a  Called by pyglet internal processes when the operating system is about to block due to a user interaction.

        For example, this is common when the user begins resizing or moving a window.

        This method provides the event loop with an opportunity to set up
        an OS timer on the platform event loop, which will continue to
        be invoked during the blocking operation.

        The default implementation ensures that :py:meth:`idle` continues to be
        called as documented.

        .. versionadded:: 1.2
        N)re   r   rd   rA   _blocking_timerr;   s     r   enter_blockingzEventLoop.enter_blocking   s3     ))++))$*>HHHHHr   c                 F    t           j                            dd           dS )z}Called by pyglet internal processes when the blocking operation completes.

        :see: :py:meth:`enter_blocking`.
        N)r   rd   rA   r5   r   r   exit_blockingzEventLoop.exit_blocking   s#     	))$55555r   c                "   | j                                         }| j                             |           | j        |                     |           | j                             d          }t          j                            | j	        |           d S )NT)
r   update_timecall_scheduled_functionsrP   rV   get_sleep_timer   rd   rA   rh   )r   rQ   r8   s      r   rh   zEventLoop._blocking_timer   s    Z##%%
++B///>!  $$$ *++D11))$*>HHHHHr   r9   c                    | j                                         }| j                             |           | j                             d          S )ac  Called during each iteration of the event loop.

        The method is called immediately after any window events (i.e., after
        any user input).  The method can return a duration after which
        the idle method will be called again.  The method may be called
        earlier if the user creates more input events.  The method
        can return `None` to only wait for user events.

        For example, return ``1.0`` to have the idle method called every
        second, or immediately after any user events.

        The default implementation dispatches the
        :py:meth:`pyglet.window.Window.on_draw` event for all windows and uses
        :py:func:`pyglet.clock.tick` and :py:func:`pyglet.clock.get_sleep_time`
        on the default clock to determine the return value.

        This method should be overridden by advanced users only.  To have
        code execute at regular intervals, use the
        :py:func:`pyglet.clock.schedule` methods.

        Returns:
            The number of seconds before the idle method should
            be called again, or ``None`` to block for user input.
        T)r   rm   rn   ro   )r   rQ   s     r   re   zEventLoop.idle   sE    2 Z##%%
++B/// z((...r   r   c                x    | j                                          | j        }| j                                          |S )zFlag indicating if the event loop will exit in the next iteration.

        When set, all waiting threads are interrupted.

        :see :py:meth:`sleep`:

        Thread-safe since pyglet 1.2.
        )rN   acquire	_has_exitrelease)r   results     r   r_   zEventLoop.has_exit   s:     	 ((*** ((***r   valuec                    | j                                          || _        | j                                          | j                                          d S r   )rN   rr   rs   r'   rt   )r   rv   s     r   r_   zEventLoop.has_exit   sN     ((*** ''))) ((*****r   c                P    d| _         t          j                                         dS )zSafely exit the event loop at the end of the current iteration.

        This method is a thread-safe equivalent for setting
        :py:attr:`has_exit` to ``True``.  All waiting threads will be
        interrupted (see :py:meth:`sleep`).
        TN)r_   r   rd   r'   r   s    r   exitzEventLoop.exit  s&     &&(((((r   r8   c                    | j                                          | j                             |           | j        }| j                                          |S )a   Wait for some amount of time.

        Waits until the :py:attr:`has_exit` flag is set or :py:meth:`exit` is called.

        This method is thread-safe.

        Args:
            timeout: Time to sleep, in seconds.

        .. versionadded:: 1.2
        )rN   rr   waitrs   rt   )r   r8   ru   s      r   sleepzEventLoop.sleep  sQ     	 ((*** %%g... ((***r   rU   r   c                l    t          t          j                  dk    r|                                  dS dS )zDefault window close handler.r   N)lenr   rS   ry   r   rU   s     r   on_window_closezEventLoop.on_window_close  s0    s{q  IIKKKKK ! r   c                    dS )a  A window was closed.

            This event is dispatched when a window is closed.  It is not
            dispatched if the window's close button was pressed but the
            window did not close.

            The default handler calls :py:meth:`exit` if no more windows are
            open.  You can override this handler to base your application exit
            on some other policy.
            Nr5   r   s     r   r   zEventLoop.on_window_close'        r   c                    dS )zThe event loop is about to begin.

            This is dispatched when the event loop is prepared to enter
            the main run loop, and represents the last chance for an
            application to initialise itself.
            Nr5   r   s    r   r[   zEventLoop.on_enter3  r   r   c                    dS )zThe event loop is about to exit.

            After dispatching this event, the :py:meth:`run` method returns (the
            application may not actually exit if you have more code
            following the :py:meth:`run` invocation).
            Nr5   r   s    r   r\   zEventLoop.on_exit;  r   r   rD   )rQ   r?   r   r   )rW   )r>   rX   r   r   )r   r9   rE   )rv   r   r   r   )r8   r?   r   r   )rU   r   r   r   )rF   rG   rH   rI   rN   rs   r   staticmethodrV   rf   ri   rk   rh   re   propertyr_   setterry   r|   r   _is_pyglet_doc_runr[   r\   r5   r   r   rK   rK   U   s         I       \
6# 6# 6# 6# 6#pI I I I" 6 6 6 \6I I I I/ / / />    X _+ + + _+) ) ) )   $   
  
	 
	 
	 
		 	 	 		 	 	 	 	 	/ r   rK   r   r[   r\   )
__future__r   r   sysr   typingr   r   r   pygletr   r   r	   pyglet.eventr
   r`   r   hasattrr   r   r   rK   register_event_typer5   r   r   <module>r      sd   " " " " " "  



     / / / / / / / / / / $ $ $ $ $ $ $ $ $ $ ),,,,,,((((((WS"566P3;P A A A A A A A AHl l l l l% l l l^ 
  / 0 0 0 	  j ) ) ) 	  i ( ( ( ( (r   