
    
8dQ                         d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZmZmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  G d de          Z G d dee          ZdS )z"Frontend widget for the Qt Console    )
namedtupleN)QtCoreQtGui	QtWidgets)import_item)BaseFrontendMixin)AnyBoolInstanceUnicodeDottedObjectNamedefault   )BracketMatcher)CallTipWidget)HistoryConsoleWidget)PygmentsHighlighterc                   N     e Zd ZdZd	 fd	Zd Zd Z fdZ fdZ fdZ	 xZ
S )
FrontendHighlighterzA A PygmentsHighlighter that understands and ignores prompts.
    Nc                 r   t                                          |j                                        |           d| _        || _        d| _        t          j        dt          j	        |j
                  z            | _        t          j        dt          j	        |j
                  z            | _        d S )Nlexerr   Fz!^(%s)?([ \t]*>>> |^[ \t]*\.\.\. )z0^(%s)?([ \t]*In \[\d+\]: |[ \t]*\ \ \ \.\.\.+: ))super__init___controldocument_current_offset	_frontendhighlighting_onrecompileescapeother_output_prefix_classic_prompt_re_ipy_prompt_re)selffrontendr   	__class__s      9lib/python3.11/site-packages/qtconsole/frontend_widget.pyr   zFrontendHighlighter.__init__   s    *3355UCCC !$"$*029X=Y3Z3ZZ#
 #
 !j?")HLhBiBii
 
    c                     |r|                                 r|S | j                            |          }|r*|t          |                    d                    d         S |S )z,Handle inputs that start with '>>> ' syntax.r   N)isspacer$   matchlengroupr&   linems      r)   transform_classic_promptz,FrontendHighlighter.transform_classic_prompt&   sd      	t||~~ 	K#))$// 	AGGAJJ(())Kr*   c                     |r|                                 r|S | j                            |          }|r*|t          |                    d                    d         S |S )z7Handle inputs that start classic IPython prompt syntax.r   N)r,   r%   r-   r.   r/   r0   s      r)   transform_ipy_promptz(FrontendHighlighter.transform_ipy_prompt1   sd      	t||~~ 	K%%d++ 	AGGAJJ(())Kr*   c                 ~   t          | d          r| j        sdS |                                 }|                                }|                    dd          }|                     |          }t          |          t          |          z
  }|dk    r*|| _        t                      	                    |           dS dS )zL Highlight a block of text. Reimplemented to highlight selectively.
        r   N     r   )
hasattrr   currentBlocktextreplacer5   r.   r   r   highlightBlock)r&   stringcurrent_blockwithout_promptdiffr(   s        r)   r=   z"FrontendHighlighter.highlightBlock<   s     t.// 	t7K 	F
 ))++##%% ,, 226::6{{S000!88#'D GG"">22222 8r*   c                 t    | j         }d| _         t                                          |           || _         dS )zG Reimplemented to temporarily enable highlighting if disabled.
        TN)r   r   rehighlightBlock)r&   blockoldr(   s      r)   rC   z$FrontendHighlighter.rehighlightBlockT   s;     "#  '''"r*   c                 b    || j         z  }t                                          |||           dS )z1 Reimplemented to highlight selectively.
        N)r   r   	setFormat)r&   startcountformatr(   s       r)   rG   zFrontendHighlighter.setFormat\   s4     	%%%/////r*   N)__name__
__module____qualname____doc__r   r3   r5   r=   rC   rG   __classcell__r(   s   @r)   r   r      s         

 

 

 

 

 

	 	 		 	 	3 3 3 3 30# # # # #0 0 0 0 0 0 0 0 0r*   r   c                       e Zd ZdZ ed          Z e            Z ed          Z ed          Z	 e
j                    Z ed          Z e
j        e          Z e
j                    Z eddd          Z eddd          Z eddd          Z edd	          Zd
 Zd Z e            Zd Z e
j        e          Z e
j        e          Z e
j        e          Z edddg          Z  edg d          Z! edg d          Z"dZ# e$e%d          Z&e#f fd	Z'd Z(d Z)d Z*d Z+d Z, fdZ-d Z.d Z/ fdZ0d Z1d  Z2d! Z3d" Z4d# Z5d$ Z6dAd%Z7d& Z8dAd'Z9d( Z:d) Z;d* Z<d+ Z=d, Z>d- Z?d. Z@d/ ZAdBd0ZBdBd1ZCd2 ZDd3 ZEd4 ZFd5 ZGd6 ZHd7 ZId8 ZJd9 ZKd: ZLd; ZMd< ZNd= ZOd> ZP eQd?          d@             ZR xZSS )CFrontendWidgetz0 A Qt frontend for a generic Python kernel.
    T)configFz9Whether to draw information calltips on open-parentheses.)rT   helpz9Whether to clear the console when the kernel is restartedz;Whether to ask for user confirmation when restarting kernelz The pygments lexer class to use.c                 B    t          |          } |            | _        d S rK   )r   r   )r&   namerE   newlexer_classs        r)   _lexer_class_changedz#FrontendWidget._lexer_class_changed   s     !#&& []]


r*   c                     dS )Nzpygments.lexers.Python3Lexer r&   s    r)   _lexer_class_defaultz#FrontendWidget._lexer_class_default   s    --r*   c                 >    t          | j                  } |            S rK   )r   rY   )r&   rY   s     r)   _lexer_defaultzFrontendWidget._lexer_default   s    !$"233{}}r*   _CallTipRequestidpos_CompletionRequest)rb   coderc   _ExecutionRequest)rb   kindhidden)
allow_nonec                     t                      j        |i | t          | j                  | _        t          | j                  | _        t          j        dd           | _	        t          | | j                  | _        d | _        d | _        i | _        i | j        d<   i | _        d| _        d| _        |                     d           | j                            | j                   | j                            | j        j                   | j	        }t0          j        j        t0          j        j        z  t0          j        j        z  }|                    d           |                    t?          j         |                     |!                    t0          j        j"                   |j#                            | j$                   | j%                            |j                   | &                    |           | j        '                                }|j(                            | j)                   || _*        d| _+        d S )NzCopy (Raw Text)r   executeT   z... F),r   r   r   r   _bracket_matcherr   _call_tip_widgetr   QAction_copy_raw_actionr   r   _highlighter_kernel_manager_kernel_client_request_info_callback_dict_display_banner	tab_width_set_continuation_promptsetFontfontfont_changedconnectr   QtCTRLSHIFTKey_C
setEnabledsetShortcutr   QKeySequencesetShortcutContextWidgetWithChildrenShortcut	triggeredcopy_rawcopy_available	addActionr   contentsChange_document_contents_change_local_kernel_pending_clearoutput)r&   local_kernelargskwactionkeyr   r(   s          r)   r   zFrontendWidget.__init__   s   $%"%%% .t} = = -dm < < ) 12CT J J/DJGGG#"(*9% # %%f--- 	%%di000!!$"7"?@@@ &invy.@%   5-c22333!!&)"FGGG  ///##F$5666v =))++''(FGGG * %*!!!r*   c                 R     j         4 j                                         r j                                          dS  j                                        r6 j                                                                                                        }|r|                                ^}} j                                        }|                    |	                                           |                    |
                                                                t          j        j                   |                                                                } fd}||z   }t          |          } ||          }|t          |          z
  }	|	t          |          k     r|t          |          |	z
  d         }t          |          dk    r1|d         r( j                                        }|                    |                                           |
                                }
|
                                }|
                                }|                    |           |                    ||z   dz
  t          j        j                   |                                                                }t          |          t           ||                    z
  }	t          |d                   |	k     rd|d<   t%          ||          }d                    |g|          }	 |d         dk    }n# t(          $ r d}Y nw xY w|r
|dd         }t*          j                                                            |           dS dS  j                            d	           dS )
zN Copy the currently selected text to the clipboard, removing prompts.
        Nc                 l    j                             |           } j                             |           S )zRemove all prompts from line.)rq   r3   r5   r1   r&   s    r)   remove_promptsz+FrontendWidget.copy.<locals>.remove_prompts   s0    ,EEdKKD,AA$GGGr*   r   r    
Fz%frontend widget : unknown copy target)_page_controlhasFocuscopyr   
textCursor	selectiontoPlainText
splitlinessetPositionselectionStartrD   positionr   QTextCursor
KeepAnchorr.   selectionEndlengthmapjoin
IndexErrorr   QApplication	clipboardsetTextlogdebug)r&   r;   first_line_selectionremaining_linescursorpreceding_textr   
first_linelen_with_prompt
prompt_lenrD   	start_posr   last_line_fullwas_newlines   `              r)   r   zFrontendWidget.copy   s    )d.@.I.I.K.K)##%%%%%]##%% ;	D=++--7799EEGGD 7A9=9J9J6$ 1133""6#8#8#:#:;;;""6<<>>#:#:#<#<#(#4#?A A A!'!1!1!3!3!?!?!A!AH H H H H ,.BB
"%j//+^J77
,s:>
 N 3 333!+C,?,?*,L,M,M!NJ ''!++0C+!]5577F&&v':':'<'<==="LLNNE % 0 0I"\\^^F&&y111&&y6'9A'=','8'CE E E%+%5%5%7%7%C%C%E%ENN++nn^<<==>  ?2.//*<<.0+ #&no"F"Fyy*!?!?@@("&r(d"2KK! ( ( ("'KKK( %9D&0022::4@@@@@o7A 7Ar HNNBCCCCCs   -L: :M	M	c                     | j                             ||          }|                     |d|          | j        d         |<   |s| j                            |           dS dS )z Execute 'source'. If 'hidden', do not show any output.

        See parent class :meth:`execute` docstring for full details.
        userrk   N)kernel_clientrk   rf   rt   	executingemit)r&   sourcerh   msg_ids       r)   _executezFrontendWidget._execute  ss    
 #++FF;;040F0FFF1$ 1$9%f- 	(N'''''	( 	(r*   c                 0    | j         sd| j        _        dS dS )z= Called immediately after a new prompt is displayed.
        TN_readingrq   r   r]   s    r)   _prompt_started_hookz#FrontendWidget._prompt_started_hook'  s)     } 	504D---	5 	5r*   c                 0    | j         sd| j        _        dS dS )z Called immediately after a prompt is finished, i.e. when some input
            will be processed and a new prompt displayed.
        FNr   r]   s    r)   _prompt_finished_hookz$FrontendWidget._prompt_finished_hook-  s)     } 	605D---	6 	6r*   c                 2   |                                  }|dS t          |d|                                                                                    }|o)|                                                                 dk    }|r|                                  | S )zk Called when the tab key is pressed. Returns whether to continue
            processing the event.
        NFr   )_get_input_buffer_cursor_linebool_get_input_buffer_cursor_columnstrip_get_cursorselectedText	_complete)r&   r;   non_ws_beforecompletes       r)   _tab_pressedzFrontendWidget._tab_pressed4  s     1133<5T"I4#G#G#I#I"IJPPRRSS LT%5%5%7%7%D%D%F%F"%L 	NN|r*   c                 D   t                                          |          }|                                D ]h}|                                                    t
          j        j                  t
          j        j        k    r|	                    || j
                    ni|S )z6 Reimplemented to add an action for raw copy.
        )r   _context_menu_makeactionsshortcutmatchesr   r   Paste
ExactMatchinsertActionrp   )r&   rc   menubefore_actionr(   s       r)   r   z!FrontendWidget._context_menu_makeI  s     ww))#..!\\^^ 	 	M%%''//0B0HII&12 2!!-1FGGG2 r*   c                 @    | j         r|                                  d S d S rK   )
_executinginterrupt_kernelr]   s    r)   request_interrupt_kernelz'FrontendWidget.request_interrupt_kernelT  s.    ? 	$!!#####	$ 	$r*   c                 8    d}|                      |d           d S )Nz,Are you sure you want to restart the kernel?Fnow)restart_kernel)r&   messages     r)   request_restart_kernelz%FrontendWidget.request_restart_kernelX  s&    @G/////r*   c                 <   |                                 }|                     |                                d          r|t          j        j        k    rj| j        rc|                                 r9|                    t          j
        j                  r|                                  n|                                  dS |t          j        j        k    r|                                  dS n|                                t          j        j        z  s|t          j        j        k    r|                                 }| j                                        }|dk    r|                                s|                                 d|         }|                    d          r_|                                sK|                    t          j        j        t          j        j        d           |                                 dS t=                                          |          S )zG Reimplemented for execution interruption and smart backspace.
        F)include_commandT   Nz    rl   ) r   _control_key_down	modifiersr   r}   r   r   can_copyr   r   r   Copyr   r   
Key_Periodr   AltModifierKey_Backspacer   r   r   hasSelectionr   endswithr   movePositionr   Leftr   removeSelectedTextr   _event_filter_console_keypress)r&   eventr   colr   r;   r(   s         r)   r   z-FrontendWidget._event_filter_console_keypress\  s    iikk!!%//"3"3U!KK 	$fio%%$/%==?? 4u}}U5G5L'M'M 4IIKKKK11333t	,,,++---t - ""VY%:: 	$
 fi---::<<1133776#6#6#8#87==??ED}}V,, $TZZ\\ $++E,=,B,1,=,H!M M M11333#tww55e<<<r*   c                     |                      |          r=|d                             dd          }|r	d| _        dS |                                  dS dS )zHandle clear output messages.contentwaitTN)include_outputgetr   clear_output)r&   msgr   s      r)   _handle_clear_outputz#FrontendWidget._handle_clear_output  si    s## 	$y>%%fd33D $,0)))!!#####	$ 	$r*   c                     t          t          j                              }| j                            dd||i          }|| j        |<   |                     |dd          | j        d         |<   dS )aL  Silently execute `expr` in the kernel and call `callback` with reply

        the `expr` is evaluated silently in the kernel (without) output in
        the frontend. Call `callback` with the
        `repr <http://docs.python.org/library/functions.html#repr> `_ as first argument

        Parameters
        ----------
        expr : string
            valid string to be executed by the kernel.
        callback : function
            function accepting one argument, as a string. The string will be
            the `repr` of the result of evaluating `expr`

        The `callback` is called with the `repr()` of the result of `expr` as
        first argument. To get the object, do `eval()` on the passed value.

        See Also
        --------
        _handle_exec_callback : private method, deal with calling callback with reply

        r   T)silentuser_expressionssilent_exec_callbackFrk   N)struuiduuid1r   rk   ru   rf   rt   )r&   exprcallback
local_uuidr   s        r)   _silent_exec_callbackz$FrontendWidget._silent_exec_callback  s}    4 &&
#++BJt*= , ? ?*2J'040F0F*E13 139%f---r*   c                     |d                              d          }|sdS |D ]4}|| j        v r) | j                            |          ||                    5dS )a  Execute `callback` corresponding to `msg` reply, after ``_silent_exec_callback``

        Parameters
        ----------
        msg : raw message send by the kernel containing an `user_expressions`
                and having a 'silent_exec_callback' kind.

        Notes
        -----
        This function will look for a `callback` associated with the
        corresponding message id. Association has been made by
        `_silent_exec_callback`. `callback` is then called with the `repr()`
        of the value of corresponding `user_expressions` as argument.
        `callback` is then removed from the known list so that any message
        coming again with the same id won't trigger it.
        r   r  N)r   ru   pop)r&   r   user_exp
expressions       r)   _handle_exec_callbackz$FrontendWidget._handle_exec_callback  s{    " y>%%&899 	F" 	J 	JJT0003#''
33HZ4HIII	J 	Jr*   c                    | j                             d|                    dd                     |d         d         }| j        d                             |          }d| _        |r|j        rdS |j        d	k    r| j        j        	                                s| j        j        
                                 | j        r| j                                         |d         }|d
         }|dk    r|                     |           n|dk    r|                     |           |                     |           | j                            |           | j        d                             |           dS |j        dk    r7|                     |           | j        d                             |           dS t+          d|j        z            )z- Handles replies for code execution.
        zexecute_reply: %sr   r   parent_headerr   rk   FNr   statusokabortedr  zUnknown handler for %s)r   r   r   rt   r   rh   rg   r   iopub_channelclosedflush
ansi_codes_ansi_processor	reset_sgr_process_execute_ok_process_execute_abort"_show_interpreter_prompt_for_replyexecutedr   r  r  RuntimeError)r&   r   r   infor   r  s         r)   _handle_execute_replyz$FrontendWidget._handle_execute_reply  s    	*CGGIr,B,BCCC_%h/!),0088  	t{ 	F9 %3::<< 9"066888
  1$..000)nGX&F~~((----9$$++C00033C888Ms###y)--f55555Y000&&s+++y)--f555557$)CDDDr*   c                 0    |                      |           dS )z  Handle error messages.
        N)_process_execute_errorr&   r   s     r)   _handle_errorzFrontendWidget._handle_error  s     	##C(((((r*   c                 $     j                             d|                    dd                     |d         d         } j        d                             |          }|r|j        rt          d           j        j                                        s j        j        	                                  fd} j
        r! j                             d	           d
 _
                             |d         d         ||d         d                    dS )z( Handle requests for raw_input.
        z	input: %sr   r   r  r   rk   z.Request for raw input during hidden execution.c                 d                                      j                            |            d S rK   )_finalize_input_requestr   inputr   s    r)   r	  z6FrontendWidget._handle_input_request.<locals>.callback   s2    ((***$$T*****r*   z9Got second input request, assuming first was interrupted.Fpromptpassword)r	  r,  N)r   r   r   rt   rh   r   r   r  r  r  r   	_readline)r&   r   r   r!  r	  s   `    r)   _handle_input_requestz$FrontendWidget._handle_input_request  s    	{CGGIr$:$:;;;_%h/!),0088 	QDK 	QOPPP !/6688 	5,22444	+ 	+ 	+ 	+ 	+ = 	"HNNVWWW!DMs9~h/(SQZ^\fMghhhhhr*   c                 F    |rdnd}|                      d|z  d           d S )NzKernel died, restartingzKernel restartingz<br>%s<hr><br>Fbefore_prompt)_append_html)r&   diedr   s      r)   _kernel_restarted_messagez(FrontendWidget._kernel_restarted_message  sE    +/H''5H*S0 	 	
 	
 	
 	
 	
r*   c                     | j                             d|           | j        r| j                            |           dS |                     d           |                                  dS )zAHandle the kernel's death (if we do not own the kernel).
        zkernel died: %sTr3  N)r   warningcustom_restartcustom_restart_kernel_diedr   r4  reset)r&   since_last_heartbeats     r)   _handle_kernel_diedz"FrontendWidget._handle_kernel_died  so     	*,@AAA 	+001EFFFFF***555JJLLLLLr*   c                     | j                             d           |                     |           | j        r| j                                         |                                  dS )zoNotice that the autorestarter restarted the kernel.

        There's nothing to do but show a message.
        zkernel restartedr6  N)r   r7  r4  kernel_managerreset_autorestart_countr:  )r&   r3  s     r)   _handle_kernel_restartedz'FrontendWidget._handle_kernel_restarted  se    
 	+,,,&&D&111  	:77999

r*   c                    | j                             d|                    dd                     |                                 }| j                            d          }|r|j        |d         d         k    rr|j        |                                k    rW|d         }|                    d          dk    r8|                    d	d
          r$| j        	                    |           dS dS dS dS dS dS )zHandle replies for call tips.z	oinfo: %sr   r   call_tipr  r   r  r  foundFN)
r   r   r   r   rt   rb   rc   r   rn   show_inspect_data)r&   repr   r!  r   s        r)   _handle_inspect_replyz$FrontendWidget._handle_inspect_reply'  s    {CGGIr$:$:;;;!!##!%%j11 	ADGs?3H===FOO----)nG{{8$$,,We1L1L,%77@@@@@		A 	A==--,,,,r*   c                 
   | j                             d|                    dd                     |                     |          r>|                                  |d         d         }|                     |dz   d           dS dS )	z% Handle display hook output.
        zexecute_result: %sr   r   datar   Tr0  N)r   r   r   r   flush_clearoutput_append_plain_text)r&   r   r;   s      r)   _handle_execute_resultz%FrontendWidget._handle_execute_result2  s     	+SWWY-C-CDDDs## 	E""$$$y>&)D##D4Kt#DDDDD	E 	Er*   c                     | j                             d|                    dd                     |                     |          r7|                                  |                     |d         d                    dS dS )z+ Handle stdout, stderr, and stdin.
        z
stream: %sr   r   r;   N)r   r   r   r   rI  append_streamr%  s     r)   _handle_streamzFrontendWidget._handle_stream;  s}     	|SWWY%;%;<<<s## 	7""$$$s9~f566666	7 	7r*   c                    | j                             d|                    dd                     |                    di                               dd          }|d         r9|d         d         }| j        d                             |          }|r	|j        rd	S |                     |          s|r|                     d
           d	S | j        r| j        	                    |            d	S | 
                                                                }t          j                            | |dt          j        j        t          j        j                  }|t          j        j        k    r| j        	                    |            d	S d	S d	S )z= Handle shutdown signal, only if from other console.
        zshutdown: %sr   r   restartFr  r   rk   Nr6  z8Kernel has been shutdown permanently. Close the Console?)r   r   r   rt   rh   	from_herer@  r   exit_requestedr   windowwindowTitler   QMessageBoxquestionYesNo)r&   r   rP  r   r!  titlereplys          r)   _handle_shutdown_replyz%FrontendWidget._handle_shutdown_replyC  s    	~swwy"'='=>>>'')R((,,Y>> 	)(3F%i044V<<D  ~~c"" 	7 7--5-99999 % 	7',,T22222 KKMM5577E%1::4-!-1)2G2JL LE 	 5 999+0066666'	7 	7$ :9r*   c                     |d                              dd          }|dk    r!| j        r|                     d           d	S d	S |dk    rd	S |dk    rd	S d	S )
zHandle status messager   execution_stater   startingTr6  idlebusyN)r   r   r@  )r&   r   states      r)   _handle_statuszFrontendWidget._handle_statusb  s}     I""#4b99J 9--4-888889 9f__Df__D _r*   c                 2    |                      d           dS )z Called when the KernelManager channels have started listening or
            when the frontend is assigned an already listening KernelManager.
        T)clearN)r:  r]   s    r)   _started_channelsz FrontendWidget._started_channelsp  s     	


r*   c                 8    | j                                          dS )z Copy the currently selected text to the clipboard without attempting
            to remove prompts or otherwise alter the text.
        N)r   r   r]   s    r)   r   zFrontendWidget.copy_rawz  s     	r*   c                     | j         r"d| _        | j                                         dS | j        r"d| _        | j                                         dS |                     d           dS )z Attempts to interrupt the running kernel.

        Also unsets _reading flag, to avoid runtime errors
        if raw_input is called again.
        Fz+Cannot interrupt a kernel I did not start.
N)custom_interruptr   custom_interrupt_requestedr   r>  r   rJ  r]   s    r)   r   zFrontendWidget.interrupt_kernel  s{       	T!DM+0022222  	T!DM0022222##$RSSSSSr*   c                 >   | j         rd| _         i | j        d<   d| _        d| j        _        |r[| j                                         | j        r;|                     | j	                   | j
        r|                     | j
                   |                                  dS )a   Resets the widget to its initial state if ``clear`` parameter
        is True, otherwise
        prints a visual indication of the fact that the kernel restarted, but
        does not clear the traces from previous usage of the kernel before it
        was restarted.  With ``clear=True``, it is similar to ``%clear``, but
        also re-writes the banner and aborts execution if necessary.
        Frk   N)r   rt   r   rq   r   r   rd  rv   rJ  bannerkernel_banner_show_interpreter_prompt)r&   rd  s     r)   r:  zFrontendWidget.reset  s     ? 	/#DO,.Dy),1) 	@M!!!# @''444% @++D,>??? 	%%'''''r*   c                    | j         r| j                                         dS | j        r| j        j                                         | j        r[t          j	        j
        t          j	        j        z  }t          j	                            | d||          }|t          j	        j
        k    }nd}|rg	 | j                            |           |                     dd           dS # t          $ r%}|                     d|z  d           Y d}~dS d}~ww xY w| j        j                                         dS |                     dd           dS )	z1 Attempts to restart the running kernel.
        NzRestart kernel?Tr   z!<br>Restarting kernel...
<hr><br>r0  zError restarting kernel: %s
z(Cannot restart a Kernel I did not start
)r8  custom_restart_requestedr   r>  r   
hb_channelpauseconfirm_restartr   rU  rW  rX  rV  r   r2  r   rJ  unpause)r&   r   r   buttonsresult
do_restartes          r)   r   zFrontendWidget.restart_kernel  s     	)..000F #	)//111
 # "#/3i6K6NN".77>O4;WF F#y'<'@@

 "
 8
'6636??? %%&J&* &      $   ++7!;&* ,          "-5577777 ##;" $     s   0C$ $
D.DDc                 4    |                      |d           dS )z"Appends text to the output stream.Tr0  NrJ  )r&   r;   s     r)   rM  zFrontendWidget.append_stream  s!    D99999r*   c                 N    | j         rd| _         |                                  dS dS )z(If a clearoutput is pending, execute it.FN)r   r   r]   s    r)   rI  z FrontendWidget.flush_clearoutput  s7    $ 	 (-D%	  	 r*   c                    | j                                         }|                                 |                    t          j        j        t          j        j                   |                    d           |	                                 dS )z"Clears the current line of output.r   N)
r   r   beginEditBlockr   r   r   StartOfLiner   
insertTextendEditBlockr&   r   s     r)   r   zFrontendWidget.clear_output  s|    ))++E-9!-8	: 	: 	:"r*   c                    |                                  }|                    t          j        j                   |                                                    |                                          dk    r|                                  dS dS )z{Trigger call tip automatically on open parenthesis

        Call tips can be requested explcitly with `_call_tip`.
        (N)	r   r   r   r   r   r   characterAtr   	_call_tipr  s     r)   _auto_call_tipzFrontendWidget._auto_call_tip  s{    
 !!##E-2333??(():):;;sBBNN CBr*   c                 H   | j         r| j        j                                        sdS |                                 }| j        }| j                            ||          }|                                                                 }| 	                    ||          | j
        d<   dS )zAShows a call tip, if appropriate, at the current cursor location.FrB  T)enable_calltipsr   shell_channelis_alive_get_input_buffer_cursor_posinput_bufferinspectr   r   ra   rt   )r&   
cursor_posre   r   rc   s        r)   r  zFrontendWidget._call_tip  s     # 	4+=+K+T+T+V+V 	56688
 #++D*==  ))++)-)=)=fc)J)J:&tr*   c                     | j         }|                                 }| j                            ||          }|                     |||          }|| j        d<   dS )z= Performs completion at the current cursor location.
        )re   r  r   N)r  r  r   r   rd   rt   )r&   re   r  r   r!  s        r)   r   zFrontendWidget._complete	  sb      6688
#,,$:,NN&&vtZ@@)-:&&&r*   c                 0    |                      d           dS )z; Process a reply for an aborted execution request.
        zERROR: execution aborted
Nry  r%  s     r)   r  z%FrontendWidget._process_execute_abort  s     	 <=====r*   c                    |d         }|d         dk    r;|d         dk    p|d         dk    }|| _         | j                            |            d	S d                    |d                   }|                     |           d	S )
zM Process a reply for an execution request that resulted in an error.
        r   ename
SystemExitevaluez-kTruer   	tracebackN)_keep_kernel_on_exitrR  r   r   rJ  )r&   r   r   
keepkernelr  s        r)   r$  z%FrontendWidget._process_execute_error  s     i. 7\)) *D0MGH4Ev4MJ(2D%$$T***** 455I##I.....r*   c                     |d                              dg           }|D ]>}|                     |          s'd}t          |t          |d                   z             ?dS )z= Process a reply for a successful execution request.
        r   payloadz,Warning: received unknown payload of type %sr   N)r   _process_execute_payloadprintrepr)r&   r   r  itemr7  s        r)   r  z"FrontendWidget._process_execute_ok'  sq     i.$$Y33 	6 	6D0066 6HgT(^ 4 44555	6 	6r*   c                     dS )z Process a single payload item from the list of payload items in an
            execution reply. Returns whether the payload was handled.
        Fr\   )r&   r  s     r)   r  z'FrontendWidget._process_execute_payload0  s	     ur*   c                 0    |                      d           dS )z- Shows a prompt for the interpreter.
        z>>> N)_show_promptr]   s    r)   rm  z'FrontendWidget._show_interpreter_prompt8  s     	&!!!!!r*   c                 .    |                                   dS )zN Shows a prompt for the interpreter given an 'execute_reply' message.
        N)rm  r%  s     r)   r  z1FrontendWidget._show_interpreter_prompt_for_reply=  s     	%%'''''r*   c                     ||z  }||                                                                  k    r|                                  dS dS )zh Called whenever the document's content changes. Display a call tip
            if appropriate.
        N)r   r   r  )r&   r   removedaddeds       r)   r   z(FrontendWidget._document_contents_changeD  sQ    
 	Et''))224444!!!!! 54r*   rk  c                 <    d}|t           j        t           j        fz  S )z- Returns the standard Python banner.
        zVPython %s on %s
Type "help", "copyright", "credits" or "license" for more information.)sysversionplatform)r&   rk  s     r)   _banner_defaultzFrontendWidget._banner_defaultO  s    .cl333r*   )T)F)TrL   rM   rN   rO   r   rk  rl  r
   rv   rh  r   Signalri  r8  floatr9  ro  r  clear_on_kernel_restartrr  r   rY   rZ   r^   r	   r   r`   objectr   r  rR  r   ra   rd   rf   r   r   r   rq   r   r   r   r   r   r   r   r   r   r   r   r  r  r"  r&  r.  r4  r<  r@  rF  rK  rN  r[  rb  re  r   r   r:  r   rM  rI  r   r  r  r   r  r$  r  r  rm  r  r   r   r  rP   rQ   s   @r)   rS   rS   c   s         WD!!!FGIIMd5kkO tE{{!. T%[[N!.u!5!5,v} d4HJ J JO #d4HJ J J d4JL L LO #"$/  K# # #. . . CEEE   f%%I v}V$$H #V]6**N j!2T5MBBO#$8$9$9$9; ;"
5557 7M8/DAAAL %2 (* (* (* (* (* (*\@D @D @DL	( 	( 	(5 5 56 6 6  *	 	 	 	 	$ $ $0 0 0"= "= "= "= "=N$ $ $3 3 3BJ J J0&E &E &EP) ) )
i i i,
 
 
 
     	A 	A 	AE E E7 7 77 7 7>      T T T( ( ( (20 0 0 0d: : :       	 	 	  . . .> > >
/ / /6 6 6  " " "
( ( (" " " WX4 4 4 4 4 4 4r*   rS   )rO   collectionsr   r  r  r    qtpyr   r   r   ipython_genutils.importstringr   qtconsole.base_frontend_mixinr   	traitletsr	   r
   r   r   r   r   bracket_matcherr   call_tip_widgetr   history_console_widgetr   pygments_highlighterr   r   rS   r\   r*   r)   <module>r     sj   ( (
 # " " " " " 



  				 ) ) ) ) ) ) ) ) ) ) 5 5 5 5 5 5 ; ; ; ; ; ; M M M M M M M M M M M M M M M M + + + + + + * * * * * * 8 8 8 8 8 8 5 5 5 5 5 5J0 J0 J0 J0 J0- J0 J0 J0Zr4 r4 r4 r4 r4)+< r4 r4 r4 r4 r4r*   