
    \
j/                     :   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 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 )    N)app)clock)event)compat_platformis_pyglet_doc_runc                   J    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zd ZdS )PlatformEventLoopzX Abstract class, implementation depends on platform.
    
    .. versionadded:: 1.2
    c                 f    t          j                    | _        t          j                    | _        d S N)queueQueue_event_queue	threadingEvent_is_runningselfs    I/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/app/base.py__init__zPlatformEventLoop.__init__7   s&    !KMM$?,,    c                 4    | j                                         S )zReturn True if the event loop is currently processing, or False
        if it is blocked or not activated.

        :rtype: bool
        )r   is_setr   s    r   
is_runningzPlatformEventLoop.is_running;   s     &&(((r   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.

        :Parameters:
            `dispatcher` : EventDispatcher
                Dispatcher to process the event.
            `event` : str
                Event name.
            `args` : sequence
                Arguments to pass to the event handlers.

        N)r   putnotify)r   
dispatcherr   argss       r   
post_eventzPlatformEventLoop.post_eventC   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_events[   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 afterwards.
        abstractNotImplementedErrorr   s    r   r   zPlatformEventLoop.notifyj   s     "*---r   c                     d S r    r   s    r   startzPlatformEventLoop.starts       r   Nc                      t          d          Nr(   r)   r   timeouts     r   stepzPlatformEventLoop.stepv       !*---r   c                      t          d          r0   r)   )r   funcintervals      r   	set_timerzPlatformEventLoop.set_timery   r4   r   c                     d S r   r,   r   s    r   stopzPlatformEventLoop.stop|   r.   r   r   )__name__
__module____qualname____doc__r   r   r   r&   r   r-   r3   r8   r:   r,   r   r   r	   r	   1   s         
- - -) ) )  0  . . .  . . . .. . .    r   r	   c                       e Zd ZdZdZdZd Zd Zd Zd Z	d Z
d	 Zd
 Zed             Zej        d             Zd Zd Zd Zerd Zd Z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.
    NFc                 t    t          j                    | _        t          j                    | _        d| _        d S )NF)r   	Condition_has_exit_conditionr   get_defaultr   r   s    r   r   zEventLoop.__init__   s.    #,#6#8#8 &((
r   c                    d| _         |                                  t          j        }|                                 |                     d           d| _        | j         s0|                                 }|                    |           | j         0d| _        |                     d           |	                                 dS )a  Begin processing events, scheduled functions and window updates.

        This method returns when :py:attr:`has_exit` is set to True.

        Developers are discouraged from overriding this method, as the
        implementation is platform-specific.
        Fon_enterTon_exitN)
has_exit_legacy_setupr   platform_event_loopr-   r"   r   idler3   r:   )r   rJ   r2   s      r   runzEventLoop.run   s     !5!!###J'''- 	.iikkG$$W--- - 	.  I&&&  """""r   c                     ddl m} d|_        t          j        D ]*}|                                 |                                 +d S )Nr   )WindowF)pyglet.windowrN   _enable_event_queuer   windows	switch_todispatch_pending_events)r   rN   windows      r   rI   zEventLoop._legacy_setup   s`    ((((((%*" k 	- 	-F**,,,,	- 	-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rK   r   rJ   r8   _blocking_timerr1   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   rJ   r8   r   s    r   exit_blockingzEventLoop.exit_blocking   s#     	))$55555r   c                 x    |                                  }t          j                            | j        |           d S r   rV   r1   s     r   rW   zEventLoop._blocking_timer   s1    ))++))$*>HHHHHr   c                 b   | j                                         }| j                             |          }t          j        D ]V}|s|j        rK|j        rD|                                 |                    d           |	                                 d|_        W| j         
                    d          S )ak  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.

        :rtype: float
        :return: The number of seconds before the idle method should
            be called again, or `None` to block for user input.
        on_drawFT)r   update_timecall_scheduled_functionsr   rQ   _legacy_invalidinvalidrR   r"   flipget_sleep_time)r   dt
redraw_allrT   s       r   rK   zEventLoop.idle   s    2 Z##%%Z88<<
 k 	/ 	/F /f4 / /  """%%i000).& z((...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.
    
        :see: `exit`
        :type: bool
        )rC   acquire	_has_exitrelease)r   results     r   rH   zEventLoop.has_exit   s:     	 ((*** ((***r   c                     | j                                          || _        | j                                          | j                                          d S r   )rC   rg   rh   r   ri   )r   values     r   rH   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 for setting 
        :py:attr:`has_exit` to ``True``.  All waiting threads will be
        interrupted (see :py:meth:`sleep`).
        TN)rH   r   rJ   r   r   s    r   exitzEventLoop.exit  s&     &&(((((r   c                     | j                                          | j                             |           | j        }| j                                          |S )a  Wait for some amount of time, or until the :py:attr:`has_exit` flag
        is set or :py:meth:`exit` is called.

        This method is thread-safe.

        :Parameters:
            `timeout` : float
                Time to wait, in seconds.

        .. versionadded:: 1.2

        :rtype: bool
        :return: ``True`` if the `has_exit` flag is set, otherwise ``False``.
        )rC   rg   waitrh   ri   )r   r2   rj   s      r   sleepzEventLoop.sleep  sQ     	 ((*** %%g... ((***r   c                 l    t          t          j                  dk    r|                                  dS dS )zDefault window close handler.r   N)lenr   rQ   rn   r   rT   s     r   on_window_closezEventLoop.on_window_close1  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.

            :event:
            Nr,   rt   s     r   ru   zEventLoop.on_window_close7        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.

            :event:
            Nr,   r   s    r   rF   zEventLoop.on_enterE  rw   r   c                     dS )a  The 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).

            :event:
            Nr,   r   s    r   rG   zEventLoop.on_exitO  rw   r   )r;   r<   r=   r>   rC   rh   r   rL   rI   rX   rZ   rW   rK   propertyrH   setterrn   rq   ru   _is_pyglet_doc_runrF   rG   r,   r   r   r@   r@      sA         I     
# # #0- - -I I I"6 6 6I I I%/ %/ %/N   X _+ + _+) ) )  *  
  !	 	 		 	 		 	 	 	 	3! !r   r@   ru   rF   rG   )sysr   platformr   pygletr   r   r   r   hasattrr   r|   r	   EventDispatcherr@   register_event_typer,   r   r   <module>r      s>  H 


                         " " " " " "WS"566P3;P L L L L L L L L^W W W W W% W W Wt 
  / 0 0 0 	  j ) ) ) 	  i ( ( ( ( (r   