
    ChK                     V   S r SSKrSSKrSSKrSSKJr  SSKrSSKJr	  SSK
Jr  S rSSSSSSSS.rS rS	 r\" S
SS5      S 5       r\r\R$                  S 5       rS r\" S5      S 5       r\R$                  S 5       r\" S5      S 5       r\R$                  S 5       r\" S5      S 5       r\R$                  S 5       r\" S5      S 5       r\R$                  S 5       r\" S5      S 5       r\R$                  S 5       r\" S5      S  5       r\R$                  S! 5       r S" r!S# r"S%S$ jr#g)&z4Event loop integration for the ZeroMQ-based kernels.    N)partial)Version)Applicationc                      [         R                  S:H  =(       a-    [        [        R                  " 5       S   5      [        S5      :  $ )z`Should we use appnope for dealing with OS X app nap?

Checks if we are on OS X 10.9 or greater.
darwinr   z10.9)sysplatformVmac_ver     gC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\ipykernel/eventloops.py_use_appnoper      s4    
 <<8#M(*:*:*<Q*?(@AfI(MMr   )inlinenbaggwebaggnotebookipymplwidgetNc                     ^  U 4S jnU$ )a  Decorator to register an event loop to integrate with the IPython kernel

The decorator takes names to register the event loop as for the %gui magic.
You can provide alternative names for the same toolkit.

The decorated function should take a single argument, the IPython kernel
instance, arrange for the event loop to call ``kernel.do_one_iteration()``
at least every ``kernel._poll_interval`` seconds, and start the event loop.

:mod:`ipykernel.eventloops` provides and registers such functions
for a few common event loops.
c                 X   >^  T H  nT [         U'   M     S T l        U 4S jnUT l        T $ )z#Integration registration decorator.c                     g Nr   kernels    r   <lambda>9register_integration.<locals>.decorator.<locals>.<lambda>7   s    r   c                    > U Tl         U $ )zK@func.exit is now a decorator

to register a function to be called on exit
)	exit_hook)	exit_funcfuncs    r   exit_decorator?register_integration.<locals>.decorator.<locals>.exit_decorator9   s    
 'DNr   )loop_mapr   exit)r!   namer"   toolkitnamess   `  r   	decorator'register_integration.<locals>.decorator2   s2     D!HTN ! -	 #	r   r   )r'   r(   s   ` r   register_integrationr*   $   s    $ r   c                 j  ^ ^^^^ SS K mSSKJn  SSKJm   SSKJm  U 4S jmUU 4S jn[        T S5      (       d  T R                  R                  [        R                  5      nTR                  UT" S	5      R                  T R                  R                  5      T l        T R                   R"                  R%                  U5        OT R                   R'                  S
5        UUUU 4S jnU[(        l        TR,                  R/                  SU5        g ! [         a    U" S 5      UU4S j5       m GNf = f)Nr   )	lru_cacheQtCore)enum_helperc                    > TR                  U R                  S5      S   5      " [        R                  TR                     5      $ )N.r   )
attrgetter
rpartitionr   modules__package__)r&   r.   operators    r   r/   &_notify_stream_qt.<locals>.enum_helperQ   s6    &&ts';A'>?FL^L^@_``r   c                     > T R                   R                  S5        T R                  R                  R	                  5         g)fall back to main loopFN)_qt_notifier
setEnabledappqt_event_loopquitr   s   r   	exit_loop$_notify_stream_qt.<locals>.exit_loopU   s-    &&u-

  %%'r   c                  R   > TR                   R                  SS9(       a  T " 5         ggz2fall back to main loop when there's a socket event   limitNshell_streamflush)r?   r   s   r   process_stream_events0_notify_stream_qt.<locals>.process_stream_eventsZ   s&     $$1$-K .r   r:   zQtCore.QSocketNotifier.TypeTc                   > [        TS5      (       d  TR                  TR                  5      Tl        TR                  R	                  S5        TR                  R                  T" S5      R                  5        TR                  R                  R                  T5        TR                  R                  [        SU -  5      5        g)2schedule fall back to main loop in [delay] seconds	_qt_timerTzQtCore.Qt.TimerType  N)hasattrQTimerr<   rM   setSingleShotsetTimerTypePreciseTimertimeoutconnectstartint)delayr.   r/   r?   r   s    r   _schedule_exit)_notify_stream_qt.<locals>._schedule_exitn   s     v{++%}}VZZ8F**40))+6K*L*Y*YZ$$,,Y7s4%<01r   )r6   	functoolsr,   IPython.external.qt_for_kernelr.   r/   ImportErrorrO   rG   
getsockoptzmqFDQSocketNotifierReadr<   r=   r:   	activatedrU   r;   loop_qtrY   rP   
singleShot)	r   r,   rI   fdrY   r.   r/   r?   r6   s	   `    @@@@r   _notify_stream_qtrg   G   s    #5a>(
 6>**  ++CFF3$449:??AYAY
 	%%--.CD&&t,2 2 ,G MMQ 56k  a	4	a 
	aas   D D21D2qtqt5qt6c                     [        U 5        SU R                  l        U R                  R                  n[	        US5      (       a  UR                  5       OUR                  5         SU R                  l        g)z,Event loop for all supported versions of Qt.TexecFN)rg   r<   _in_event_loopr=   rO   rl   exec_)r   els     r   rd   rd      sU     f !%FJJ 
	!	!BV$$BGGI"((* %FJJr   c                 8    U R                   R                  5         g r   )r<   r%   r   s    r   loop_qt_exitrq      s    
JJOOr   c                 @    SU l         U R                  5         SU l         g)zInner-loop for running the Wx eventloop

Pulled from guisupport.start_event_loop in IPython < 5.2,
since IPython 5.2 only checks `get_ipython().active_eventloop` is defined,
rather than if the eventloop is actually running.
TFN)rm   MainLoopr<   s    r   _loop_wxru      s     CLLNCr   wxc                 
  ^ ^^^^ SSK m[        ST R                  -  5      mU 4S jm " UU4S jSTR                  5      m " UU4S jSTR                  5      n[        T S	S5      (       a%  [        T R                  TR                  5      (       d  U" S
S9T l        SSKn[        UR                  UR                  5      5      (       d&  UR                  UR                  UR                  5        [        T R                  5        g)z*Start a kernel with wx event loop support.r   NrN   c                  x   > T R                   R                  SS9(       a  T R                  R                  5         gg)zwake from wxrC   rD   N)rG   rH   r<   ExitMainLoopr   s   r   wakeloop_wx.<locals>.wake   s2    $$1$-JJ##% .r   c                   *   > \ rS rSrU U4S jrS rSrg)loop_wx.<locals>.TimerFrame   c                    > TR                   R                  U S S5        TR                  U 5      U l        U R                  R	                  T5        U R                  TR                  U R                  5        Xl        g )N)	Frame__init__TimertimerStartBind	EVT_TIMERon_timerr!   )selfr!   poll_intervalrv   s     r   r   $loop_wx.<locals>.TimerFrame.__init__   sU    HHdD"-$DJJJ]+IIbllDMM2Ir   c                 $    U R                  5         g r   )r!   )r   events     r   r   $loop_wx.<locals>.TimerFrame.on_timer   s    IIKr   )r!   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__)r   rv   s   r   
TimerFramer}      s    		r   r   c                   $   > \ rS rSrU U4S jrSrg)loop_wx.<locals>.IPWxApp   c                 V   > T" T5      U l         U R                   R                  S5        g)NFT)frameShow)r   r   rz   s    r   OnInitloop_wx.<locals>.IPWxApp.OnInit   s"    #D)DJJJOOE"r   )r   N)r   r   r   r   r   r   )r   rz   s   r   IPWxAppr      s    	 	r   r   r<   F)redirect)rv   rW   _poll_intervalr   Appgetattr
isinstancer<   signalcallable	getsignalSIGINTdefault_int_handlerru   )r   r   r   r   r   rz   rv   s   `  @@@@r   loop_wxr      s      v4445M
 
RXX 
 "&&  FE4((Z

BFF-K-Ke,

 F$$V]]344fmmV%?%?@VZZr   c                 ,    SSK nUR                  5         g)zExit the wx loop.r   N)rv   Exit)r   rv   s     r   loop_wx_exitr      s     GGIr   tkc                 n  ^ ^	^
^^ SSK JnJn  U" 5       m	[        T	S5      (       a   " S S5      nU	U 4S jmUU 4S jnU	U4S jnU[        l        U" T	5      T l        T	R                  R                  T R                  R                  [        R                  5      X5        T	R                  SU5        T	R                  5         g	SS	Km
SS	KnUR#                  5         T R$                  n['        S
T R(                  -  5      m " U
U U4S jS5      nU" T	U5      T l        T R                  R+                  5         g	)z&Start a kernel with the Tk event loop.r   )READABLETkcreatefilehandlerc                       \ rS rSrS rSrg) loop_tk.<locals>.BasicAppWrapper   c                 D    Xl         U R                   R                  5         g r   )r<   withdraw)r   r<   s     r   r   )loop_tk.<locals>.BasicAppWrapper.__init__   s    !!#r   rt   N)r   r   r   r   r   r   r   r   r   BasicAppWrapperr      s    $r   r   c                     > T R                   R                  TR                  R                  [        R
                  5      5        T R                  5         T R                  5         T?g)r9   N)	r   deletefilehandlerrG   r^   r_   r`   r>   destroyapp_wrapper)r<   r   s   r   r?   loop_tk.<locals>.exit_loop   sB    FF$$V%8%8%C%CCFF%KLHHJKKM"r   c                  R   > TR                   R                  SS9(       a  T" 5         ggrB   rF   )akwr?   r   s     r   rI   &loop_tk.<locals>.process_stream_events   s$    ""((q(1 2r   c                 B   > TR                  [        SU -  5      T5        g)rL   rN   N)afterrW   )rX   r<   r?   s    r   rY   loop_tk.<locals>._schedule_exit  s    IIc$,'3r   NrN   c                   2   > \ rS rSrS rU UU4S jrS rSrg) loop_tk.<locals>.TimedAppWrapperi"  c                 P    Xl         U R                   R                  5         X l        g r   )r<   r   r!   )r   r<   r!   s      r   r   )loop_tk.<locals>.TimedAppWrapper.__init__#  s    !!# 	r   c                   > TR                  5       n UR                  U R                  5       5        U R                  R                  TU R                  5        g ! [         a    TR                  R                  S5         NNf = f)NzError in message handler)	get_event_looprun_until_completer!   	Exceptionlog	exceptionr<   r   r   )r   loopasyncior   r   s     r   r   )loop_tk.<locals>.TimedAppWrapper.on_timer(  si    --/E++DIIK8 }dmm< ! EJJ(()CDEs   A %B Bc                 X    U R                  5         U R                  R                  5         g r   )r   r<   mainloop)r   s    r   rV   &loop_tk.<locals>.TimedAppWrapper.start0  s    !!#r   )r<   r!   N)r   r   r   r   r   r   rV   r   )r   r   r   s   r   TimedAppWrapperr   "  s    !
=$r   r   )tkinterr   r   rO   loop_tkrY   r   r   r   rG   r^   r_   r`   r   r   r   nest_asyncioapplydo_one_iterationrW   r   rV   )r   r   r   r   rI   rY   r   doir   r<   r   r?   r   s   `        @@@@r   r   r      s     %
$C s'((	$ 	$
	#		4 "0 -S1  **3662H	
 			!*+ 	%%D6#8#889	$ 	$$ -S#6  "r   c                 ~     U R                   R                  R                  5         U ? g! [        [        4 a     gf = f)zExit the tk loop.N)r   r<   r   RuntimeErrorAttributeErrorr   s    r   loop_tk_exitr   8  s<    &&(.) s   &) <<gtkc                 L    SSK Jn  U" U 5      nUR                  5         X l        gz6Start the kernel, coordinating with the GTK event looprC   )GTKEmbedN)gui.gtkembedr   rV   _gtkr   r   
gtk_kernels      r   loop_gtkr   B  s"     '&!JKr   c                 8    U R                   R                  5         g)zExit the gtk loop.Nr   stopr   s    r   loop_gtk_exitr   L       KKr   gtk3c                 L    SSK Jn  U" U 5      nUR                  5         X l        gr   )gui.gtk3embedr   rV   r   r   s      r   	loop_gtk3r   R  s"     (&!JKr   c                 8    U R                   R                  5         g)zExit the gtk3 loop.Nr   r   s    r   loop_gtk3_exitr   \  r   r   osxc                   ^^ SSK JnJm  [        R                  mUU4S jnU R
                  R                  (       dt    U[        l        U" U R                  5        U R                  R                  SS9(       a   T[        l        g T[        l        U R
                  R                  (       d  Ms  gg! [         a    e f = f! [         a    [        S[        R                  S9   N]f = f! T[        l        f = f)zfStart the kernel, coordinating with the Cocoa CFRunLoop event loop
via the matplotlib MacOSX backend.
rC   )r   r   c                 j   > T" 5         U [         L a  [        S[        R                  S9  gT" XU5        g)z.don't let KeyboardInterrupts look like crashesz%KeyboardInterrupt caught in CFRunLoopfileN)KeyboardInterruptprintr   
__stdout__)etypevaluetbreal_excepthookr   s      r   
handle_intloop_cocoa.<locals>.handle_intk  s,     	%%9OE"-r   rD   Nz"KeyboardInterrupt caught in kernelr   )_eventloop_macosr   r   r   
excepthookshellexit_nowr   rG   rH   BaseExceptionr   r   r   )r   r   r   r   r   s      @@r   
loop_cocoar  b  s    
 1nnO. ll##	-!+../&&,,1,5 -CN 6 -CN% ll### !   	M6S^^L	M
 -CNs5   ;B2 C) 2B>>C "C&#C) %C&&C) )C6c                     SSK Jn  U" 5         g)zExit the cocoa loop.rC   )r   N)r  r   )r   r   s     r   loop_cocoa_exitr    s     'Fr   r   c                 \  ^ SSK nUR                  5       mTR                  5       (       a  gTR                  5       (       a!  UR	                  5       mUR                  T5        STl        U4S jn[        X R                  5      nTR                  U R                  R                  [        R                  5      U5        TR                  U5         Sn TR                  5         TR                  (       a  TR#                  5         Ub  Ueg! [         a     MH  [          a  nUn SnANDSnAff = f)z/Start a kernel with asyncio event loop support.r   NFc                 P   > U R                  SS9(       a  TR                  5         ggrB   )rH   r   )streamr   s    r   rI   +loop_asyncio.<locals>.process_stream_events  s    <<a< IIK !r   )r   r   
is_running	is_closednew_event_loopset_event_loop_should_closer   rG   
add_readerr^   r_   r`   	call_soonrun_foreverr   r   close)r   r   rI   notifiererrorer   s         @r   loop_asyncior    s     !!#D~~%%'t$D
 ,.A.ABHOOF''22366:HENN8
	
 JJLK ! 	 	E	s   D	 	
D+	D+D&&D+c                    ^ SSK nUR                  5       mU4S jnTR                  5       (       a  U" 5         gTR                  5       (       d"  TR	                  U5        TR                  5         gg)zExit hook for asyncior   Nc                    >#    [        T S5      (       a  T R                  5       7v   ST l        T R                  5         g 7f)Nshutdown_asyncgensT)rO   r  r  r   )r   s   r   
close_loop%loop_asyncio_exit.<locals>.close_loop  s4     4-..))++!		s   =A )r   r   r  r  r   r  )r   r   r  r   s      @r   loop_asyncio_exitr    sX     !!#D ^^
+

 r   c                    [         R                  R                  SS5      nSSKJnJnJnJnJn  U" 5       nUSUSUSUS0nUb   U S:w  a  X   U :w  a  [        SX    S	35        gUb"  U S:w  a  X   U :w  a  [        S
U  SU S35        gOzU S:X  a   SSK
n	S[         R                  S'   O[U S:X  a   SSKnS[         R                  S'   O<U S:X  a&  S[         R                  ;   a  [         R                  S	 O[        SU  S35        g g! [         a?     SSKn
S[         R                  S'    N&! [         a    S[         R                  S'     NFf = ff = f! [         a?     SSKnS[         R                  S'    Nr! [         a    S[         R                  S'     Nf = ff = f! [         a=  nS[         R                  ;   a  [         R                  S	 [        SU 35         SnAgSnAff = f)a  
Sets the QT_API environment variable by trying to import PyQtx or PySidex.

The user can generically request `qt` or a specific Qt version, e.g. `qt6`.
For a generic Qt request, we let the mechanism in IPython choose the best
available version by leaving the `QT_API` environment variable blank.

For specific versions, we check to see whether the PyQt or PySide
implementations are present and set `QT_API` accordingly to indicate to
IPython which version we want. If neither implementation is present, we
leave the environment variable set so IPython will generate a helpful error
message.

Notes
-----
- If the environment variable is already set, it will be used unchanged,
  regardless of what the user requested.
QT_APINr   )QT_API_PYQT5QT_API_PYQT6QT_API_PYSIDE2QT_API_PYSIDE6
loaded_apiri   rj   rh   z9Cannot switch Qt versions for this session; you must use r1   zRequest for "zC" will be ignored because `QT_API` environment variable is set to ""pyqt5pyside2pyqt6pyside6zUnrecognized Qt version: z". Should be "qt5", "qt6", or "qt".z$QT_API couldn't be set due to error )osenvirongetIPython.external.qt_loadersr"  r#  r$  r%  r&  r   PyQt5r]   PySide2PyQt6PySide6r   )guiqt_apir"  r#  r$  r%  r&  loaded
qt_env2guir0  r1  r2  r3  r  s                 r   set_qt_api_env_from_guir8    s   & ZZ^^Hd+F  \F 	ee	J cTkj.@C.GI*J\I]]^_`cTk$u %339(!=  % %<
3'.

8$ E\
3'.

8$ D[2::%JJx(-cU2TUV;  33"+4BJJx(" 3+2BJJx(33  33"+4BJJx(" 3+2BJJx(33$  rzz!

8$8<=sf   D .E 
ED((E	EE		E
FE44FFFF
G#&3GG#c                     [        US5      (       a  g[        U 5        SSKJn  SSKJn  U" S/5      Ul        UR                  UR                  5      UR                  l        g)z?Sets the `QT_API` environment variable if it isn't already set.r<   Nr   r-   )get_app_qt4 )	rO   r8  r\   r.   IPython.lib.guisupportr:  r<   
QEventLoopr=   )r4  r   r.   r:  s       r   make_qt_app_for_kernelr>  +  sM    vu 	C  62cU#FJ%00<FJJr   c                 t   U [         ;  a&  SU < S[         R                  5        3n[        U5      eUcJ  [        R                  " 5       (       a   [        [        R                  " 5       SS5      nUc  Sn[        U5      eU cX  [        US5      (       a  [        US5        [        US5      (       a  [        US5        [        US5      (       a  [        US5        O!U R                  S	5      (       a  [        X5        [         U    nU(       a)  UR                  b  UR                  ULa  S
n[        U5      eXAl        g)z#Enable integration with a given GUIzInvalid GUI request z, valid ones are:Nr   z\You didn't specify a kernel, and no IPython Application with a kernel appears to be running.r<   r:   rM   rh   z'Cannot activate multiple GUI eventloops)r$   keys
ValueErrorr   initializedr   instancer   rO   delattr
startswithr>  	eventloop)r4  r   r  msgr   s        r   
enable_guirH  <  s   
("3'):8==?:KLm~""$$[113XtDF>S  s##
{65!!FE"6>**FN+6;''FK(>>$"3/C=D!!-&2B2B$2N73r   r   )$__doc__r,  r	   r   r[   r   r_   packaging.versionr   r
   traitlets.config.applicationr   r   r$   r*   rg   rd   loop_qt5r%   rq   ru   r   r   r   r   r   r   r   r   r  r  r  r  r8  r>  rH  r   r   r   <module>rM     s   :
 
  
  
 * 4N 
 F=7@ dE5)
& *
&  	 	 d1 1h 	  dL# L#^ 	  e  
 
 f   
 e#- #-L   i % !%P  (Yx="!r   