
    [A1e9                         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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 ddlmZ  G d de      Z G d dee      Zy)z"Frontend widget for the Qt Console    )
namedtupleN)QtCoreQtGui	QtWidgets)BaseFrontendMixin)AnyBoolInstanceUnicodeDottedObjectNamedefault   )BracketMatcher)CallTipWidget)HistoryConsoleWidget)PygmentsHighlighter)import_itemc                   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.
    c                 j   t         |   |j                  j                         |       d| _        || _        d| _        t        j                  dt        j                  |j                        z        | _        t        j                  dt        j                  |j                        z        | _        y )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      ;/usr/lib/python3/dist-packages/qtconsole/frontend_widget.pyr   zFrontendHighlighter.__init__   s    **335UC !$"$**0299X=Y=Y3ZZ#
 !jj?"))HLhLhBii
    c                     |r|j                         r|S | j                  j                  |      }|r|t        |j	                  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&   sL     t||~K##))$/AGGAJ())Kr*   c                     |r|j                         r|S | j                  j                  |      }|r|t        |j	                  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   sL     t||~K%%d+AGGAJ())Kr*   c                 $   t        | d      r| j                  sy| j                         }|j                         }|j	                  dd      }| j                  |      }t        |      t        |      z
  }|dkD  r|| _        t        | %  |       yy)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./t7K7K
 ))+##% , 226:6{S00!8#'D G">2 r*   c                 X    | j                   }d| _         t        | 	  |       || _         y)zG Reimplemented to temporarily enable highlighting if disabled.
        TN)r   r   rehighlightBlock)r&   blockoldr(   s      r)   rC   z$FrontendHighlighter.rehighlightBlockT   s-     ""# '"r*   c                 F    || j                   z  }t        | 	  |||       y)z1 Reimplemented to highlight selectively.
        N)r   r   	setFormat)r&   startcountformatr(   s       r)   rG   zFrontendHighlighter.setFormat\   s&     	%%%%/r*   N)__name__
__module____qualname____doc__r   r3   r5   r=   rC   rG   __classcell__r(   s   @r)   r   r      s+    

		30#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                 2    t        |      } |       | _        y rK   )r   r   )r&   namerE   newlexer_classs        r)   _lexer_class_changedz#FrontendWidget._lexer_class_changed   s    !#& ]
r*   c                      y)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"23}r*   _CallTipRequestidpos_CompletionRequest)rb   coderc   _ExecutionRequest)rb   kindhidden)
allow_nonec                    t        |   |i | t        | j                        | _        t        | j                        | _        t        j                  dd       | _	        t        | | j                        | _        d | _        d | _        i | _        i | j                  d<   i | _        d| _        d| _        | j'                  d       | j                  j)                  | j*                         | j,                  j/                  | j                  j(                         | j                  }t0        j2                  j4                  t0        j2                  j6                  z  t0        j2                  j8                  z  }|j;                  d       |j=                  t?        j@                  |             |jC                  t0        j2                  jD                         |jF                  j/                  | jH                         | jJ                  j/                  |j:                         | jM                  |       | j                  jO                         }|jP                  j/                  | jR                         || _*        d| _+        y )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}} = -dmm < ) 1 12CT J/DJJG#"(*9% # %%f- 	%%dii0!!$"7"7"?"?@ &&iinnvyy.@% 5--c23!!&))"F"FG  /##F$5$56v ==))+''(F(FG * %*!r*   c                 V     j                   5 j                   j                         r j                   j                          y j                  j                         r j                  j	                         j                         j                         }|rf|j                         ^}} j                  j	                         }|j                  |j                                |j                  |j                         j                         t        j                  j                         |j                         j                         } fd}||z   }t        |      } ||      }|t        |      z
  }	|	t        |      k  r|t        |      |	z
  d }t        |      dkD  r |d   r j                  j	                         }|j                  |j!                                |j                         }
|
j                         }|
j#                         }|j                  |       |j                  ||z   dz
  t        j                  j                         |j                         j                         }t        |      t         ||            z
  }	t        |d         |	k  rd|d<   t%        ||      }dj'                  |g|      }	 |d   dk(  }|r|dd }t*        j,                  j/                         j1                  |       yy j2                  j5                  d	       y# t(        $ r d}Y _w xY w)
zN Copy the currently selected text to the clipboard, removing prompts.
        Nc                 p    j                   j                  |       } 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KD,,AA$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##%]]##%==++-779EEGD9=9J6$ 113""6#8#8#:;""6<<>#:#:#<#(#4#4#?#?A!'!1!1!3!?!?!AH ,.BB
"%j/+J7
,s:>
 N 33!+C,?*,L,M!NJ '!+0C!]]557F&&v':':'<="LLNE % 0I"\\^F&&y1&&y6'9A'=','8'8'C'CE%+%5%5%7%C%C%ENN+n^<=>  ?2./*<.0+ #&no"Fyy*!?!?@("&r(d"2K 9D&&002::4@o r HHNNBC " ("'K(s    L L('L(c                     | j                   j                  ||      }| j                  |d|      | j                  d   |<   |s| j                  j                  |       yy)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  s]    
 ##++FF;040F0FFF1$9%f-NN' r*   c                 @    | j                   sd| j                  _        yy)z= Called immediately after a new prompt is displayed.
        TN_readingrq   r   r]   s    r)   _prompt_started_hookz#FrontendWidget._prompt_started_hook'  s     }}04D- r*   c                 @    | j                   sd| j                  _        yy)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     }}05D- r*   c                     | j                         }|yt        |d| j                          j                               }|xr! | j	                         j                         dk(  }|r| j                          | 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  st     113<T"I4#G#G#IJPPRS LT%5%5%7%D%D%F"%LNN|r*   c                 2   t         |   |      }|j                         D ]s  }|j                         j	                  t
        j                  j                        t
        j                  j                  k(  sV|j                  || j                          |S  |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     w)#.!\\^ 	M%%'//0B0B0H0HI&&112!!-1F1FG	
 r*   c                 >    | j                   r| j                          y y rK   )
_executinginterrupt_kernelr]   s    r)   request_interrupt_kernelz'FrontendWidget.request_interrupt_kernelT  s    ??!!# r*   c                 .    d}| j                  |d       y )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                    |j                         }| j                  |j                         d      r|t        j                  j
                  k(  rg| j                  r[| j                         r:|j                  t        j                  j                        r| j                          y| j                          y|t        j                  j                  k(  r | j                          y|j                         t        j                  j                   z  s|t        j                  j"                  k(  r| j%                         }| j&                  j)                         }|dkD  r|j+                         s| j-                         d| }|j/                  d      rd|j1                         sT|j3                  t        j4                  j6                  t        j4                  j8                  d       |j;                          y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\  su    iik!!%//"3U!Kfiioo%$//==?u}}U5G5G5L5L'MIIK  113		,,,++-"VYY%:%::
 fii---::<11376#6#6#8==?ED}}V,TZZ\++E,=,=,B,B,1,=,=,H,H!M113#w5e<<r*   c                     | j                  |      r0|d   j                  dd      }|rd| _        y| j                          yy)zHandle clear output messages.contentwaitTN)include_outputgetr   clear_output)r&   msgr   s      r)   _handle_clear_outputz#FrontendWidget._handle_clear_output  sB    s#y>%%fd3D,0)!!# $r*   c                     t        t        j                               }| j                  j	                  dd||i      }|| j
                  |<   | j                  |dd      | j                  d   |<   y)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  ss    4 &
##++BJt*= , ?*2J'040F0F*E139%f-r*   c                     |d   j                  d      }|sy|D ]5  }|| j                  v s | j                  j                  |      ||          7 y)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" 	JJT0003##''
3HZ4HI	Jr*   c                 ~   | j                   j                  d|j                  dd             |d   d   }| j                  d   j                  |      }d| _        |r|j
                  ry|j                  d	k(  r| j                  j                  j                         s$| j                  j                  j                          | j                  r| j                  j                          |d   }|d
   }|dk(  r| j                  |       n|dk(  r| j                  |       | j!                  |       | j"                  j%                  |       | j                  d   j'                  |       y|j                  dk(  r0| j)                  |       | j                  d   j'                  |       y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  sz    	*CGGIr,BC_%h/!!),008 t{{99 %%33::<""00668
 $$..0)nGX&F~((-9$++C033C8MMs#y)--f5YY00&&s+y)--f57$))CDDr*   c                 &    | j                  |       y)z  Handle error messages.
        N)_process_execute_errorr&   r   s     r)   _handle_errorzFrontendWidget._handle_error  s     	##C(r*   c                      j                   j                  d|j                  dd             |d   d   } j                  d   j                  |      }|r|j                  rt        d       j                  j                  j                         s$ j                  j                  j                           fd} j                  r" j                   j                  d	       d
 _
         j                  |d   d   ||d   d          y)z( Handle requests for raw_input.
        z	input: %sr   r   r  r   rk   z.Request for raw input during hidden execution.c                 \    j                          j                  j                  |        y rK   )_finalize_input_requestr   inputr   s    r)   r	  z6FrontendWidget._handle_input_request.<locals>.callback   s#    ((*$$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DKKOPP !!//668,,224	+ ==HHNNVW!DMs9~h/(SQZ^\fMghr*   c                 <    |rdnd}| j                  d|z  d       y )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  s+    +/'5H*S0 	 	
r*   c                     | j                   j                  d|       | j                  r| j                  j	                  |       y| j                  d       | j                          y)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  sR     	*,@A++001EF***5JJLr*   c                     | j                   j                  d       | j                  |       | j                  r| j                  j	                          | j                          y)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  sN    
 	+,&&D&1 779

r*   c                    | j                   j                  d|j                  dd             | j                         }| j                  j                  d      }|r}|j
                  |d   d   k(  rg|j                  |j                         k(  rI|d   }|j                  d      dk(  r/|j                  d	d
      r| j                  j                  |       yyyyyy)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DGGs?3H==FOO--)nG{{8$,We1L%%77@ 2M, . >4r*   c                     | j                   j                  d|j                  dd             | j                  |      r/| j	                          |d   d   }| j                  |dz   d       yy)	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  sf     	+SWWY-CDs#""$y>&)D##D4Kt#D $r*   c                     | j                   j                  d|j                  dd             | j                  |      r(| j	                          | j                  |d   d          yy)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;  sW     	|SWWY%;<s#""$s9~f56 $r*   c                    | j                   j                  d|j                  dd             |j                  di       j                  dd      }|d   r5|d   d   }| j                  d   j                  |      }|r|j                  ry	| j                  |      s|r| j                  d
       y	| j                  r| j                  j                  |        y	| j                         j                         }t        j                  j                  | |dt        j                  j                  t        j                  j                         }|t        j                  j                  k(  r| j                  j                  |        y	y	y	)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"--5-9 %%'',,T2 KKM557E%11::4-!--11)2G2G2J2JLE 	 5 5 9 99++006 :% #r*   c                     |d   j                  dd      }|dk(  r | j                  r| j                  d       y	y	|dk(  ry	|dk(  ry	y	)
zHandle status messager   execution_stater   startingTr6  idlebusyN)r   r   r@  )r&   r   states      r)   _handle_statuszFrontendWidget._handle_statusb  sY     I""#4b9J--4-8 f_f_ r*   c                 (    | j                  d       y)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                   j                          y)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                  j                          y| j                  r"d| _        | j                  j                          y| j                  d       y)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  sW       !DM++002  !DM002##$RSr*   c                 l   | j                   rd| _         i | j                  d<   d| _        d| j                  _        |rh| j
                  j                          | j                  rB| j                  | j                         | j                  r| j                  | j                         | j                          y)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)MM!##''4%%++D,>,>? 	%%'r*   c                    | j                   r| j                  j                          y| j                  r| j                  j
                  j                          | j                  rut        j                  j                  t        j                  j                  z  }t        j                  j                  | d||      }|t        j                  j                  k(  }nd}|r1	 | j                  j                  |       | j                  dd       y| j                  j
                  j#                          y| j!                  dd       y# t        $ r }| j!                  d|z  d       Y d}~yd}~ww xY w)	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  sR    ))..0))//1
 ###//33i6K6K6N6NN"..77>O4;WF#y'<'<'@'@@
 "

''6636? %%&J&* &  ""--557 ##;" $  $ ++7!;&* ,  s   E 	E0E++E0c                 *    | j                  |d       y)z"Appends text to the output stream.Tr0  NrJ  )r&   r;   s     r)   rM  zFrontendWidget.append_stream  s    D9r*   c                 L    | j                   rd| _         | j                          yy)z(If a clearoutput is pending, execute it.FN)r   r   r]   s    r)   rI  z FrontendWidget.flush_clearoutput  s$    $$(-D% %r*   c                    | j                   j                         }|j                          |j                  t        j
                  j                  t        j
                  j                         |j                  d       |j                          y)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  se    ))+E--99!--88	:"r*   c                     | j                         }|j                  t        j                  j                         |j                         j                  |j                               dk(  r| j                          yy)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23??(():;sBNN Cr*   c                 P   | j                   r$| j                  j                  j                         sy| j	                         }| j
                  }| j                  j                  ||      }| j                         j                         }| j                  ||      | j                  d<   y)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+K+T+T+V668
  ##++D*= ))+)-)=)=fc)J:&r*   c                     | j                   }| j                         }| j                  j                  ||      }| j	                  |||      }|| j
                  d<   y)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	  s\       668
##,,$:,N&&vtZ@)-:&r*   c                 &    | j                  d       y)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(  r5|d   dk(  xs |d   dk(  }|| _         | j                  j                  |        y	dj                  |d         }| j	                  |       y	)
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  sw     i. 7\) *D0MGH4Ev4MJ(2D%$$T* 45I##I.r*   c                     |d   j                  dg       }|D ]0  }| j                  |      rd}t        |t        |d         z         2 y)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'  sR     i.$$Y3 	6D006HgT(^ 445	6r*   c                      y)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     r*   c                 &    | j                  d       y)z- Shows a prompt for the interpreter.
        z>>> N)_show_promptr]   s    r)   rm  z'FrontendWidget._show_interpreter_prompt8  s     	&!r*   c                 $    | j                          y)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                 r    ||z  }|| j                         j                         k(  r| j                          yy)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  s9    
 	Et'')2244! 5r*   rk  c                 L    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!    .cll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   sG    D!FIM5kO E{!. %[N!.u!5,v}} 4HJO #4HJ 4JLO #$/K#. EE f%I v}}V$H #V]]6*N !2T5MBO#$8$9;"57M/DAL %2 (*\@DL	(56*	$0"=N$3BJ0&EP)
i,
	AE77>T(20d: 	.>
/6"
(" X4 4r*   rS   )rO   collectionsr   r  r  r    qtpyr   r   r   qtconsole.base_frontend_mixinr   	traitletsr   r	   r
   r   r   r   bracket_matcherr   call_tip_widgetr   history_console_widgetr   pygments_highlighterr   utilr   r   rS   r\   r*   r)   <module>r     sV    (
 # 
  	 ) ) ; M M + * 8 5 J0- J0Zr4)+< r4r*   