
    ^h                     >   S r SSKrSSKrSSKrSSKJr  SSKrS r\S 5       r	 " S S\R                  5      r " S S	\5      r\S
 5       r\S 5       r\S 5       rSr \" \R&                  S   5      r\S:  a  \rg\R,                  S:X  a  \rg\rg! \ a     N'f = f)z;Enable wxPython to be used interactively in prompt_toolkit
    N)default_timerc                    ^  U 4S jnU$ )a/  Decorator which causes KeyboardInterrupt exceptions to be ignored during
execution of the decorated function.

This is used by the inputhook functions to handle the event where the user
presses CTRL+C while IPython is idle, and the inputhook loop is running. In
this case, we want to ignore interrupts.
c                  8   >  T" U 0 UD6  g ! [          a     g f = fN)KeyboardInterrupt)argskwargsfuncs     [/home/james-whalen/.local/lib/python3.13/site-packages/IPython/terminal/pt_inputhooks/wx.pywrapper*ignore_keyboardinterrupts.<locals>.wrapper   s'    	$!&!  		s    
 )r
   r   s   ` r   ignore_keyboardinterruptsr      s    
 N    c                 \   [         R                  " 5       nUb  [         R                  " 5       (       d   e[         R                  " 5       n[         R                  " U5      nUR                  5       (       a'  UR                  5         UR                  5       (       a  M'  UR                  5         Ag)zRun the wx event loop by processing pending events only.

This approach seems to work, but its performance is not great as it
relies on having PyOS_InputHook called regularly.
r   )wxGetAppThread_IsMain	EventLoopEventLoopActivatorPendingDispatchProcessIdle)contextappevtloopeas       r   inputhook_wx1r      s~     ))+C
!!!!
 ,,.""7+oo oor   c                        \ rS rSrS rS rSrg)EventLoopTimer2   c                 N    Xl         [        R                  R                  U 5        g r   )r
   r   Timer__init__)selfr
   s     r   r$   EventLoopTimer.__init__4   s    	
$r   c                 $    U R                  5         g r   r
   r%   s    r   NotifyEventLoopTimer.Notify8   s    		r   r(   N)__name__
__module____qualname____firstlineno__r$   r*   __static_attributes__r   r   r   r    r    2   s     r   r    c                        \ rS rSrS rS rSrg)EventLoopRunner<   c                     X l         [        R                  " 5       U l        [	        U R
                  5      U l        U R                  R                  U5        U R                  R                  5         g r   )	input_is_readyr   r   r   r    check_stdintimerStartRun)r%   timer5   s      r   r9   EventLoopRunner.Run>   sI    ,||~#D$4$45


r   c                     U R                  5       (       a5  U R                  R                  5         U R                  R	                  5         g g r   )r5   r7   Stopr   Exitr)   s    r   r6   EventLoopRunner.check_stdinE   s4      JJOOLL !r   )r   r5   r7   N)r,   r-   r.   r/   r9   r6   r0   r   r   r   r2   r2   <   s     r   r2   c                     [         R                  " 5       nUb@  [         R                  " 5       (       d   e[        5       nUR	                  SU R
                  S9  g)a`  Run the wx event loop, polling for stdin.

This version runs the wx eventloop for an undetermined amount of time,
during which it periodically checks to see if anything is ready on
stdin.  If anything is ready on stdin, the event loop exits.

The argument to elr.Run controls how often the event loop looks at stdin.
This determines the responsiveness at the keyboard.  A setting of 1000
enables a user to type at most 1 char per second.  I have found that a
setting of 10 gives good keyboard response.  We can shorten it further,
but eventually performance would suffer from calling select/kbhit too
often.

   )r:   r5   r   )r   r   r   r2   r9   r5   )r   r   elrs      r   inputhook_wx2rC   K   sR     ))+C
!!!! 	R&55 	 	7r   c                 b   [         R                  " 5       nUGb  [         R                  " 5       (       d   e[        [        R
                  " [        R                  5      5      (       d3  [        R                  " [        R                  [        R                  5        [         R                  " 5       n[         R                  " U5      n[        5       nU R                  5       (       d  UR                  5       (       a1  [        5       nUR                  5         UR                  5       (       a  M1  UR                  5         [        5       U-
  nUS:  a  [        R                   " S5        O3US:  a  [        R                   " S5        O[        R                   " S5        U R                  5       (       d  M  Ag)aJ  Run the wx event loop by processing pending events only.

This is like inputhook_wx1, but it keeps processing pending events
until stdin is ready.  After processing all pending events, a call to
time.sleep is inserted.  This is needed, otherwise, CPU usage is at 100%.
This sleep time should be tuned though for best performance.
g      $@g      ?g?g?gMbP?r   )r   r   r   callablesignal	getsignalSIGINTdefault_int_handlerr   r   clockr5   r   r   r   r:   sleep)r   r   r   r   t	used_times         r   inputhook_wx3rN   e   s%    ))+C
!!!!
 ((788MM&--)C)CD,,.""7+G((**//##G  " //## OO !I4

3S 

4  

5!3 ((**4 r   c                 L  ^ ^^ [         R                  " 5       mTc  gT R                  5       (       a  g[         R                  " 5       (       d   eSn[         R                  " 5       mUU U4S jnTR                  U5        TR                  [         R                  U5        [        [        R                  " [        R                  5      5      (       d3  [        R                  " [        R                  [        R                  5        TR                  S5        TR                  5         g)ad  Run the wx event loop until the user provides more input.

This input hook is suitable for use with wxPython >= 4 (a.k.a. Phoenix).

It uses the same approach to that used in
ipykernel.eventloops.loop_wx. The wx.MainLoop is executed, and a wx.Timer
is used to periodically poll the context for input. As soon as input is
ready, the wx.MainLoop is stopped.
Nd   c                 r   > TR                  5       (       a!  TR                  5         TR                  5         g g r   )r5   r=   ExitMainLoop)evr   r   r7   s    r   poll!inputhook_wxphoenix.<locals>.poll   s,    !!##JJL $r   F)r   r   r5   IsMainThreadr#   r8   Bind	EVT_TIMERrE   rF   rG   rH   rI   SetExitOnFrameDeleteMainLoop)r   poll_intervalrT   r   r7   s   `  @@r   inputhook_wxphoenixr\      s     ))+C
{?? M HHJE
 
KK	JJr||T"
 F$$V]]344fmmV%?%?@ U#LLNr         darwin)__doc__sysrF   r:   timeitr   rJ   r   r   r   r#   r    objectr2   rC   rN   r\   major_versionint__version__	Exception	inputhookplatformr   r   r   <module>rj      s       ) 	   ,RXX  f    2 0 0f - -b 	q)*M
 A#I 	\\XII  		s   B BB