
    Mh                        d Z ddlZddlZddlmZ ej                            ej                            d                    Z	ej
        Zee	j        _        ee	j        _        ee	j        _        e	j        Zd Zd Zd Zej                            ej                            d                    Zej        Zej        e_        ej        Zee_        ej        Zee_        ej        Zde_        ege_        ej        Zee_        eej        ej        ej        ej        eege_        ej        Zde_        eeege_        e                    ed	          Zd
 Z d Z! e            Z"ddZ# ej$        dee          Z% e%e#          Z&d Z'ddZ(dS )zGEventloop hook for OS X

Calls NSApp / CoreFoundation APIs via ctypes.
    N)Eventobjcc                 Z    t          | t                    s|                     d          } | S )zensure utf8 bytesutf8)
isinstancebytesencode)ss    Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipykernel/_eventloop_macos.py_utf8r      s*    a HHVH    c                 P    t                               t          |                     S )z)create a selector name (for ObjC methods))r   sel_registerNamer   )names    r   nr      s      t---r   c                 P    t                               t          |                     S )zget an ObjC Class by name)r   objc_getClassr   )	classnames    r   Cr   $   s    eI..///r   CoreFoundationkCFRunLoopCommonModesc                      t           t           gt          j        _        t	          t          d          t          d                    S )z0Return the global NSApplication instance (NSApp)NSApplicationsharedApplicationvoid_pr   objc_msgSendargtypesmsgr   r    r   r   _NSAppr!   P   s3    "(&!1Dq!!1%8#9#9:::r   c                    t           t           t           t           t           t           t           t           t           t           t           gt          j        _        t	          t          d          t          d          ddddddddd          }t           t           t           t           gt          j        _        t	          | t          d          t          |          d           dS )zWake the ApplicationNSEventz]otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:   r   NzpostEvent:atStart:Tr   )NSAppevents     r   _waker'   V   s     	"D 	)	B	
 	
 								 E  #)&&&!ADq%&&ut<<<<<r   c                    t                                            t                      }t          t          gt          j        _        t          |t          d                    rRt          t          t          gt          j        _        t          |t          d          |           t          |           dS t          t                                 dS )z.Callback to fire when there's input to be read	isRunningzstop:N)
_triggeredsetr!   r   r   r   r   r   r   r'   CFRunLoopStopCFRunLoopGetCurrent)timerloopr%   s      r   stopr0   |   s    NNHHE #)&!1D
5!K..!! -&,ff%="E1W::u%%%e)++,,,,,r   c           	          t          dt                      | z   dddt          d          }t          t	                      |t
                     dS )z1Register callback to stop eventloop after a delayNr   )CFRunLoopTimerCreateCFAbsoluteTimeGetCurrent_c_stop_callbackCFRunLoopAddTimerCFRunLoopGetMainr   )delayr.   s     r   _stop_afterr8      s^      ""U*			 E     r      c                 N   t                                            t                      }t          |            t          t          gt
          j        _        t          |t          d                     t           
                                st                                           dS dS )z<run the Cocoa eventloop for the specified duration (seconds)runN)r*   clearr!   r8   r   r   r   r   r   r   is_setr   CFRunLoopRun)durationr%   s     r   mainloopr@      s     HHE"(&!1Dqxx &
 	##%%%%%& &r   )NN)r9   ))__doc__ctypesctypes.util	threadingr   cdllLoadLibraryutilfind_libraryr   c_void_pr   r   restyper   r   r   r   r   r   r   r3   c_doubler-   r6   r,   r   r2   c_intr5   in_dllr   r!   r'   r*   r0   	CFUNCTYPE_c_callback_func_typer4   r8   r@   r    r   r   <module>rP      sE              {v{77??@@	#   &  "  
  . . .
0 0 0 ((
K-..  *B #)?   $8 $  !2 !  ,   %: %  

O
O
L
L

!   #4    $ff5  n6MNN ; ; ; =  =  =F UWW
- - - - )(vv>> ((..   $& & & & & &r   