
    +Vf                        d Z ddlZddlZddlmZ ej
                  j                  ej                  j                  d            Z	ej                  Zee	j                  _        ee	j                  _        ee	j                  _        eege	j                  _        e	j                  Zd Zd Zd Zej
                  j                  ej                  j                  d            Zej,                  Zej.                  e_        ej0                  Zee_        ej2                  Zee_        ej4                  Zde_        ege_        ej6                  Zee_        eej.                  ej.                  ej8                  ej8                  eege_        ej:                  Zde_        eeege_        ej=                  ed	      Zd
 Z d Z! e       Z"ddZ# ejH                  dee      Z% e%e#      Z&d Z'ddZ(y)zGEventloop hook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 H    t        | t              s| j                  d      } | S )zensure utf8 bytesutf8)
isinstancebytesencode)ss    c/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/ipykernel/_eventloop_macos.py_utf8r      s    aHHVH    c                 >    t         j                  t        |             S )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr       s      t--r   c                 >    t         j                  t        |             S )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   %   s    eI.//r   CoreFoundationkCFRunLoopCommonModesc                  >    t        t        d      t        d            S )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplication)msgr   r    r   r   _NSAppr   Q   s    q!1%8#9::r   c                     t        t        d      t        d      ddddddddd      }t        | t        d      t        |      d       y)zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:T)r   r   r   void_p)NSAppevents     r   _waker$   V   sX    	)	B	
 								E  q%&ut<r   c                     t         j                          t               }t        |t	        d            r"t        |t	        d      |       t        |       yt        t                      y)z.Callback to fire when there's input to be read	isRunningzstop:N)
_triggeredsetr   r   r   r$   CFRunLoopStopCFRunLoopGetCurrent)timerloopr"   s      r   stopr-   n   sF    NNHE 5!K.!E1W:u%e)+,r   c           	      v    t        dt               | z   dddt        d      }t        t	               |t
               y)z1Register callback to stop eventloop after a delayNr   )CFRunLoopTimerCreateCFAbsoluteTimeGetCurrent_c_stop_callbackCFRunLoopAddTimerCFRunLoopGetMainr   )delayr+   s     r   _stop_afterr5      s?      "U*			E r   c                     t         j                          t               }t        |        t	        |t        d             t         j                         st        j                          yy)z<run the Cocoa eventloop for the specified duration (seconds)runN)	r'   clearr   r5   r   r   is_setr   CFRunLoopRun)durationr"   s     r   mainloopr<      sL     HEqx
 	##% r   )NN)   ))__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr!   r   restyper   objc_msgSendargtypesr   r   r   r   r   r0   c_doubler*   r3   r)   r/   c_intr2   in_dllr   r   r$   r'   r-   	CFUNCTYPE_c_callback_func_typer1   r5   r<   r   r   r   <module>rO      s     {{v{{77?@	#    &   "   $f-   
.
0 ((
KK-. *BB #)??   $88 $  !22 !  ,,   %:: %  

OO
OO
LL
LL

!   #44    $ff5  n6MN ;
=* W

- )((vv> (. $&r   