
    ^jb*                       d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZmZmZmZ  e
j        d          Z e
j        d          Z e
j        d          Z e
j        d	          Z e
j        d
          Z e
j        d          Z e
j        d          Z e
j        d          Zd Zd Z G d d          Z ed          Z G d de          Z G d de          ZdS )    )annotationsN)app)PlatformEventLoop	EventLoop)cocoapyAutoReleasePoolObjCSubclassPyObjectEncodingObjCInstance
send_super	ObjCClassget_selectorNSApplicationNSMenu
NSMenuItemNSDateNSEventNSUserDefaultsNSTimerNSRunningApplicationc                z   t                      5  t          j        |          }t          j        |          }t          j        |          }t                                                              |||          }|                     |           |                                 d d d            d S # 1 swxY w Y   d S N)	r   r   CFSTRr   r   alloc#initWithTitle_action_keyEquivalent_addItem_release)menutitleactionkeymenuItems        K/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/app/cocoa.pyadd_menu_itemr$      s    			 	 	e$$%f--mC  ##%%II63   h 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB00B47B4c                    t                      5  t                                                                          } t	          | ddd           |                     t                                                     t	          | ddd           t                                                                          }t                                                                          }|                    |            |                    |           t          
                                }|                    |           |                                  |                                 |                                 d d d            d S # 1 swxY w Y   d S )NzHide!zhide:hzQuit!z
terminate:q)r   r   r   initr$   r   r   separatorItemsetSubmenu_r   sharedApplicationsetMainMenu_r   )appMenumenubarappMenuItemNSApps       r#   create_menur1   "   s   			  ,,..%%'' 	gw5551133444gwc:::,,..%%'' &&((--//(((%%%//117### 	%                 s   E&FF	Fc                     e Zd Z edd          Ze                    dez             d             Ze                    d          d             Ze                    d          d             Z	e                    d          d	             Z
e                    d          d
             Ze                    d          d             ZdS )_AppDelegate_ImplementationNSObject_AppDelegate   @c                N    t          t          | d                    }|| _        |S )Nr(   )r   r   _pyglet_loop)selfpyglet_loopobjcs      r#   r(   z _AppDelegate_Implementation.init;   s&    JtV4455'    vc                8    | j                                          d S r   )r8   
nsapp_stepr9   s    r#   updatePyglet_z)_AppDelegate_Implementation.updatePyglet_A   s    $$&&&&&r<   zv@c                6    d| j         _        d| j         _        d S )NFT)r8   
is_runninghas_exitr9   notifications     r#   applicationWillTerminate_z5_AppDelegate_Implementation.applicationWillTerminate_E   s    ',$%)"""r<   c                   d| j         _        t                                          }t	          j        d          }t                              |          }|                                }t          |          D ]6}|
                    |          }|                    t          j                    t          j        d           |                    d           d S )NTzcom.apple.dockg{Gz?)r8   _finished_launchingr   r+   r   get_NSStringr   (runningApplicationsWithBundleIdentifier_countrangeobjectAtIndex_activateWithOptions_&NSApplicationActivateIgnoringOtherAppstimesleepactivateIgnoringOtherApps_)r9   rF   r0   dock_strrunning_apps	app_countirunning_apps           r#   applicationDidFinishLaunching_z:_AppDelegate_Implementation.applicationDidFinishLaunching_J   s    04- //11 '(899+TTU]^^ &&((	y!! 	 	A&55a88K,,W-[\\\ 	
4((.....r<   c                    d S r    rE   s     r#   applicationWillFinishLaunching_z;_AppDelegate_Implementation.applicationWillFinishLaunching_b   s    r<   Bc                    dS NTr[   r@   s    r#   )applicationSupportsSecureRestorableState_zE_AppDelegate_Implementation.applicationSupportsSecureRestorableState_f   s    tr<   N)__name__
__module____qualname__r	   r5   methodr
   r(   rA   rG   rY   r\   r`   r[   r<   r#   r3   r3   8   s%       <
N;;L 0011  21
 ' ' ' * * * / / /.        r<   r3   r5   c                  2     e Zd ZdZ fdZdd	dZd Z xZS )
CocoaAlternateEventLoopaY  This is an alternate loop developed mainly for ARM64 variants of macOS.
    nextEventMatchingMask_untilDate_inMode_dequeue_ is very broken with ctypes calls. Events eventually stop
    working properly after X returns. This event loop differs in that it uses the built-in NSApplication event
    loop. We tie our schedule into it via timer.
    c                V    t                                                       d | _        d S r   )super__init__platform_event_loop)r9   	__class__s    r#   ri   z CocoaAlternateEventLoop.__init__r   s'    #'   r<   ?intervalfloat | Nonec                   |nB|s | j                             | j                   n | j                             | j        |           d| _        ddlm} d|_        t          j	        D ]*}|
                                 |                                 +t          j        | _        |                     d           d| _        | j                            |pd           d S )NFr   )Windowon_enterT)clockschedule_redraw_windowsschedule_intervalrD   pyglet.windowrp   _enable_event_queuer   windows	switch_todispatch_pending_eventsrj   dispatch_eventrC   nsapp_start)r9   rm   rp   windows       r#   runzCocoaAlternateEventLoop.runv   s     	IJ 45555J(()=xHHH((((((%*" k 	- 	-F**,,,,#&#: J''' ,,X];;;;;r<   c                    d| _         | j        | j                                         d| _        |                     d           | j        | j                                         dS 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`).
        TNFon_exit)rD   rj   notifyrC   r{   
nsapp_stopr@   s    r#   exitzCocoaAlternateEventLoop.exit   sp     #/$++---I&&&#/$//11111 0/r<   )rl   )rm   rn   )ra   rb   rc   __doc__ri   r~   r   __classcell__rk   s   @r#   rf   rf   l   sj         
( ( ( ( (< < < < <22 2 2 2 2 2 2r<   rf   c                  J     e Zd Z fdZd Zd Zd Zd Zd
dZd Z	d	 Z
 xZS )CocoaPlatformEventLoopc                &    t                                                       d  _        t                      5  t                                           _         j                                        r	 d d d            d S  j                                        st                        j        
                    t          j                   t                                          }t          j        d          }|                    |          s|                    d|           t          j        d          }|                    |          s|                    d|           t$                                                                          _         j                             j                   d _        d d d            n# 1 swxY w Y    fd}t1          j        t0          j        |           t1          j        t0          j        |           d S )NApplePersistenceIgnoreStateTApplePressAndHoldEnabledFc                     j         r j                                          d _         j        rj                            d            d S d S r   )_timer
invalidater0   
terminate_)argsr9   s    r#   term_receivedz6CocoaPlatformEventLoop.__init__.<locals>.term_received   sX    { #&&((("z ,
%%d+++++, ,r<   )rh   ri   r   r   r   r+   r0   	isRunningmainMenur1   setActivationPolicy_r   $NSApplicationActivationPolicyRegularr   standardUserDefaultsr   objectForKey_setBool_forKey_r5   r   r(   appdelegatesetDelegate_rI   signalSIGINTSIGTERM)r9   defaultsignoreStateholdEnabledr   rk   s   `    r#   ri   zCocoaPlatformEventLoop.__init__   s'    	- 	-&88::DJz##%% 	- 	- 	- 	- 	- 	- 	- 	- :&&(( J++G,XYYY &::<<H!-(EFFK))+66 <(({;;;!-(BCCK))+66 =((<<<+113388>>DJ##D$4555',D$1	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-4	, 	, 	, 	, 	, 	fm]333fnm44444s   9G>D9GG
Gc                   t                      5  | j                                        sA| j        s:| j                                         | j                            d           d| _        d d d            d S # 1 swxY w Y   d S r_   )r   r0   r   rI   finishLaunchingrS   r@   s    r#   startzCocoaPlatformEventLoop.start   s     	0 	0:'')) 0$2J 0 
**,,,
55d;;;+/(	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0   AA77A;>A;c                    ddl m} || _        | j        J t                              || j        t          d          dd          | _        | j        	                                 dS )%Used only for CocoaAlternateEventLoopr   )
event_loopNzupdatePyglet:FT)

pyglet.appr   _event_loopr   r   @scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_r   r   r0   r~   )r9   rm   r   s      r#   r|   z"CocoaPlatformEventLoop.nsapp_start   su    ))))))%{"""^^))
 
 	
r<   c                    | j                                          t                      5  |                                  ddd           dS # 1 swxY w Y   dS r   N)r   idler   dispatch_posted_eventsr@   s    r#   r?   z!CocoaPlatformEventLoop.nsapp_step   s     	* 	*'')))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   A

AAc                    | j                             d           | j        r"| j                                         d| _        dS dS r   )r0   stop_r   r   r@   s    r#   r   z!CocoaPlatformEventLoop.nsapp_stop   sK    
; 	K""$$$DKKK	 	r<   Nc                ~   t                      5  |                                  |t                                          }n#|dk    rd }nt                              |          }| j                                         | j                            t          j
        |t          j        d          }|Z|                                }|t          j        k    r| j                            |           | j                                         d}nd}| j                                         |cd d d            S # 1 swxY w Y   d S )N        TF)r   r   r   distantFuturedateWithTimeIntervalSinceNow__is_runningsetr0   /nextEventMatchingMask_untilDate_inMode_dequeue_r   NSAnyEventMaskNSDefaultRunLoopModetypeNSApplicationDefined
sendEvent_updateWindowsclear)r9   timeouttimeout_dateevent
event_typedid_time_outs         r#   stepzCocoaPlatformEventLoop.step   su    !	  !	 '')))   &3355C#%CCGLL
   """JNN&g6RTXZ ZE  "ZZ\\
!===J))%000
((***$#""$$$C!	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	 s   DD22D69D6c                    d S r   r[   r@   s    r#   stopzCocoaPlatformEventLoop.stop  s    r<   c                   t                      5  t                              t          j        t          j        dd          dddd ddd	  	        }| j                            |d           d d d            d S # 1 swxY w Y   d S )Nr   r   F)r   r   ]otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_r   r   NSPointr0   postEvent_atStart_)r9   notifyEvents     r#   r   zCocoaPlatformEventLoop.notify  s     	> 	>!,S))
 
K J))+u===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>r   r   )ra   rb   rc   ri   r   r|   r?   r   r   r   r   r   r   s   @r#   r   r      s        (5 (5 (5 (5 (5T0 0 0  "* * *  "  "  "  " H  > > > > > > >r<   r   ) 
__future__r   r   rQ   pygletr   pyglet.app.baser   r   pyglet.libs.darwinr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r$   r1   r3   r5   rf   r   r[   r<   r#   <module>r      s   " " " " " "         8 8 8 8 8 8 8 8                    "!/22		8	$	$W|,,
		8	$	$
'
I
&
&""#344
'
I
&
&(w()?@@ 
 
 
  ,0 0 0 0 0 0 0 0d y((22 22 22 22 22i 22 22 22hI> I> I> I> I>. I> I> I> I> I>r<   