B
    –õå[J€  ã               @   sæ   d Z ddlmZ ddlmZ ddlZddlZddlZddlm	Z	 ddl
mZmZ ddl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 ddlmZ ddlmZ ddlmZ ddlm Z  G dd„ de ƒZ!G dd„ deeƒZ"dS )z"Frontend widget for the Qt Consoleé    )Úprint_function)Ú
namedtupleN)Úqt)ÚQtCoreÚQtGui)Ú	py3compat)Úimport_item)ÚBaseFrontendMixin)ÚAnyÚBoolÚInstanceÚUnicodeÚDottedObjectNameé   )ÚBracketMatcher)ÚCallTipWidget)ÚHistoryConsoleWidget)ÚPygmentsHighlighterc                   sV   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Z‡ fd	d
„Z‡ fdd„Z‡ fdd„Z	‡  Z
S )ÚFrontendHighlighterzA A PygmentsHighlighter that understands and ignores prompts.
    Nc                s`   t t| ƒj|j ¡ |d d| _|| _d| _t 	dt 
|j¡ ¡| _t 	dt 
|j¡ ¡| _d S )N)Úlexerr   Fz!^(%s)?([ \t]*>>> |^[ \t]*\.\.\. )z0^(%s)?([ \t]*In \[\d+\]: |[ \t]*\ \ \ \.\.\.+: ))Úsuperr   Ú__init__Ú_controlÚdocumentÚ_current_offsetÚ	_frontendÚhighlighting_onÚreÚcompileÚescapeZother_output_prefixÚ_classic_prompt_reÚ_ipy_prompt_re)ÚselfZfrontendr   )Ú	__class__© ú8lib/python3.7/site-packages/qtconsole/frontend_widget.pyr      s    zFrontendHighlighter.__init__c             C   s>   |r|  ¡ r|S | j |¡}|r6|t| d¡ƒd… S |S dS )z,Handle inputs that start with '>>> ' syntax.r   N)Úisspacer    ÚmatchÚlenÚgroup)r"   ÚlineÚmr$   r$   r%   Útransform_classic_prompt*   s    z,FrontendHighlighter.transform_classic_promptc             C   s>   |r|  ¡ r|S | j |¡}|r6|t| d¡ƒd… S |S dS )z7Handle inputs that start classic IPython prompt syntax.r   N)r&   r!   r'   r(   r)   )r"   r*   r+   r$   r$   r%   Útransform_ipy_prompt5   s    z(FrontendHighlighter.transform_ipy_promptc                sd   t | dƒr| jsdS |  ¡ }| j |¡}|  |¡}t|ƒt|ƒ }|dkr`|| _tt	| ƒ 
|¡ dS )zL Highlight a block of text. Reimplemented to highlight selectively.
        r   Nr   )Úhasattrr   ZcurrentBlockr   Z_get_block_plain_textr-   r(   r   r   r   ÚhighlightBlock)r"   ÚstringZcurrent_blockZwithout_promptZdiff)r#   r$   r%   r/   @   s    
z"FrontendHighlighter.highlightBlockc                s&   | j }d| _ tt| ƒ |¡ || _ dS )zG Reimplemented to temporarily enable highlighting if disabled.
        TN)r   r   r   ÚrehighlightBlock)r"   ÚblockÚold)r#   r$   r%   r1   T   s    z$FrontendHighlighter.rehighlightBlockc                s"   || j 7 }tt| ƒ |||¡ dS )z1 Reimplemented to highlight selectively.
        N)r   r   r   Ú	setFormat)r"   ÚstartÚcountÚformat)r#   r$   r%   r4   \   s    
zFrontendHighlighter.setFormat)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r,   r-   r/   r1   r4   Ú__classcell__r$   r$   )r#   r%   r      s   r   c                   sr  e Zd ZdZeddZeƒ ZedƒZedƒZ	e
 ¡ ZedƒZe
 e¡Ze
 ¡ ZeddddZeddddZeddddZedd	dZd
d„ Zdd„ Zeƒ Zdd„ Ze
 e¡Ze
 e¡Ze
 e¡ZedddgƒZ edddgƒZ!edddgƒZ"dZ#e$e%ddZ&e#f‡ fdd„	Z'dd„ Z(dd„ Z)dd„ Z*dd „ Z+d!d"„ Z,‡ fd#d$„Z-d%d&„ Z.d'd(„ Z/‡ fd)d*„Z0d+d,„ Z1d-d.„ Z2d/d0„ Z3d1d2„ Z4d3d4„ Z5d5d6„ Z6dmd7d8„Z7d9d:„ Z8dnd;d<„Z9d=d>„ Z:d?d@„ Z;dAdB„ Z<dCdD„ Z=dEdF„ Z>dGdH„ Z?dIdJ„ Z@dKdL„ ZAdodMdN„ZBdpdOdP„ZCdQdR„ ZDdSdT„ ZEdUdV„ ZFdWdX„ ZGdYdZ„ ZHd[d\„ ZId]d^„ ZJd_d`„ ZKdadb„ ZLdcdd„ ZMdedf„ ZNdgdh„ ZOdidj„ ZPdkdl„ ZQ‡  ZRS )qÚFrontendWidgetz0 A Qt frontend for a generic Python kernel.
    T)ÚconfigFz9Whether to draw information calltips on open-parentheses.)r>   Ú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             C   s   t |ƒ}|ƒ | _d S )N)r   r   )r"   Únamer3   ÚnewÚlexer_classr$   r$   r%   Ú_lexer_class_changed…   s    z#FrontendWidget._lexer_class_changedc             C   s   t jr
dS dS d S )Nzpygments.lexers.Python3Lexerzpygments.lexers.PythonLexer)r   ZPY3)r"   r$   r$   r%   Ú_lexer_class_default‰   s    z#FrontendWidget._lexer_class_defaultc             C   s   t | jƒ}|ƒ S )N)r   rB   )r"   rB   r$   r$   r%   Ú_lexer_default   s    
zFrontendWidget._lexer_defaultÚ_CallTipRequestÚidÚposÚ_CompletionRequestÚ_ExecutionRequestÚkind)Z
allow_nonec                sl  t t| ƒj||Ž tjtjkrFdd l}|jdk rF| j 	d|j
¡ d| _t| jƒ| _t| jƒ| _t dd ¡| _d| _t| | jd| _d | _d | _i | _i | jd< i | _d| _d	| _|  d
¡ | j | j ¡ | j! "| jj¡ | j}t#j$j%t#j$j&B t#j$j'B }| (d¡ | )t *|¡¡ | +t#j$j,¡ |j- "| j.¡ | j/ "|j(¡ |  0|¡ | j 1¡ }|j2 "| j3¡ || _4d| _5d S )Nr   )r   r   é   z+PySide %s < 1.0.7 found; disabling calltipsFzCopy (Raw Text))r   ÚexecuteTé   z... )6r   r=   r   r   ZQT_APIZQT_API_PYSIDEÚPySideZ__version_info__ÚlogÚwarningÚ__version__Úenable_calltipsr   r   Z_bracket_matcherr   Ú_call_tip_widgetr   ZQActionÚ_copy_raw_actionÚ_hiddenr   r   Ú_highlighterZ_kernel_managerZ_kernel_clientÚ_request_infoÚ_callback_dictÚ_display_bannerZ	tab_widthZ_set_continuation_promptZsetFontZfontZfont_changedZconnectr   ÚQtZCTRLZSHIFTÚKey_CZ
setEnabledZsetShortcutÚQKeySequenceZsetShortcutContextZWidgetWithChildrenShortcutZ	triggeredÚcopy_rawZcopy_availableZ	addActionr   ZcontentsChangeÚ_document_contents_changeÚ_local_kernelÚ_pending_clearoutput)r"   Zlocal_kernelÚargsÚkwrO   ÚactionÚkeyr   )r#   r$   r%   r   ©   sD    





zFrontendWidget.__init__c             C   sÊ   | j dk	r | j  ¡ r | j  ¡  n¦| j ¡ rº| j ¡  ¡  ¡ }|rÆ| ¡ }t| j	j
|ƒ}t| j	j|ƒ}d |¡}y|d dk}W n tk
r–   d}Y nX |r¨|dd… }tj ¡  |¡ n| j d¡ dS )zN Copy the currently selected text to the clipboard, removing prompts.
        NÚ
éÿÿÿÿFz%frontend widget : unknown copy target)Z_page_controlZhasFocusÚcopyr   Ú
textCursorZ	selectionZtoPlainTextÚ
splitlinesÚmaprW   r,   r-   ÚjoinÚ
IndexErrorr   ZQApplicationZ	clipboardZsetTextrP   Údebug)r"   ÚtextÚlinesZwas_newliner$   r$   r%   rh   á   s"    


zFrontendWidget.copyc             C   s>   | j  ||¡}|  |d¡| jd |< || _|s:| j |¡ dS )z† Execute 'source'. If 'hidden', do not show any output.

        See parent class :meth:`execute` docstring for full details.
        ÚuserrM   N)Úkernel_clientrM   rJ   rX   rV   Ú	executingÚemit)r"   ÚsourceZhiddenÚmsg_idr$   r$   r%   Ú_executeþ   s
    zFrontendWidget._executec             C   s   | j sd| j_dS )z= Called immediately after a new prompt is displayed.
        TN)Ú_readingrW   r   )r"   r$   r$   r%   Ú_prompt_started_hook	  s    z#FrontendWidget._prompt_started_hookc             C   s   | j sd| j_dS )z‡ Called immediately after a prompt is finished, i.e. when some input
            will be processed and a new prompt displayed.
        FN)rx   rW   r   )r"   r$   r$   r%   Ú_prompt_finished_hook  s    z$FrontendWidget._prompt_finished_hookc             C   sR   |   ¡ }|dkrdS t|d|  ¡ …  ¡ ƒ}|o>|  ¡  ¡ dk}|rL|  ¡  | S )zk Called when the tab key is pressed. Returns whether to continue
            processing the event.
        NFÚ )Ú_get_input_buffer_cursor_lineÚboolÚ_get_input_buffer_cursor_columnÚstripÚ_get_cursorZselectedTextÚ	_complete)r"   ro   Znon_ws_beforeÚcompleter$   r$   r%   Ú_tab_pressed  s    zFrontendWidget._tab_pressedc                sP   t t| ƒ |¡}x:| ¡ D ].}| ¡  tjj¡tjj	kr| 
|| j¡ P qW |S )z6 Reimplemented to add an action for raw copy.
        )r   r=   Ú_context_menu_makeZactionsZshortcutZmatchesr   r]   ZPasteZ
ExactMatchZinsertActionrU   )r"   rH   ZmenuZbefore_action)r#   r$   r%   r„   +  s    
z!FrontendWidget._context_menu_makec             C   s   | j r|  ¡  d S )N)Ú
_executingÚinterrupt_kernel)r"   r$   r$   r%   Úrequest_interrupt_kernel6  s    z'FrontendWidget.request_interrupt_kernelc             C   s   d}| j |dd d S )Nz,Are you sure you want to restart the kernel?F)Únow)Úrestart_kernel)r"   Úmessager$   r$   r%   Úrequest_restart_kernel:  s    z%FrontendWidget.request_restart_kernelc                sä   |  ¡ }| j| ¡ ddrR|tjjkr8| jr8|  ¡  dS |tjjkrÔ|  	¡  dS n‚| ¡ tjj
@ sÔ|tjjkrÔ|  ¡ }| j ¡ }|dkrÔ| ¡ sÔ|  ¡ d|… }| d¡rÔ| ¡ sÔ| tjjtjjd¡ | ¡  dS tt| ƒ |¡S )zG Reimplemented for execution interruption and smart backspace.
        F)Zinclude_commandTé   Nz    rN   )re   Z_control_key_downZ	modifiersr   r[   r\   r…   r‡   Z
Key_Periodr‹   ZAltModifierZKey_Backspacer~   r   ri   ZhasSelectionr|   Úendswithr   ÚmovePositionr   ÚQTextCursorÚLeftÚ
KeepAnchorZremoveSelectedTextr   r=   Ú_event_filter_console_keypress)r"   Zeventre   ÚcolÚcursorro   )r#   r$   r%   r’   >  s(    

z-FrontendWidget._event_filter_console_keypressc             C   s2   |   |¡r.|d  dd¡}|r&d| _n|  ¡  dS )zHandle clear output messages.ÚcontentÚwaitTN)Úinclude_outputÚgetra   Úclear_output)r"   Úmsgr–   r$   r$   r%   Ú_handle_clear_outputa  s
    
z#FrontendWidget._handle_clear_outputc             C   sF   t t ¡ ƒ}| jjdd||id}|| j|< |  |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)ZsilentÚuser_expressionsÚsilent_exec_callbackrM   N)ÚstrÚuuidZuuid1rr   rM   rY   rJ   rX   )r"   ÚexprÚcallbackZ
local_uuidrv   r$   r$   r%   Ú_silent_exec_callbackj  s
    
z$FrontendWidget._silent_exec_callbackc             C   sF   |d   d¡}|sdS x*|D ]"}|| jkr| j |¡|| ƒ qW d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˜   rY   Úpop)r"   rš   Zuser_expZ
expressionr$   r$   r%   Ú_handle_exec_callbackŠ  s    

z$FrontendWidget._handle_exec_callbackc             C   s  | j  d| dd¡¡ |d d }| jd  |¡}d| _|rÆ|jdkrÆ| jsÆ| jj 	¡  | j
rh| j ¡  |d }|d	 }|d
krŒ|  |¡ n|dkrž|  |¡ |  |¡ | j |¡ | jd  |¡ nL|rö|jdkrö| jsö|  |¡ | jd  |¡ n|r| jstd|j ƒ‚dS )z- Handles replies for code execution.
        zexecute_reply: %sr•   r{   Úparent_headerrv   rM   Frq   ÚstatusÚokZabortedr   zUnknown handler for %sN)rP   rn   r˜   rX   rx   rK   rV   rr   Úiopub_channelÚflushZ
ansi_codesZ_ansi_processorZ	reset_sgrÚ_process_execute_okÚ_process_execute_abortÚ"_show_interpreter_prompt_for_replyÚexecutedrt   r£   r¤   ÚRuntimeError)r"   rš   rv   Úinfor•   r¦   r$   r$   r%   Ú_handle_execute_reply¢  s,    



z$FrontendWidget._handle_execute_replyc             C   s   |   |¡ dS )z  Handle error messages.
        N)Ú_process_execute_error)r"   rš   r$   r$   r%   Ú_handle_errorÇ  s    zFrontendWidget._handle_errorc                sx   ˆ j  d| dd¡¡ ˆ jr$tdƒ‚ˆ jj ¡  ‡ fdd„}ˆ jrTˆ j  d¡ dˆ _ˆ j	|d d	 ||d d
 d dS )z( Handle requests for raw_input.
        z	input: %sr•   r{   z.Request for raw input during hidden execution.c                s   ˆ j  | ¡ d S )N)rr   Úinput)r*   )r"   r$   r%   r¡   ×  s    z6FrontendWidget._handle_input_request.<locals>.callbackz9Got second input request, assuming first was interrupted.FÚpromptÚpassword)r¡   rµ   N)
rP   rn   r˜   rV   r®   rr   r¨   r©   rx   Z	_readline)r"   rš   r¡   r$   )r"   r%   Ú_handle_input_requestÌ  s    z$FrontendWidget._handle_input_requestc             C   s"   |rdnd}| j d| dd d S )NzKernel died, restartingzKernel restartingz<br>%s<hr><br>F)Úbefore_prompt)Ú_append_html)r"   Údiedrš   r$   r$   r%   Ú_kernel_restarted_messageÞ  s    
z(FrontendWidget._kernel_restarted_messagec             C   s:   | j  d|¡ | jr"| j |¡ n| jdd |  ¡  dS )zAHandle the kernel's death (if we do not own the kernel).
        zkernel died: %sT)r¹   N)rP   rQ   Úcustom_restartÚcustom_restart_kernel_diedrt   rº   Úreset)r"   Zsince_last_heartbeatr$   r$   r%   Ú_handle_kernel_diedä  s
    z"FrontendWidget._handle_kernel_diedc             C   s$   | j  d¡ | j|d |  ¡  dS )zoNotice that the autorestarter restarted the kernel.

        There's nothing to do but show a message.
        zkernel restarted)r¹   N)rP   rQ   rº   r½   )r"   r¹   r$   r$   r%   Ú_handle_kernel_restartedî  s    z'FrontendWidget._handle_kernel_restartedc             C   s€   | j  d| dd¡¡ |  ¡ }| j d¡}|r||j|d d kr||j| ¡ kr||d }| d¡dkr|| d	d
¡r|| j 	|¡ dS )zHandle replies for call tips.z	oinfo: %sr•   r{   Úcall_tipr¥   rv   r¦   r§   ÚfoundFN)
rP   rn   r˜   r€   rX   rG   rH   ÚpositionrT   Zshow_inspect_data)r"   Zrepr”   r¯   r•   r$   r$   r%   Ú_handle_inspect_reply÷  s    z$FrontendWidget._handle_inspect_replyc             C   sJ   | j  d| dd¡¡ |  |¡rF|  ¡  |d d }| j|d dd dS )	z% Handle display hook output.
        zexecute_result: %sr•   r{   Údatarf   T)r·   N)rP   rn   r˜   r—   Úflush_clearoutputÚ_append_plain_text)r"   rš   ro   r$   r$   r%   Ú_handle_execute_result  s
    
z%FrontendWidget._handle_execute_resultc             C   s>   | j  d| dd¡¡ |  |¡r:|  ¡  |  |d d ¡ dS )z+ Handle stdout, stderr, and stdin.
        z
stream: %sr•   r{   ro   N)rP   rn   r˜   r—   rÅ   Úappend_stream)r"   rš   r$   r$   r%   Ú_handle_stream  s    
zFrontendWidget._handle_streamc             C   s¤   | j  d| dd¡¡ | di ¡ dd¡}| js |  |¡s |rL| jdd nT| jr`| j | ¡ n@|  	¡  
¡ }tj | |dtjjtjj¡}|tjjkr | j | ¡ dS )	z= Handle shutdown signal, only if from other console.
        zshutdown: %sr•   r{   ÚrestartF)r¹   z8Kernel has been shutdown permanently. Close the Console?N)rP   rn   r˜   rV   Z	from_herer¿   r`   Úexit_requestedrt   ZwindowZwindowTitler   ÚQMessageBoxÚquestionÚYesÚNo)r"   rš   rÊ   ÚtitleZreplyr$   r$   r%   Ú_handle_shutdown_reply  s    
z%FrontendWidget._handle_shutdown_replyc             C   sB   |d   dd¡}|dkr,| jr>| jdd n|dkr6n|dkr>d	S )
zHandle status messager•   Zexecution_stater{   ZstartingT)r¹   ZidleZbusyN)r˜   r…   r¿   )r"   rš   Ústater$   r$   r%   Ú_handle_status-  s    zFrontendWidget._handle_statusc             C   s   | j d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"   r$   r$   r%   Ú_started_channels;  s    z FrontendWidget._started_channelsc             C   s   | j  ¡  dS )z‰ Copy the currently selected text to the clipboard without attempting
            to remove prompts or otherwise alter the text.
        N)r   rh   )r"   r$   r$   r%   r^   E  s    zFrontendWidget.copy_rawc             C   s>   | j rd| _| j ¡  n"| jr0d| _| j ¡  n
|  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_interruptrx   Úcustom_interrupt_requestedrt   Úkernel_managerr†   rÆ   )r"   r$   r$   r%   r†   K  s    zFrontendWidget.interrupt_kernelc             C   sb   | j rd| _ i | jd< d| _d| j_|rV| j ¡  | jrV|  | j	¡ | j
rV|  | 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.
        FrM   N)r…   rX   rx   rW   r   r   rÔ   rZ   rÆ   ÚbannerÚkernel_bannerÚ_show_interpreter_prompt)r"   rÔ   r$   r$   r%   r½   Z  s    

zFrontendWidget.resetc          
   C   sÜ   | j r| j ¡  dS | jrÊ| jj ¡  | jr\tj	j
tj	jB }tj	 | d||¡}|tj	j
k}nd}|r¼y| jj|d W n4 tk
rª } z| jd| dd W dd}~X Y qÈX | jddd qØ| jj ¡  n| jddd dS )	z1 Attempts to restart the running kernel.
        NzRestart kernel?T)rˆ   zError restarting kernel: %s
)r·   z!<br>Restarting kernel...
<hr><br>z(Cannot restart a Kernel I did not start
)r»   Úcustom_restart_requestedrt   rØ   rr   Z
hb_channelÚpauseÚconfirm_restartr   rÌ   rÎ   rÏ   rÍ   r‰   r®   rÆ   r¸   Zunpause)r"   rŠ   rˆ   ZbuttonsÚresultZ
do_restartÚer$   r$   r%   r‰   s  s0    	


zFrontendWidget.restart_kernelc             C   s   |  d¡}| j|dd dS )z"Appends text to the output stream.é   T)r·   N)Ú
expandtabsrÆ   )r"   ro   r$   r$   r%   rÈ   ¥  s    
zFrontendWidget.append_streamc             C   s   | j rd| _ |  ¡  dS )z(If a clearoutput is pending, execute it.FN)ra   r™   )r"   r$   r$   r%   rÅ   ­  s    z FrontendWidget.flush_clearoutputc             C   s8   | j  ¡ }| ¡  | |j|j¡ | d¡ | ¡  dS )z"Clears the current line of output.r{   N)r   ri   ZbeginEditBlockrŽ   ZStartOfLiner‘   Z
insertTextZendEditBlock)r"   r”   r$   r$   r%   r™   ³  s
    

zFrontendWidget.clear_outputc             C   s8   |   ¡ }| tjj¡ | ¡  | ¡ ¡dkr4|  ¡  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   ZcharacterAtrÂ   Ú	_call_tip)r"   r”   r$   r$   r%   Ú_auto_call_tip¿  s    zFrontendWidget._auto_call_tipc             C   sT   | j r| jj ¡ sdS |  ¡ }| j}| j ||¡}|  ¡  ¡ }|  	||¡| j
d< dS )zAShows a call tip, if appropriate, at the current cursor location.FrÀ   T)rS   rr   Zshell_channelZis_aliveÚ_get_input_buffer_cursor_posÚinput_bufferÚinspectr€   rÂ   rF   rX   )r"   Ú
cursor_posÚcoderv   rH   r$   r$   r%   rä   Ê  s    zFrontendWidget._call_tipc             C   s<   | j j| j|  ¡ d}|  ¡  ¡ }|  ||¡}|| jd< dS )z= Performs completion at the current cursor location.
        )rê   ré   r‚   N)rr   r‚   rç   ræ   r€   rÂ   rI   rX   )r"   rv   rH   r¯   r$   r$   r%   r   ×  s    zFrontendWidget._completec             C   s   |   d¡ dS )z; Process a reply for an aborted execution request.
        zERROR: execution aborted
N)rÆ   )r"   rš   r$   r$   r%   r«   ã  s    z%FrontendWidget._process_execute_abortc             C   s\   |d }|d dkr@|d dkp*|d dk}|| _ | j | ¡ nd |d ¡}|  |¡ d	S )
zM Process a reply for an execution request that resulted in an error.
        r•   ZenameÚ
SystemExitZevaluez-kÚTruer{   Ú	tracebackN)Z_keep_kernel_on_exitrË   rt   rl   rÆ   )r"   rš   r•   Z
keepkernelrí   r$   r$   r%   r±   è  s    z%FrontendWidget._process_execute_errorc             C   sD   |d   dg ¡}x.|D ]&}|  |¡sd}t|t|d ƒ ƒ qW dS )z= Process a reply for a successful execution request.
        r•   Úpayloadz,Warning: received unknown payload of type %sru   N)r˜   Ú_process_execute_payloadÚprintÚrepr)r"   rš   rî   ÚitemrQ   r$   r$   r%   rª   ÷  s
    

z"FrontendWidget._process_execute_okc             C   s   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ò   r$   r$   r%   rï      s    z'FrontendWidget._process_execute_payloadc             C   s   |   d¡ dS )z- Shows a prompt for the interpreter.
        z>>> N)Z_show_prompt)r"   r$   r$   r%   rÛ     s    z'FrontendWidget._show_interpreter_promptc             C   s   |   ¡  dS )zN Shows a prompt for the interpreter given an 'execute_reply' message.
        N)rÛ   )r"   rš   r$   r$   r%   r¬     s    z1FrontendWidget._show_interpreter_prompt_for_replyc             C   s.   ||7 }| j  ¡ }||  ¡  ¡ kr*|  ¡  dS )zh Called whenever the document's content changes. Display a call tip
            if appropriate.
        N)r   r   r€   rÂ   rå   )r"   rÂ   ZremovedZaddedr   r$   r$   r%   r_     s    
z(FrontendWidget._document_contents_changec             C   s   d}|t jt jf S )z- Returns the standard Python banner.
        zVPython %s on %s
Type "help", "copyright", "credits" or "license" for more information.)ÚsysÚversionÚplatform)r"   rÙ   r$   r$   r%   Ú_banner_default!  s    zFrontendWidget._banner_default)T)T)F)F)Sr8   r9   r:   r;   r   rÙ   rÚ   r   rZ   rÖ   r   ZSignalr×   r»   Úfloatr¼   rÜ   rS   Zclear_on_kernel_restartrÞ   r   rB   rC   rD   r
   r   rE   Úobjectrs   r­   rË   r   rF   rI   rJ   r`   r   r   rW   r   rh   rw   ry   rz   rƒ   r„   r‡   r‹   r’   r›   r¢   r¤   r°   r²   r¶   rº   r¾   r¿   rÃ   rÇ   rÉ   rÑ   rÓ   rÕ   r^   r†   r½   r‰   rÈ   rÅ   r™   rå   rä   r   r«   r±   rª   rï   rÛ   r¬   r_   rö   r<   r$   r$   )r#   r%   r=   c   s   




8#	 %


		


2	r=   )#r;   Z
__future__r   Úcollectionsr   ró   rŸ   r   Z	qtconsoler   Zqtconsole.qtr   r   Zipython_genutilsr   Zipython_genutils.importstringr   Zqtconsole.base_frontend_mixinr	   Z	traitletsr
   r   r   r   r   Zbracket_matcherr   Zcall_tip_widgetr   Zhistory_console_widgetr   Zpygments_highlighterr   r   r=   r$   r$   r$   r%   Ú<module>   s"   I