
    \
j"                        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d Zd Z G d d          Z ed          Z G d de          Z G d de          ZdS )    N)app)PlatformEventLoop	EventLoop)cocoapyAutoReleasePoolObjCSubclassPyObjectEncodingObjCInstance
send_super	ObjCClassget_selectorNSApplicationNSMenu
NSMenuItemNSDateNSEventNSUserDefaultsNSTimerc                 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        J/DATA/AppData/hermes/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_menur/      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
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.init7   s&    JtV4455'    vc                 8    | j                                          d S r   )r6   
nsapp_stepr7   s    r!   updatePyglet_z)_AppDelegate_Implementation.updatePyglet_=   s    $$&&&&&r:   zv@c                 6    d| j         _        d| j         _        d S )NFT)r6   
is_runninghas_exitr7   notifications     r!   applicationWillTerminate_z5_AppDelegate_Implementation.applicationWillTerminate_A   s    ',$%)"""r:   c                     d| j         _        d S NT)r6   _finished_launchingrC   s     r!   applicationDidFinishLaunching_z:_AppDelegate_Implementation.applicationDidFinishLaunching_F   s    04---r:   N)__name__
__module____qualname__r   r3   methodr	   r&   r?   rE   rI    r:   r!   r1   r1   4   s        <
N;;L 0011  21
 ' ' ' * * * 5 5 5 5 5r:   r1   r3   c                        e Zd ZdZddZd Zd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                 *   d| _         ddlm} d|_        t          j        D ]*}|                                 |                                 +t          j        | _        | 	                    d           d| _
        | j                            |           d S )NFr   )Windowon_enterT)rB   pyglet.windowrS   _enable_event_queuer   windows	switch_todispatch_pending_eventsplatform_event_loopdispatch_eventrA   nsapp_start)r7   intervalrS   windows       r!   runzCocoaAlternateEventLoop.runR   s    ((((((%*" k 	- 	-F**,,,,#&#: J''' ,,X66666r:   c                     d| _         | j                                         d| _        |                     d           | 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`).
        TFon_exitN)rB   rZ   notifyrA   r[   
nsapp_stopr>   s    r!   exitzCocoaAlternateEventLoop.exitc   sV      '')))I&&& ++-----r:   N)rQ   )rJ   rK   rL   __doc__r_   rd   rN   r:   r!   rP   rP   L   sA         
7 7 7 7". . . . .r:   rP   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          t          |                                            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|           d| _        d d d            d S # 1 swxY w Y   d S )NApplePersistenceIgnoreStateTApplePressAndHoldEnabledF)superrg   __init__r   r   r)   r.   	isRunningmainMenur/   setActivationPolicy_r   $NSApplicationActivationPolicyRegularr   standardUserDefaultsr   objectForKey_setBool_forKey_rH   )r7   defaultsignoreStateholdEnabled	__class__s       r!   rl   zCocoaPlatformEventLoop.__init__t   s   $d++44666 	- 	-&88::DJz##%% 	- 	- 	- 	- 	- 	- 	- 	- :&&(( J++G,XYYY &::<<H!-(EFFK))+66 <(({;;;!-(BCCK))+66 =((<<<',D$+	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   9E3=C)E33E7:E7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 rG   )r   r.   rm   rH   finishLaunchingactivateIgnoringOtherApps_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} | _         fd}t          j        t          j        |           t          j        t          j        |           t                                                                          _	         j
                             j	                   t                              | j	        t          d          dd           _         j
                                         dS )%Used only for CocoaAlternateEventLoopr   )
event_loopc                  ~    j         r j                                          d _                                          d S r   )timer
invalidaterc   )argsr7   s    r!   term_receivedz9CocoaPlatformEventLoop.nsapp_start.<locals>.term_received   s>    z "
%%'''!
OOr:   zupdatePyglet:FTN)
pyglet.appr   _event_loopsignalSIGINTSIGTERMr3   r   r&   appdelegater.   setDelegate_r   @scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_r   r   r_   )r7   r]   r   r   s   `   r!   r\   z"CocoaPlatformEventLoop.nsapp_start   s    ))))))%	 	 	 	 	 	fm]333fnm444'--//44T::
 0111]]/** 
 	
r:   c                 `    | j                                          |                                  dS r~   N)r   idledispatch_posted_eventsr>   s    r!   r=   z!CocoaPlatformEventLoop.nsapp_step   s/    ##%%%%%r:   c                 :    | j                             d           dS r   )r.   
terminate_r>   s    r!   rc   z!CocoaPlatformEventLoop.nsapp_stop   s    
d#####r:   Nc                    t                      5  |                                  |t                                          }n:|dk    rt                                          }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distantPastdateWithTimeIntervalSinceNow__is_runningsetr.   /nextEventMatchingMask_untilDate_inMode_dequeue_r   NSAnyEventMaskNSDefaultRunLoopModetypeNSApplicationDefined
sendEvent_updateWindowsclear)r7   timeouttimeout_dateevent
event_typedid_time_outs         r!   stepzCocoaPlatformEventLoop.step   s    !	  !	 '')))   &3355C%1133%CCGLL
   """JNN&g6RTXZ ZE  "ZZ\\
!===J))%000
((***$#""$$$C!	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	  !	 s   D-E		EEc                     d S r   rN   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   NSPointr.   postEvent_atStart_)r7   notifyEvents     r!   rb   zCocoaPlatformEventLoop.notify   s     	> 	>!,S))
 
K J))+u===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>r|   r   )rJ   rK   rL   rl   r{   r\   r=   rc   r   r   rb   __classcell__)rw   s   @r!   rg   rg   r   s        - - - - -20 0 0  :& & &
$ $ $"  "  "  " H  > > > > > > >r:   rg   )r   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   rP   rg   rN   r:   r!   <module>r      s          8 8 8 8 8 8 8 8                    "!/22		8	$	$W|,,
		8	$	$
'
I
&
&""#344
'
I
&
&
 
 
  ,5 5 5 5 5 5 5 5, y(($. $. $. $. $.i $. $. $.L> > > > >. > > > > >r:   