
    Mh                     T   d Z ddlZddlZddlZddlmZ ddlZd Zed             Z	 G d dej
                  Z G d d	          Zed
             Zed             Zed             ZdZ	  eej        d                   Zn# e$ r Y nw xY wedk    reZdS ej        dk    reZdS eZdS )z;Enable wxPython to be used interactively in prompt_toolkit
    N)default_timerc                       fd}|S )aC  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                  <    	  | i | d S # t           $ r Y d S w xY wN)KeyboardInterrupt)argskwargsfuncs     a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/terminal/pt_inputhooks/wx.pywrapperz*ignore_keyboardinterrupts.<locals>.wrapper   sE    	D$!&!!!!!  	 	 	DD	s    
 )r
   r   s   ` r   ignore_keyboardinterruptsr      s#        
 N    c                 J   t          j                    }|t          j                    sJ t          j                    }t          j        |          }|                                r(|                                 |                                (|                                 ~dS )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.
    Nr   )wxGetAppThread_IsMain	EventLoopEventLoopActivatorPendingDispatchProcessIdle)contextappevtloopeas       r   inputhook_wx1r      s     )++C
!!!!!
 ,.."7++oo 	 oo 	1r   c                       e Zd Zd Zd ZdS )EventLoopTimerc                 R    || _         t          j                            |            d S r   )r
   r   Timer__init__)selfr
   s     r   r"   zEventLoopTimer.__init__4   s%    	
$r   c                 .    |                                   d S r   )r
   r#   s    r   NotifyzEventLoopTimer.Notify8   s    		r   N)__name__
__module____qualname__r"   r&   r   r   r   r   r   2   s2                 r   r   c                       e Zd Zd Zd ZdS )EventLoopRunnerc                     || _         t          j                    | _        t	          | j                  | _        | j                            |           | j                                         d S r   )	input_is_readyr   r   r   r   check_stdintimerStartRun)r#   timer-   s      r   r1   zEventLoopRunner.Run>   sY    ,|~~#D$455

r   c                     |                                  r4| j                                         | j                                         d S d S r   )r-   r/   Stopr   Exitr%   s    r   r.   zEventLoopRunner.check_stdinE   sL       	 JOOL	  	 r   N)r'   r(   r)   r1   r.   r   r   r   r+   r+   <   s2                   r   r+   c                     t          j                    }|?t          j                    sJ t                      }|                    d| j                   dS )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.
    N
   )r2   r-   r   )r   r   r   r+   r1   r-   )r   r   elrs      r   inputhook_wx2r9   K   s^     )++C
!!!!! 	R&5 	 	7 	7 	71r   c                 2   t          j                    }|t          j                    sJ t          t	          j        t          j                            s)t	          j        t          j        t          j                   t          j                    }t          j	        |          }t                      }|                                 s|                                r6t                      }|                                 |                                6|                                 t                      |z
  }|dk    rt          j        d           n/|dk    rt          j        d           nt          j        d           |                                 ~dS )a^  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.
    Ng      $@g      ?g?g?gMbP?r   )r   r   r   callablesignal	getsignalSIGINTdefault_int_handlerr   r   clockr-   r   r   r   r2   sleep)r   r   r   r   t	used_times         r   inputhook_wx3rD   e   sd    )++C
!!!!!
 (7788 	EM&-)CDDD,.."7++GG((** 	"//## #GG  """ //## # OO !I4
3S 
4     
5!!!3 ((** 	"4 1r   c                 ,    t          j                    dS                                  rdS t          j                    sJ d}t          j                     fd}                    |                               t           j        |           t          t          j
        t          j                            s)t          j	        t          j        t          j                                       d                                            dS )a|  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*                                                                  d S d S r   )r-   r4   ExitMainLoop)evr   r   r/   s    r   pollz!inputhook_wxphoenix.<locals>.poll   sF    !!## 	JJLLL	 	r   F)r   r   r-   IsMainThreadr!   r0   Bind	EVT_TIMERr;   r<   r=   r>   r?   SetExitOnFrameDeleteMainLoop)r   poll_intervalrJ   r   r/   s   `  @@r   inputhook_wxphoenixrQ      s    )++C
{ ? M HJJE      
 
KK	JJr|T"""
 F$V]3344 AfmV%?@@@ U###LLNNNNNr         darwin)__doc__sysr<   r2   timeitr   r@   r   r   r   r!   r   r+   r9   rD   rQ   major_versionint__version__	Exception	inputhookplatformr   r   r   <module>r^      s    


   ) ) ) ) ) ) 				      ,    RX                     2 0 0 0f - - -b 	Cq)**MM 	 	 	D	 A#III 	\XIIIIIIs   +B B
	B
