
_y]c           @   s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 Z	 d d l
 m Z d d l Z d d l m Z m Z d d l m Z d d l m 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 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( d   Z) d   Z* d e d e e e j+  f i   f d     YZ, d S(   s0   An abstract base class for console-type widgets.i(   t   partialN(   t   dedent(   t   category(   t   QtCoret   QtGui(   t   LoggingConfigurable(   t   HtmlExporter(   t   MetaQObjectHasTraitst   get_fontt   superQ(   t	   columnize(   t   Boolt   Enumt   Integert   Unicodei   (   t   QtAnsiCodeProcessor(   t   CompletionWidget(   t   CompletionHtml(   t   CompletionPlain(   t
   QtKillRingc         C   s(   t  |   } | j d  p' | j d  S(   sN    Returns whether the specified unicode character is a letter or a number.
    t   Lt   N(   R   t
   startswith(   t   chart   cat(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   is_letter_or_number   s    c         C   s   t  |   j d  S(   s1   Check whether a given char counts as white space.t   Z(   R   R   (   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   is_whitespace$   s    t   ConsoleWidgett   NewBasec           B   s  e  Z d  Z e e d e d d Z e d d e d d Z e e d e d d Z e	 d d d	 g d e d
 d	 d d Z
 e	 d d g d
 d d e d d Z e	 d d d d d g d
 d d e d d Z e d e d d  Z d   Z e d e d d  Z e d d e d d Z e d d e d d Z e e  Z e Z e Z e j e  Z e j e  Z e j e  Z e j e  Z e j e  j!  Z" e Z# e Z$ e Z% i e j& j' e j& j( 6e j& j) e j& j* 6e j& j+ e j& j, 6e j& j- e j& j. 6e j& j/ e j& j0 6e j& j1 e j& j2 6Z3 e4 j5 d k rHe j& j6 e3 e j& j7 <n  e8 e3 j9    e j& j: e j& j; e j& j< e j& j= h BZ> e Z? e d  Z@ d   ZA d   ZB d   ZC d    ZD d!   ZE e e d e d d" ZF e d# d e d d$ ZG d%   ZH d&   ZI d'   ZJ e d(  ZK d)   ZL d*   ZM d+   ZN d,   ZO e d- d.  ZP d/   ZQ e e e d0  ZR d1   ZS d2   ZT d3   ZU e d4  ZV d5   ZW eX eV eW  ZY d6   ZZ d7   Z[ eX eZ e[  Z\ d8   Z] e  j^ j_ d9  Z` e d:  Za d;   Zb d<   Zc d=   Zd d>   Ze d?   Zf d@   Zg dA   Zh dB   Zi dC   Zj dD   Zk eX ej ek  Zl dE   Zm dF   Zn dG   Zo dH   Zp dI   Zq dJ   Zr dK   Zs dL   Zt e dM  Zu e e dN  Zv e dO  Zw e dP  Zx e dQ  Zy dR   Zz dS   Z{ dT   Z| e dU  Z} dV   Z~ e dW  Z dX   Z dY   Z dZ   Z d[   Z d\   Z d]   Z d^ d_  Z d`   Z da   Z db   Z dc   Z dd   Z de   Z df   Z dg   Z dh   Z di   Z dj   Z dk   Z e dl  Z dm   Z dn   Z eX do    Z eX dp    Z dq   Z dr   Z ds   Z dt   Z e du  Z dv dw  Z e dx  Z dy   Z dz   Z e d{  Z d|   Z e d}  Z d~   Z d   Z e d  Z d   Z d   Z d   Z dv e e d  Z e d  Z d   Z d   Z e e e d  Z d   Z d   Z RS(   s   An abstract base class for console-type widgets. This class has
        functionality for:

            * Maintaining a prompt and editing region
            * Providing the traditional Unix-style console keyboard shortcuts
            * Performing tab completion
            * Paging text
            * Handling ANSI escape codes

        ConsoleWidget also provides a number of utility methods that will be
        convenient to implementors of a console-style widget.
    t   configt   helps%   Whether to process ANSI escape codes.i  s   
        The maximum number of lines of text before truncation. Specifying a
        non-positive number disables text truncation (not recommended).
        s  Whether to automatically execute on syntactically complete input.

        If False, Shift-Enter is required to submit each execution.
        Disabling this is mainly useful for non-Python kernels,
        where the completion check would be wrong.
        t   plaint   droplistt   ncursest   default_valuesP  
                    The type of completer to use. Valid values are:

                    'plain'   : Show the available completion as a text list
                                Below the editing area.
                    'droplist': Show the completion in a drop down list navigable
                                by the arrow keys, and from which you can select
                                completion by pressing Return.
                    'ncurses' : Show the completion as a text list which is navigable by
                                `tab` and arrow keys.
                    t   richs   
        The type of underlying text widget to use. Valid values are 'plain',
        which specifies a QPlainTextEdit, and 'rich', which specifies a
        QTextEdit.
        t   insidet   hsplitt   vsplitt   customt   nones\  
        The type of paging to use. Valid values are:

        'inside'
           The widget pages like a traditional terminal.
        'hsplit'
           When paging is requested, the widget is split horizontally. The top
           pane contains the console, and the bottom pane contains the paged text.
        'vsplit'
           Similar to 'hsplit', except that a vertical splitter is used.
        'custom'
           No action is taken by the widget beyond emitting a
           'custom_page_requested(str)' signal.
        'none'
           The text is written directly to the console.
        s   The font family to use for the console.
        On OSX this defaults to Monaco, on Windows the default is
        Consolas with fallback of Courier, and on other platforms
        the default is Monospace.
        c         C   s.   t  j d k r d St  j d k r& d Sd Sd  S(   Nt   win32t   Consolast   darwint   Monacot	   Monospace(   t   syst   platform(   t   self(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _font_family_default}   s
    s`   The font size. If unconfigured, Qt will be entrusted
        with the size of the font.
        iQ   sr   The width of the console at start time in number
        of characters (will double with `hsplit` paging)
        i   ss   The height of the console at start time in number
        of characters (will double with `vsplit` paging)
        R,   c         K   s  t  t |   j |   | r, |  j |  n  d  |  _ t j j g |  _	 t
 t j d  rr |  j	 j t j j  n  t j |   } | j d d d d  |  j   |  _ |  j d! k r(t j   |  _ |  j d k r |  j j t j j  n |  j j t j j  |  j j |  j  | j |  j  n | j |  j  |  j d" k r|  j   |  _ |  j r|  j j   |  j j |  j  q| j |  j  n  |  j j   |  _ t   |  _  |  j! d k rt" |   |  _# nB |  j! d k rt$ |   |  _# n! |  j! d k rt% |   |  _# n  d	 |  _& d  |  _' t( |  _) t( |  _* t+ |  j  |  _, d
 |  _- d
 |  _. t/ |  j  |  _0 d
 |  _1 d  |  _2 |  j j   |  _3 d
 |  _4 t( |  _5 d  |  _6 d |  _7 g  |  _8 t j9 |  j  |  _: |  j: j; d  |  j: j< t=  |  j: j> j? |  j@  |  jA   t jB d d   } | jC t=  t jD t jD jE  } | jF d  rqtG jH d k rqd } n  | jI |  | jJ t j jK  | jL j? |  jM  |  jN |  | |  _O t jB d d   } | jI t jD jP  | jJ t j jK  | jL j? |  jQ  |  jN |  | |  _R t jB d d   } | jC t=  t jD t jD jS  } | jF d  rvtG jH d k rvd } n  | jI |  | jJ t j jK  | jL j? |  jT  |  jN |  | |  _U t jB d |  d t jD jV d t j jK d d d |  jW |  _X |  jN |  jX  t jB d |  d t jD jY d t j jK d d d |  jZ |  _[ |  jN |  j[  t jB d |  d d d t j jK d d d |  jA |  _\ |  jN |  j\  |  j] t=  d  S(#   s    Create a ConsoleWidget.

        Parameters
        ----------
        parent : QWidget, optional [default None]
            The parent for this widget.
        t   NativeGesturei    R&   R'   R%   R"   R!   R    s   > t    i   id   t   Prints   Ctrl+PR,   s   Ctrl+Shift+Ps   Save as HTML/XMLs
   Select Alls   Ctrl+As   Ctrl+Shift+As   Bigger Fontt   shortcutt   shortcutContextt	   statusTips#   Increase the font size by one pointt	   triggereds   Smaller Fonts#   Decrease the font size by one points   Normal Fonts   Ctrl+0s   Restore the Normal font sizeN(   R&   R'   (   R%   R&   R'   (^   t   superR   t   __init__t	   setParentt   Nonet   _is_complete_msg_idR   t   QEventt   Wheelt   _pager_scroll_eventst   hasattrt   appendR3   R   t   QStackedLayoutt   setContentsMarginst   _create_controlt   _controlt   pagingt	   QSplittert	   _splittert   setOrientationt   Qtt
   Horizontalt   Verticalt	   addWidgett   _create_page_controlt   _page_controlt   hidet
   textCursort   _append_before_prompt_cursorR   t   _ansi_processort   gui_completionR   t   _completion_widgetR   R   t   _continuation_promptt   _continuation_prompt_htmlt   Falset
   _executingt   _filter_resizeR   t   _html_exportert   _input_buffer_executingt   _input_buffer_pendingR   t
   _kill_ringt   _promptt   _prompt_htmlt   _prompt_cursort   _prompt_sept   _readingt   _reading_callbackt
   _tab_widtht   _pending_insert_textt   QTimert   _pending_text_flush_intervalt   setIntervalt   setSingleShott   Truet   timeoutt   connectt   _on_flush_pending_stream_timert
   reset_fontt   QActiont
   setEnabledt   QKeySequenceR5   t   matchesR/   R0   t   setShortcutt   setShortcutContextt   WidgetWithChildrenShortcutR9   t   print_t	   addActiont   print_actiont   Savet   export_htmlt   export_actiont	   SelectAllt   select_all_smartt   select_all_actiont   ZoomInt   _increase_font_sizet   increase_font_sizet   ZoomOutt   _decrease_font_sizet   decrease_font_sizet   reset_font_sizet   setAcceptDrops(   R1   t   parentt   kwt   layoutt   actiont   printkeyt	   selectall(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR;      s    															

								c         C   sh   | j    j   r2 | j t j j  | j   n2 | j    j   rd | j t j j  | j   n  d  S(   N(	   t   mimeDatat   hasUrlst   setDropActionR   RL   t
   LinkActiont   acceptt   hasTextt
   CopyAction(   R1   t   e(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   dragEnterEventl  s    c         C   s   | j    j   r n | j    j   r |  j j | j    } |  j | j    rz | j t	 j
 j  |  j j |  n | j t	 j
 j  | j   n  d  S(   N(   R   R   R   RG   t   cursorForPositiont   post
   _in_buffert   positionR   R   RL   R   t   setTextCursort   IgnoreActionR   (   R1   R   t   cursor(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   dragMoveEventx  s    c         C   s   | j    j   r |  j   |  j j   } g  | j    j   D] } | j   ^ q> } d j d   | D  } |  j | |  ng | j    j	   r |  j j
 | j    } |  j | j    r | j    j   } |  j | |  q n  d  S(   Ns   , c         s   s)   |  ] } d  | j  d  d  d  Vq d S(   t   's   '"'"'N(   t   replace(   t   .0t   f(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pys	   <genexpr>  s   (   R   R   t   _keep_cursor_in_bufferRG   RS   t   urlst   toLocalFilet   joint   _insert_plain_text_into_bufferR   R   R   R   R   t   text(   R1   R   R   t   urlt	   filenamesR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt	   dropEvent  s    
+c         C   s  | j    } |  j   | t j j k r | j   } |  j | j    r | |  j k r t	 j
 t j j |  j | t j j  } t	 j j | |  t S| |  j k r |  j |  S| |  j k rl|  j |  Sn| t j j k rP| j   t j j k rP| |  j j   k rP|  j j | j    } |  j j |  |  j t	 j j  t S| t j j k r|  j rt |  _ t	 j  j!   j | |  |  j"   t# |  _ t S| t j j$ k r|  j% r|  j | j    r| j   |  j& k r| j'   nu | |  j( k r&| |  j k r&|  j j)   t S| t j j* k rl|  j j+ | j    } t	 j, j- | j.   |  n  t/ t0 |   j1 | |  S(   se    Reimplemented to ensure a console-like behavior in the underlying
            text widgets.
        (2   t   typet   _trigger_is_complete_callbackR   R?   t   KeyPresst   keyt   _control_key_downt	   modifierst   _ctrl_down_remapR   t	   QKeyEventRL   t
   NoModifiert   qAppt	   sendEventRm   RG   t   _event_filter_console_keypressRQ   t   _event_filter_page_keypresst   MouseButtonReleaset   buttont	   MidButtont   viewportR   R   R   t   pastet
   QClipboardt	   Selectiont   ResizeR\   t   QApplicationt   instancet   _adjust_scrollbarsRZ   t   ShortcutOverridet   override_shortcutst
   _shortcutsR   RA   t   repaintt	   MouseMovet   anchorAtt   QToolTipt   showTextt	   globalPosR:   R   t   eventFilter(   R1   t   objt   eventt   etypeR   t	   new_eventR   t   anchor(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR     sR    

	
		c         C   s   t  j |  j  } |  j j   |  j j   j   d } |  j   } | j t  j	 j
  } | j d  |  j | } | | j t  j	 j  7} |  j d k r | d | } n  | j   |  j | } |  j d k r | d | } n  t j t |  t |   S(   sc    Reimplemented to suggest a size that is 80 characters wide and
            25 lines high.
        i   t    R&   R'   (   R   t   QFontMetricst   fontRG   t
   frameWidtht   documentt   documentMargint   stylet   pixelMetrict   QStylet   PM_SplitterWidtht   widtht   console_widtht   PM_ScrollBarExtentRH   t   heightt   console_heightR   t   QSizet   int(   R1   t   font_metricst   marginR   t
   splitwidthR   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   sizeHint  s    s   Whether to include output from clients
        other than this one sharing the same kernel.

        Outputs are not displayed until enter is pressed.
        s	   [remote] s   Prefix to add to outputs coming from clients other than this one.

        Only relevant if include_other_output is True.
        c         C   s   |  j  j   j   S(   s>    Returns whether text can be copied to the clipboard.
        (   RG   RS   t   hasSelection(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   can_copy  s    c         C   sC   |  j  j   } | j   oB |  j | j    oB |  j | j    S(   s;    Returns whether text can be cut to the clipboard.
        (   RG   RS   R   R   R   R   (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   can_cut  s    c         C   s6   |  j  j   t j j @r2 t t j j   j	    St
 S(   s@    Returns whether text can be pasted from the clipboard.
        (   RG   t   textInteractionFlagsR   RL   t   TextEditablet   boolR   R   t	   clipboardR   RZ   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt	   can_paste  s    c         C   sX   |  j  r |  j j   n; | r+ |  j } n  |  j j   |  j   | rT | |  _ n  d S(   s    Clear the console.

        Parameters
        ----------
        keep_input : bool, optional (default True)
            If set, restores the old input buffer if a new prompt is written.
        N(   R[   RG   t   cleart   input_buffert   _show_prompt(   R1   t
   keep_inputR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR     s    	
c         C   s   |  j    j   j   d S(   s<    Copy the currently selected text to the clipboard.
        N(   R   t   currentWidgett   copy(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   (  s    c         C   s   t  j j   j |  d S(   s+    Copy anchor text to the clipboard
        N(   R   R   R   t   setText(   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   copy_anchor-  s    c         C   s0   |  j    |  j   r, |  j j   j   n  d S(   sv    Copy the currently selected text to the clipboard and delete it
            if it's inside the input buffer.
        N(   R   R   RG   RS   t   removeSelectedText(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   cut2  s    
c         C   si   | d j  d d  |  j k r# d  S| d j  d d  } | d j  d d  } |  j | d	 k |  d  S(
   Nt   parent_headert   msg_idi    t   contentt   statusu   completet   indentu    t
   incomplete(   t   getR>   R   (   R1   t   msgR   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _handle_is_complete_reply:  s
    u    c         C   s/   |  j  d  k	 r+ d  |  _  |  j | |  n  d  S(   N(   R>   R=   t   _is_complete_callback(   R1   t   completeR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   A  s    	c         C   s,   |  j    |  j j |  |  _ | |  _ d  S(   N(   R   t   kernel_clientt   is_completeR>   R  (   R1   t   sourcet   callback(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _register_is_complete_callbackF  s    
c         C   s   | d k r |  j } n | s* | |  _ n  | rC |  j | |  nA | rq |  j rq |  j | t |  j |   n |  j | t d  d S(   s|   Executes source or the input buffer, possibly prompting for more
        input.

        Parameters
        ----------
        source : str, optional

            The source to execute. If not specified, the input buffer will be
            used. If specified and 'hidden' is False, the input buffer will be
            replaced with the source before execution.

        hidden : bool, optional (default False)

            If set, no output will be shown and the prompt will not be modified.
            In other words, it will be completely invisible to the user that
            an execution has occurred.

        interactive : bool, optional (default False)

            Whether the console is to treat the source as having been manually
            entered by the user. The effect of this parameter depends on the
            subclass implementation.

        Raises
        ------
        RuntimeError
            If incomplete input is given and 'hidden' is True. In this case,
            it is not possible to prompt for more input.

        Returns
        -------
        A boolean indicating whether the source was executed.
        R4   N(   R=   R   t   _executet   execute_on_complete_inputR  R    t
   do_executeRm   (   R1   R	  t   hiddent   interactive(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   executeK  s    'c         C   s   | rE |  j  d  |  j |  _ t |  _ |  j   |  j | t  n[ |  j   } | j	   z! | j
 d  |  j | |  Wd  | j   X|  j j t j j  d  S(   Ns   
(   t   _append_plain_textR   R^   Rm   R[   t   _finalize_input_requestR  RZ   t   _get_end_cursort   beginEditBlockt
   insertTextt   _insert_continuation_promptt   endEditBlockRG   t
   moveCursorR   t   QTextCursort   End(   R1   R	  R  R   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    	

c         C   s   |  j  j   d S(   s?    Shows a dialog to export HTML/XML in various formats.
        N(   R]   t   export(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR}     s    c         C   s\   t  |  _ |  j   |  j j |  j   j    |  j j   j	 |  j
  |  j j t   d S(   s8   
        Set the widget to a non-reading state.
        N(   RZ   Re   t   _prompt_finishedRT   t   setPositionR  R   RG   R   t   setMaximumBlockCountt   buffer_sizet   setUndoRedoEnabled(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    	
	c         C   se   |  j  r | r |  j S|  j   } | j |  j t j j  | j   j	   } | j
 d |  j d  S(   s    The text that the user has entered entered at the current prompt.

        If the console is currently executing, the text that is executing will
        always be returned.
        s   
(   R[   R^   R  R  t   _prompt_posR   R  t
   KeepAnchort	   selectiont   toPlainTextR   RX   (   R1   t   forceR   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_input_buffer  s    c         C   s   |  j  r | |  _ d S|  j   } | j   | j |  j t j j  | j	   |  j
 |  j   |  | j   |  j j t j j  d S(   s    Sets the text in the input buffer.

        If the console is currently executing, this call has no *immediate*
        effect. When the execution is finished, the input buffer will be updated
        appropriately.
        N(   R[   R_   R  R  R  R"  R   R  R#  R   R   t   _get_prompt_cursorR  RG   R  R  (   R1   t   stringR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _set_input_buffer  s    		


c         C   s   |  j  j   j   S(   s8    The base font being used by the ConsoleWidget.
        (   RG   R   t   defaultFont(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt	   _get_font  s    c         C   s   t  j |  } |  j j |  j | j d   |  j j |  |  j j   j	 |  |  j
 rw |  j
 j   j	 |  n  |  j j |  d S(   sJ    Sets the base font for the ConsoleWidget to the specified QFont.
        R   N(   R   R   RG   t   setTabStopWidtht	   tab_widthR   RW   t   setFontR   t   setDefaultFontRQ   t   font_changedt   emit(   R1   R   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt	   _set_font  s     	c         C   s   t  j |  d S(   s8    Open selected anchor in the default webbrowser
        N(   t
   webbrowsert   open(   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   open_anchor  s    c         C   s   |  j  j   t j j @r |  j   |  j  j   } t j j	   j
 |  j   } | j   |  j   } | j d |  r | | } n  |  j | t |   n  d S(   s   Paste the contents of the clipboard into the input region.

        Parameters
        ----------
        mode : QClipboard::Mode, optional [default QClipboard::Clipboard]

            Controls which part of the system clipboard is used. This can be
            used to access the selection clipboard in X11 and the Find buffer
            in Mac OS. By default, the regular clipboard is used.
        R   N(   RG   R   R   RL   R   R   RS   R   R   R   R   t   rstripR   t   _get_line_start_posR   R   R   (   R1   t   modeR   R   t   cursor_offset(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR     s    
c         C   sN   | s: t  j   } t  j |  j   t  j j k r: d Sn  |  j j |  d S(   sL    Print the contents of the ConsoleWidget to the specified QPrinter.
        N(   R   t   QPrintert   QPrintDialogt   exec_t   QDialogt   AcceptedRG   Ry   (   R1   t   printer(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRy     s
    !c         C   sW   |  j  sS |  j   } |  j   j   | j   k  rC |  j |  n  |  j |  n  d S(   s6    Moves the prompt to the top of the viewport.
        N(   R[   R(  t   _get_cursort   blockNumbert   _set_cursort   _set_top_cursor(   R1   t   prompt_cursor(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   prompt_to_top  s
    	c         C   s   |  j  j   d S(   sa    Redo the last operation. If there is no operation to redo, nothing
            happens.
        N(   RG   t   redo(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRG  (  s    c         C   s   t  j d k r d } n t  j d k r0 d } n d } t |  j |  } |  j rd | j |  j  n" | j t j j   j	   j
    | j t j j  |  j |  d S(   sJ    Sets the font to the default fixed-width font for this platform.
        R*   t   CourierR,   R-   R.   N(   R/   R0   R   t   font_familyt	   font_sizet   setPointSizeR   R   R   R   t	   pointSizet   setStyleHintt   QFontt
   TypeWriterR3  (   R1   t   fallbackR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRq   .  s    			"c         C   s@   |  j  } t | j   | d  } | j |  |  j |  d S(   sB   Change the font size by the specified amount (in points).
        i   N(   R   t   maxRL  RK  R3  (   R1   t   deltaR   t   size(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   change_font_sizeB  s    	c         C   s   |  j  d  d  S(   Ni   (   RT  (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   J  s    c         C   s   |  j  d  d  S(   Ni(   RT  (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   M  s    c         C   s   |  j    } | j   | j   f } | j   | j |  j   j    | j |  j   d t j	 j
 | j   | j   f } | | k r |  j   n |  j j |  d S(   sK    Select current cell, or, if already selected, the whole document.
        R9  N(   RA  t   selectionStartt   selectionEndt   clearSelectionR  R(  R   t   _get_end_posR   R  R#  t   select_documentRG   R   (   R1   t   ct	   sel_ranget   new_sel_range(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   P  s    
c         C   s   |  j  j   d S(   s-    Selects all the text in the buffer.
        N(   RG   t	   selectAll(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRY  b  s    c         C   s   |  j  S(   sF    The width (in terms of space characters) for tab characters.
        (   Rg   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_tab_widthg  s    c         C   s<   t  j |  j  } |  j j | | j d   | |  _ d S(   sK    Sets the width (in terms of space characters) for tab characters.
        R   N(   R   R   R   RG   R-  R   Rg   (   R1   R.  R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _set_tab_widthl  s    c         C   s   |  j  j   d S(   sa    Undo the last operation. If there is no operation to undo, nothing
            happens.
        N(   RG   t   undo(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR`  v  s    c         C   s
   t   d S(   s    Returns whether 'source' can be executed. When triggered by an
            Enter/Return key press, 'interactive' is True; otherwise, it is
            False.
        N(   t   NotImplementedError(   R1   R	  R  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _is_complete  s    c         C   s
   t   d S(   s@    Execute 'source'. If 'hidden', do not show any output.
        N(   Ra  (   R1   R	  R  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   s   d S(   s=    Called immediately after a new prompt is displayed.
        N(    (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _prompt_started_hook  s    c         C   s   d S(   s    Called immediately after a prompt is finished, i.e. when some input
            will be processed and a new prompt displayed.
        N(    (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _prompt_finished_hook  s    c         C   s   t  S(   sj    Called when the up key is pressed. Returns whether to continue
            processing the event.
        (   Rm   (   R1   t   shift_modifier(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _up_pressed  s    c         C   s   t  S(   sl    Called when the down key is pressed. Returns whether to continue
            processing the event.
        (   Rm   (   R1   Re  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _down_pressed  s    c         C   s   t  S(   sk    Called when the tab key is pressed. Returns whether to continue
            processing the event.
        (   Rm   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _tab_pressed  s    c         O   s   |  j  j   } | rE |  j s( |  j rE |  j   | j |  j  n/ | |  j k ra |  j   n  | j t	 j
 j  | | | | |  } | S(   s    A low-level method for appending content to the end of the buffer.

        If 'before_prompt' is enabled, the content will be inserted before the
        current prompt, if there is one.
        (   RG   RS   Re   R[   t   _flush_pending_streamR  t   _append_before_prompt_post   _insert_plain_textt   movePositionR   R  R  (   R1   t   insertt   inputt   before_promptt   argst   kwargsR   t   result(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _append_custom  s    
c         C   s   |  j  |  j | |  d S(   sE    Appends an new QTextBlock to the end of the console buffer.
        N(   Rs  t   _insert_block(   R1   t   block_formatRo  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _append_block  s    c         C   s   |  j  |  j | |  d S(   s8    Appends HTML at the end of the console buffer.
        N(   Rs  t   _insert_html(   R1   t   htmlRo  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _append_html  s    c         C   s   |  j  |  j | |  S(   sB    Appends HTML, then returns the plain text version of it.
        (   Rs  t    _insert_html_fetching_plain_text(   R1   Rx  Ro  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt    _append_html_fetching_plain_text  s    c         C   s   |  j  |  j | |  d S(   s?    Appends plain text, processing ANSI codes if enabled.
        N(   Rs  Rk  (   R1   R   Ro  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   s   |  j  j   d S(   s4    If text completion is progress, cancel it.
        N(   RW   t   cancel_completion(   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _cancel_completion  s    c         C   s  |  j    } |  j j   } |  j r t |  _ xm | j t j j  r t j |  } | j	 t j j
  | j   j   j   } | j |  s0 Pq0 q0 Wn d S| j t j j  | j t j j t j j  | j   |  j j   r|  j j t  |  j j t  n  d S(   sh    Clears the "temporary text" buffer, i.e. all the text following
            the prompt region.
        N(   R(  RX   t   lstript   _temp_buffer_filledRZ   Rl  R   R  t	   NextBlockt   selectt   BlockUnderCursorR$  R%  R   t   LeftR  R#  R   RG   t   isUndoRedoEnabledR!  Rm   (   R1   R   t   promptt   temp_cursorR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _clear_temporary_buffer  s$    		
c         C   s   |  j    t |  d k rU | j |  j j   j   t j j  | j	 | d  n t |  d k r |  j j   j   } t
 j j |  } | r | j | t j j  | j	 |  | j   } n  |  j j | | d t |  n  d S(   sL    Performs completion with 'items' at the specified cursor location.
        i   i    t   prefix_lengthN(   R}  t   lenR  RG   RS   R   R   R  R#  R  t   ost   patht   commonprefixRW   t
   show_items(   R1   R   t   itemst   current_post   prefix(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _complete_with_items  s    
c         C   s   |  j  j   j   } | j   |  j d  |  j | d | | j   | j |  |  j  j t	 j
 j  |  j  j |  t |  _ d S(   s6   fill the area below the active editting zone with texts   
Rx  N(   RG   RS   R   R  R  t   _pageR  R  R  R   R  R  R   Rm   R  (   R1   R   R   Rx  R  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _fill_temporary_buffer  s    

c            s  t  j   } | j d  j   _  j j  j     j j t  j j	  | j d  j
   _  j j  j     j j t  j j  | j d  j   _  j j  j     j j t  j j   j j |      rB| j   | j d    f d     _ | j d    f d     _ n  | j   | j  j  | j   | j  j  | j  j  | S(   sN    Creates a context menu for the given QPoint (in widget coordinates).
        t   Cutt   Copyt   Pastes   Copy Link Addressc              s    j  d    S(   NR   (   R   (    (   R   R1   (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   <lambda>5  R4   s	   Open Linkc              s    j  d    S(   NR   (   R6  (    (   R   R1   (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  7  R4   (   R   t   QMenuRz   R   t
   cut_actionRs   R   Rv   Rt   R  R   t   copy_actionR   R  R   t   paste_actionR   R  RG   R   t   addSeparatort   copy_link_actiont   open_link_actionR   R~   R{   (   R1   R   t   menu(    (   R   R1   s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _context_menu_make   s.    


c         C   s[   t  j d k rC | o" | t j j @} t |  t | t j j @ ASt | t j j @ Sd S(   s7   Given a KeyboardModifiers flags object, return whether the Control
        key is down.

        Parameters
        ----------
        include_command : bool, optional (default True)
            Whether to treat the Command key as a (mutually exclusive) synonym
            for Control when in Mac OS.
        R,   N(   R/   R0   R   RL   t   ControlModifierR   t   MetaModifier(   R1   R   t   include_commandt   down(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   B  s    c         C   ss  |  j  r |  j    } nV |  j d k r6 t j   } n8 |  j d k rn t j   } | j t  | j t  n  | j	 t  | j
 |   | j   j
 |   | j j |  j  | j j |  j  | j j |  j  | j j |  j  | j   j   } | j j   | j j |  j  | j t j j t  | j t j j  | j  t  | j! t  | j" t j j#  | S(   s:    Creates and connects the underlying text widget.
        R    R$   ($   t   custom_controlt   kindR   t   QPlainTextEditt	   QTextEditt   setAcceptRichTextRZ   t   setMouseTrackingRm   R   t   installEventFilterR   t   customContextMenuRequestedRo   t   _custom_context_menu_requestedt   copyAvailablet   copy_availablet   redoAvailablet   redo_availablet   undoAvailablet   undo_availableR   t   documentLayoutt   documentSizeChangedt
   disconnectR   t   setAttributeR   RL   t   WA_InputMethodEnabledt   setContextMenuPolicyt   CustomContextMenut   setReadOnlyR!  t   setVerticalScrollBarPolicyt   ScrollBarAlwaysOn(   R1   t   controlR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRF   T  s2    		
c         C   s   |  j  r |  j    } n< |  j d k r6 t j   } n |  j d k rT t j   } n  | j |   | j   } | j |   | j t  | j	 t
  | j t j j  | S(   s<    Creates and connects the underlying paging widget.
        R    R$   (   t   custom_page_controlR  R   R  R  R  R   R  Rm   R!  RZ   R  R   RL   R  (   R1   R  R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRP     s    	c            s  t  }  j j       j    | j   }  j | j    } | j   t j j	 @} | j   t j j
 @} | t j j t j j f k rt }  j    j   r j r  j d  t   _  j r j   qq j s  j t j j t j j  t   j   j    d k }  j   j    j   j   k } | s\| s\| rw| rw j d |  q j    }	     f d   }
  j!  j"   |	  |
  qqn| r| t j j# k r j$   t } q| t j j% k r j   r  j&     j t j j' t j j    j(   s  j t j j) t j j    j t j j* t j j t  j+   n   j, j-     j.    n  t } q| t j j/ k r j0   t } q| t j j1 k r j2 r j2 j3   r j2 j4   n  t } q| t j j5 k r j   r  j&     j   } |  j   j   k rrt  j6  } n t  j+  }   j t j j7 t j j    j t j j* t j j |   j, j-     j.    n  t } q| t j j8 k r j9    j, j:   t } q| t j j; t j j< f k r| t j j; k rY j=     n  j>       j?  t j j   j, j-    t } q| t j j@ k rt  jA  d k r j r jB jC   qt  j" d t   d k r[ j j   jD tE d   t jF t jG jH t j j t j jI  } t jJ jK  j |  t } qt jF t jG jH t j j< t j jI  } t jJ jK  j |  t } qn3| rT| t j jL k r j.  j=    t } q| t j jM k r j.  j>    t } q| t j j8 k r4 j, jN   t } q| t j j; k r j=       j?  t j j   j, j-    t } q| t j j@ k r j>       j?  t j j   j, j-    t } q| t j j< k rt } q| t j jO k r  j jP t j j  t } q| t j jQ k r j jR  j    t } qn| rit j j } n t j jS } | t j jT k r j$   t } n=| t j jU k r j s jV |  rt } q j   j   }   j   | k } n| t j jW k rP j s  jX |  r)t } q j   j   }   j   | k } n| t j jY k r j s jZ   r j[ d t   n  t } qnA| t j j\ k r j[ d t  t } n| t j j] k rq	  j     j^   } } |  j   j   k rZ	| t  j+  k rZ	 j jP t j j_ d |  j jP t j j` d | t } q j  d	  } nf| t j ja k r
  jb   k r	  j t j j) d |   j t j j* d | d
 t  j+   j jR    n  j jP t j j* d | t } n| t j jc k r jd   }  je   }  jf   } | j   | | k su
| j^   t  j+  k r
| | 7} n  | r
 j   r
| j   r
tg | jh   | ji    }   j? | t j jS  n    j? | t j j  n   j? |   j.    t } n| t j j; k r  j     j^   } }  j r| t  j+  k r|  j   j   k r  jj     j t j j7 t j j    jk     jl     jm   t } q  jn   } |  k r j  d	  } q j to |    } n | t j j< k r j r j   r  jp   r  j(   r  j t j j) t j j    j t j j* t j j t  j+     jk   t } q  jn   }  j |  p j   } n  | sX| jq t jr js  r jt   t } qX| jq t jr ju  r- jv   t } qX| jq t jr jw  rX jx   t } qXn   j | j   d t p| t j jy t j jz f k p j o j s j9   n  | S(   sj    Filter key events for the underlying text widget to create a
            console-like interface.
        s   
i    R  c            s   zK   j      j     j d   j    | rJ   j |  n  Wd    j   X j j t j j	   j j
    d  S(   Ns   
(   R  R  R  R  R  RG   R  R   R  R  R   (   R  R   (   R   R   R1   (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR
    s    
R&  i   R   R9  i   t   nR  ({   RZ   RG   RS   R   R   R   R   R   RL   t   AltModifiert   ShiftModifiert
   Key_Returnt	   Key_EnterRm   R}  R   Re   R  Rf   R[   Rl  R   R  R  R#  R  t   selectedTextt   stripR  RB  R(  R  t   _get_input_buffer_cursor_posR  R'  t   Key_Gt   _keyboard_quitt   Key_KRW  t	   EndOfLineR   R  t   RightRX   R`   t   kill_cursorRC  t   Key_LRF  t   Key_ORQ   t	   isVisiblet   setFocust   Key_URa   t   StartOfBlockt   Key_YR   t   yankt   Key_Backspacet
   Key_Deletet   _get_word_start_cursort   _get_word_end_cursorR  t   Key_DR   t   exit_requestedR2  R  t   chrR   R?   R   R   R   R   t   Key_Bt   Key_Ft   rotatet   Key_GreaterR  t   Key_LessR   t
   MoveAnchort
   Key_Escapet   Key_UpRf  t   Key_DownRg  t   Key_TabRh  t   _indentt   Key_Backtabt   Key_Leftt   columnNumbert   PreviousBlockt
   EndOfBlockt	   Key_Rightt   _get_line_end_post   Key_HomeR8  RA  t   _get_leading_spacesRQ  RU  RV  R  R   t   deletePreviousCharR  R   t   mint
   atBlockEndRu   Rt   R  R   R  R   R  R   t
   Key_PageUpt   Key_PageDown(   R1   R   t   interceptedR   t	   ctrl_downt   alt_downt
   shift_downt   at_endt   single_lineR   R
  t
   start_linet   offsetR   t
   anchormodet   prompt_linet   end_linet   linet   colt	   start_posRZ  t   spacest   sel_maxR   (    (   R   R   R1   s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR     s   
				
	
		
		
	
												
									




		
	
	
	
c         C   s  | j    } |  j | j    } | j   t j j @} | rc | t j j k r|  j j   t	 Sn9| r | t j j
 k r |  j j t j j  t	 S| t j j k r|  j j t j j  t	 Sn| t j j t j j f k r;|  j r|  j j   |  j j   n/ |  j   j |  j  |  j j   j |  j  t	 S| t j j t j j t j j f k rt j t j j  t j j! t j j"  } t j# j$ |  j |  t	 S| t j j% k rt j t j j  t j j& t j j"  } t j# j$ |  j |  t	 S| t j j' k rIt j t j j  t j j( t j j"  } t j# j$ |  j |  t	 S| t j j) k rt j t j j  t j j* t j j"  } t j# j$ |  j |  t	 St+ S(   s_    Filter key events for the paging widget to create console-like
            interface.
        (,   R   R   R   R   RL   R  R  RG   R  Rm   R  RQ   R  R   R  R  R  t   Startt   Key_QR  RJ   RR   R   t   setCurrentWidgetR   R  R   R  R  R  R   R?   R   R  R   R   R   R  R  t   Key_JR  R  R  RZ   (   R1   R   R   R  R  R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR     s^    					c         C   sC   |  j  j   } | j t j j  |  j   | j t j j  d S(   s_    Flush the pending stream output and change the
        prompt position appropriately.
        N(   RG   RS   Rl  R   R  R  Ri  (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRp   !  s    
c         C   s   |  j  } g  |  _  |  j j   j   } | d k rH |  j | |  } n  d j |  } t j   } |  j |  j   | d t	 |  j
 j t d t j   | d   d S(   s)    Flush out pending text into the widget. i    R4   t   flushid   i  N(   Rh   RG   R   t   maximumBlockCountt   _get_last_lines_from_listR   t   timeRk  R  Rm   Rj   Rk   RQ  (   R1   R   R   t   t(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRi  *  s    		s     c         C   sW   |  j  j   j   } t j |  j  j d  } t d | | d  } t | | |  S(   s`   Transform a list of strings into a single string with columns.

        Parameters
        ----------
        items : sequence of strings
            The strings to process.

        separator : str, optional [default is two spaces]
            The string that separates columns.

        Returns
        -------
        The formatted string.
        R   i
   i   (	   RG   R   t	   textWidthR   R   R   R   RQ  R
   (   R1   R  t	   separatorR   t
   char_widtht   displaywidth(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _format_as_columns8  s    c         C   sN   t  j |  } | j t  j j  | j t  j j t  j j  | j   j   S(   s:    Given a QTextBlock, return its unformatted text.
        (   R   R  Rl  R  R  R#  R$  R%  (   R1   t   blockR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_block_plain_textN  s
    c         C   s   |  j  j   S(   s6    Get a cursor at the current insert position.
        (   RG   RS   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRA  W  s    c         C   s&   |  j  j   } | j t j j  | S(   sA    Get a cursor at the last character of the current cell.
        (   RG   RS   Rl  R   R  R  (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  \  s    c         C   s   |  j    j   S(   sE    Get the position of the last character of the current cell.
        (   R  R   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRX  c  s    c         C   s}   |  j  j   } | j   } | |  j   j   k rF | j |  j  n3 | j t j j	  | j | j
   t |  j   | S(   sB    Get a cursor at the first character of the current line.
        (   RG   RS   RB  R(  R  R"  Rl  R   R  t   StartOfLineR   R  RX   (   R1   R   R  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_line_start_cursorh  s    c         C   s   |  j    j   S(   sF    Get the position of the first character of the current line.
        (   R  R   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR8  u  s    c         C   s&   |  j  j   } | j t j j  | S(   sA    Get a cursor at the last character of the current line.
        (   RG   RS   Rl  R   R  R  (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_line_end_cursorz  s    c         C   s   |  j    j   S(   sE    Get the position of the last character of the current line.
        (   R  R   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   sC   |  j    } | d k r d S|  j j   } | j   t |  Sd S(   s    Get the column of the cursor in the input buffer, excluding the
            contribution by the prompt, or -1 if there is no such column.
        iN(   t   _get_input_buffer_cursor_promptR=   RG   RS   R  R  (   R1   R  R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_input_buffer_cursor_column  s
    c         C   sR   |  j    } | d k r d S|  j j   } |  j | j    } | t |  Sd S(   s~    Get the text of the line of the input buffer that contains the
            cursor, or None if there is no such line.
        N(   R  R=   RG   RS   R  R  R  (   R1   R  R   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_input_buffer_cursor_line  s    c         C   sW   |  j  j   } | j |  j t j j  | j   j   } t	 | j
 d |  j d   S(   s0   Get the cursor position within the input buffer.s   
(   RG   RS   R  R"  R   R  R#  R$  R%  R  R   RX   (   R1   R   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   sh   |  j  r d S|  j j   } | j   |  j k r` | j   |  j   j   k rV |  j S|  j	 Sn d Sd S(   s    Returns the (plain text) prompt for line of the input buffer that
            contains the cursor, or None if there is no such line.
        N(
   R[   R=   RG   RS   R   R"  RB  R(  Ra   RX   (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    	
c         C   s   t  |  } | | k  rD | r= | | r6 | j d  n | f S| Sn  d } xE | | k  r | j d d |  } | d k r d } Pn  | d 7} qM W| r | | | f S| | Sd S(   s    Get the last specified number of lines of text (like `tail -n`).
        If return_count is True, returns a tuple of clipped text and the
        number of lines in the clipped text.
        s   
i    ii   N(   R  t   countt   rfindR=   (   R1   R   t	   num_linest   return_countR   t   i(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_last_lines  s    c         C   sy   g  } | } xY t  |  D]K } |  j | | d t \ } } | j |  | | 8} | d k r Pq q W| d d d  S(   s?    Get the list of text clipped to last specified lines.
        R  i    Ni(   t   reversedR!  Rm   RC   (   R1   t	   text_listR  t   rett   lines_pendingR   t   lines_added(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    
c         C   s   |  j    } | j   } | |  j   j   k rB t |  j  } n t |  j  } | j t j j	  | j
   | } t |  t | j    S(   s?    Get the number of leading spaces of the current line.
        (   RA  RB  R(  R  Ra   RX   R  R   R  t   LineUnderCursorR  R~  (   R1   R   R  R  R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   s    t  |  j j   d |  j    S(   s?    Find the position in the text right after the prompt.
        i   (   R  Rc   R   RX  (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR"    s    c         C   s   t  |  j j   |  j    S(   s@    Find the position in the text right before the prompt.
        (   R  RT   R   RX  (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRj    s    c         C   s#   |  j  j   } | j |  j  | S(   sB    Get a cursor at the prompt position of the current cell.
        (   RG   RS   R  R"  (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR(    s    c         C   s6   |  j  j   } | j |  | j | t j j  | S(   s^    Get a cursor with text selected between the positions 'start' and
            'end'.
        (   RG   RS   R  R   R  R#  (   R1   t   startt   endR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _get_selection_cursor  s    c         C   s  |  j  j   } |  j  j   } |  j   } | |  j k r= | S| | k r |  j  j   } | j |  | j t j j	  | j t j j
  | j   } x2 | |  j k r t | j |   r | d 8} q W| j | d  n | d 8} x? | |  j k r+| | k r+t | j |   r+| d 8} q Wx> | |  j k rl| | k rlt | j |   rl| d 8} q/W| j | d  | S(   s    Find the start of the word to the left the given position. If a
            sequence of non-word characters precedes the first word, skip over
            them. (This emulates the behavior of bash, emacs, etc.)
        i   (   RG   R   RS   R8  R"  R  Rl  R   R  R  R  R   R   t   characterAtR   (   R1   R   R   R   t   line_start_pos(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s:    
c   	      C   s/  |  j  j   } |  j  j   } |  j   } |  j   } | | k rF | S| | k r |  j  j   } | j |  | j t j j	  | j
   t |  j  } x/ | | k  r t | j |   r | d 7} q W| j |  nOt | j |   rt } | d } |  j   } x9 | | k rHt | j |   s;t } Pn  | d 8} qW| rx; | | k  r| | k  rt | j |   r| d 7} qRW| j |  | Sn  x< | | k  r| | k  rt | j |   r| d 7} qWx; | | k  r| | k  rt | j |   r| d 7} qW| j |  | S(   s    Find the end of the word to the right the given position. If a
            sequence of non-word characters precedes the first word, skip over
            them. (This emulates the behavior of bash, emacs, etc.)
        i   (   RG   R   RS   RX  R  R  Rl  R   R  R  R   R  RX   R   R+  Rm   R8  RZ   R   (	   R1   R   R   R   t   end_post   line_end_post   is_indentation_whitespacet   back_posR,  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  7  sZ    
c   	      C   sh  |  j    j   j d  } |  j    } |  j    } | j | j    |  j j |  |  j   } |  j | |  j } | j	   x t
 | d  D] } |  j j |  | j |  j    | r,t | |  j    } | |  j } | j t j j t j j t | | d k r| n |  j   | j   n | j d |  | j t j j  q W|  j j |  d S(   s?    Indent/Dedent current line or current text selection.
        u    i   i    R   N(   RA  R  R  R  RU  RG   R   R  Rg   RW  t   rangeR8  R  Rl  R   R  R  R#  R   R  t   Down(	   R1   R   t   num_newlinest   save_curt   curR  t   stept   _t	   safe_step(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  z  s,    
	R4   c         C   sW   |  j  d k r% |  j | |  j  n |  j | |  j   |  _ | rS | j |  n  d S(   sE    Inserts new continuation prompt using the specified cursor.
        N(   RY   R=   Rk  RX   Rz  R  (   R1   R   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   s,   | d k r t j   } n  | j |  d S(   sA    Inserts an empty QTextBlock using the specified cursor.
        N(   R=   R   t   QTextBlockFormatt   insertBlock(   R1   R   Ru  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRt    s    c         C   s   | j    | j |  | j t j j t j j  | j   j   d k rX | j	   n | j t j j
  | j d t j    | j   d S(   sq    Inserts HTML using the specified cursor in such a way that future
            formatting is unaffected.
        R   N(   R  t
   insertHtmlRl  R   R  R  R#  R$  R%  R   R  R  t   QTextCharFormatR  (   R1   R   Rx  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRw    s    
c         C   s   | j    | j   | j   } |  j | |  | j   } | j | t j j  | j   j	   } | j |  | j
   | S(   sc    Inserts HTML using the specified cursor, then returns its plain text
            version.
        (   R  R   R   Rw  R  R   R  R#  R$  R%  R  (   R1   R   Rx  R(  R)  R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRz    s    


c         C   s  |  j  j   j   } |  j r | r |  j j   r | j   |  j   k r |  j j	 |  | d k r |  j
 |  j |  |  _ n  d S|  j r |  j j   r |  j j   n  | d k r |  j | |  } n  |  j  j   } |  j  j t j | j   d | j   d   j   } |  j   } | j   |  j rxd|  j j |  D]@} xz|  j j D]l}	 |	 j d k r|	 j d k r| j t j j  | j   q]|	 j d k r)|	 j d k r)| j  d  | j!   |  j" |  | j#   | j$   t% j& d	 k r| j t j j  | j   qq]|	 j d
 k rQ| j' | j( | j)  q]|	 j d k rpt j* j+   q]|	 j d k r| j,   s| j' | j- | j)  qq]|	 j d k r]| j' | j.  q]q]W|  j j/   }
 | j0   } t1 |  d k r| j  | |
  qJ| d k	 rJt1 |  t1 |  k rD| j  | |
  q| t1 |  } | j  | | |
  | j' | j- | j) t1 |   qJqJWn | j  |  | j!   | | d k r|  j  j3   j4   |  j  j3   j5   } | |  j  j3   j6   k r|  j  j3   j7 |  qn  d S(   sf    Inserts plain text using the specified cursor, processing ANSI codes
            if enabled.
        i    Ni   t   eraset   screent   scrollt   pages   
t   nts   carriage-returnt   beept	   backspacet   newline(8   RG   R   R  R[   Rj   t   isActiveR   RX  Rh   RC   R  R(  R!  R   R   R   t   QPointR   R   R  t
   ansi_codesRU   t   split_stringt   actionsR   t   areaR  R   R  t   DocumentR   t   unitR  R  RD  t   joinPreviousEditBlockR  R  t   nameRl  R  R#  R   RB  t   atBlockStartt   PreviousCharacterR  t
   get_formatR  R  R=   t   verticalScrollBart   maximumt   pageStept   valuet   setValue(   R1   R   R   R
  R   R   t   end_scroll_post   end_doc_post	   substringt   actt   formatR$  t   old_textt
   end_scroll(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRk    s|    	/
	



c         C   s   | j  t  } | r | d j d  r8 | j d  n  | j   | j | d  xY | d D]M } |  j d k r | j |  j  n |  j	 | |  j  |  _ | j |  q^ W| j
   n  d S(   s    Inserts text into the input buffer using the specified cursor (which
            must be in the input buffer), ensuring that continuation prompts are
            inserted as necessary.
        is   
R4   i    i   N(   t
   splitlinesRm   t   endswithRC   R  R  RY   R=   RX   Rz  R  (   R1   R   R   t   linesR  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   :  s    
c         C   s   |  j  j   } | d k r* | j   } n | j |  | j   } |  j   j   } | | k rn | |  j k S| | k r | j t	 j
 j  | j   t |  j  } | | k St S(   su    Returns whether the current cursor (or, if specified, a position) is
            inside the editing region.
        N(   RG   RS   R=   R   R  RB  R(  R"  Rl  R   R  R  R  RX   RZ   (   R1   R   R   R  R  t
   prompt_pos(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   Q  s    
c         C   sL   |  j    } | rH |  j j   } | j t j j  |  j j |  n  | S(   sq    Ensures that the cursor is inside the editing region. Returns
            whether the cursor was moved.
        (   R   RG   RS   Rl  R   R  R  R   (   R1   t   movedR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   d  s    c         C   s-   |  j  r  |  j   |  j   n	 d |  _ d S(   s?    Cancels the current editing task ala Ctrl-G in Emacs.
        R4   N(   R  R}  R  R   (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  o  s    	
c         C   sn  t  j |  j  j   } |  j j   j   | } |  j d k rGt j d | |  rG|  j d k rx |  j	 j
 |  qj|  j j   j d  |  j j   |  j j   } | r |  j | |  n |  j | |  |  j j t  j j  |  j j   j |  j j    |  j r.|  j j   |  j j   qj|  j   j |  j  n# | r]|  j |  n |  j |  d S(   s    Displays text using the pager if it exceeds the height of the
        viewport.

        Parameters
        ----------
        html : bool, optional (default False)
            If set, the text will be interpreted as HTML instead of plain text.
        R)   s   (?:[^
]*
){%i}R(   i    N(   R   R   R   R   RG   R   RH   t   ret   matcht   custom_page_requestedR2  R   R  RQ   R   RS   Rw  Rk  R  R  R  t   resizeRS  RJ   t   showR  R   R  Ry  R  (   R1   R   Rx  t   line_heightt   minlinesR   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  x  s*    		c         C   s   |  j  d k r t d   n  | d k rC |  j  j t j j  nP | d k rh |  j  j t j j  n+ | d k r t d   n t d |   | |  _	 d S(   s   
        Change the pager to `paging` style.

        Parameters
        ----------
        paging : string
            Either "hsplit", "vsplit", or "inside"
        sR   can only switch if --paging=hsplit or
                    --paging=vsplit is used.R&   R'   R%   sC   switching to 'inside' paging not
                    supported yet.s   unknown paging method '%s'N(
   RJ   R=   Ra  RK   R   RL   RM   RN   t
   ValueErrorRH   (   R1   RH   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _set_paging  s    	c         C   s   |  j  j t  |  j   d S(   s    Called immediately after a prompt is finished, i.e. when some input
            will be processed and a new prompt displayed.
        N(   RG   R  Rm   Rd  (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    c         C   s   |  j  j   j d  |  j  j t  |  j  j t  |  j  j t j	 j
 t  |  j sd t |  _ n  |  j   |  j r |  j |  _ d |  _ n  |  j  j t j j  d S(   s=    Called immediately after a new prompt is displayed.
        i    R4   N(   RG   R   R  R!  Rm   R  RZ   R  R   RL   R  Re   R[   Rc  R_   R   R  R   R  R  (   R1   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _prompt_started  s    	
	c            s    j  r t d   n    r;  j   r; t d   n  t  _  | r`  j d d t n   j | d t   d k r d  _ x  j  r t j	 j
   q W j d t  j d  S   f d    _ d S(	   s2   Reads one line of input from the user.

        Parameters
        ----------
        prompt : str, optional
            The prompt to print before reading the line.

        callback : callable, optional
            A callback to execute with the read line. If not specified, input is
            read *synchronously* and this method does not return until it has
            been read.

        Returns
        -------
        If a callback is specified, returns nothing. Otherwise, returns the
        input string with the trailing newline stripped.
        s.   Cannot read a line. Widget is already reading.s>   Cannot synchronously read a line if the widget is not visible!sU   Warning: QtConsole does not support password mode, the text you type will be visible.RD  R&  s   
c              s      j  d t  j d   S(   NR&  s   
(   R'  Rm   R7  (    (   R
  R1   (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR    s    N(   Re   t   RuntimeErrorR  Rm   R   RZ   R=   Rf   R   t   QCoreApplicationt   processEventsR'  R7  (   R1   R  R
  t   password(    (   R
  R1   s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt	   _readline  s    		
	c         C   s(   | r | |  _  n | |  _ d |  _  d S(   s   Sets the continuation prompt.

        Parameters
        ----------
        prompt : str
            The prompt to show when more input is needed.

        html : bool, optional (default False)
            If set, the prompt will be inserted as formatted HTML. Otherwise,
            the prompt will be treated as plain text, though ANSI color codes
            will be handled.
        N(   RY   RX   R=   (   R1   R  Rx  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   _set_continuation_prompt  s    	c         C   s   |  j  j |  d S(   s7    Convenience method to set the current cursor.
        N(   RG   R   (   R1   R   (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRC  	  s    c         C   sb   |  j  j   } | j | j    |  j  j   } |  j  j |  |  j  j   |  j  j |  d S(   sJ    Scrolls the viewport so that the specified cursor is at the top.
        N(   RG   RR  RV  RS  RS   R   t   ensureCursorVisible(   R1   R   t	   scrollbart   original_cursor(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyRD  	  s    c         C   s  |  j    |  j   } | j   d k r1 t } n  t } |  j j | j   d  | r | j   d k r | j t j	 j
 t j	 j  | j   j   d k r |  j   q n  |  j |  j  | d k r |  j d k r |  j |  j  qA|  j |  j  nC | r"|  j |  |  _ | |  _ n |  j |  | |  _ d |  _ |  j    |  j j |  j   d  | r|  j j |  j j   d  n  |  j   d S(   s   Writes a new prompt at the end of the buffer.

        Parameters
        ----------
        prompt : str, optional
            The prompt to show. If not specified, the previous prompt is used.

        html : bool, optional (default False)
            Only relevant when a prompt is specified. If set, the prompt will
            be inserted as formatted HTML. Otherwise, the prompt will be treated
            as plain text, though ANSI color codes will be handled.

        newline : bool, optional (default True)
            If set, a new line will be written before showing the prompt if
            there is not already a newline at the end of the buffer.
        i    i   s   
N(   Ri  R  R   RZ   Rm   RT   R  Rl  R   R  R  R#  R$  R%  Rv  R  Rd   R=   Rb   Ra   Ry  R{  Rc   RX  Rl  (   R1   R  Rx  RD  R   t   move_forward(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   	  s8    
			
	c         C   s  |  j  j   } |  j  j   } |  j  j   j   } t |  j  t j  r} t d | j	   d  } | |  j  j
   j   } n | j   j   } | } | | j   } | j d t |   | j t |   | d k  r| j   | j   k r| j t | j   |   n  d S(   sD    Expands the vertical scrollbar beyond the range set by Qt.
        i    i   N(   RG   R   RR  R   R   t
   isinstanceR   R  RQ  t	   lineCountt   fontMetricst   lineSpacingRS  RS  t   setRanget   roundt   setPageStept
   blockCountR  RV  RU  (   R1   R   Rt  t   viewport_heightRS  R6  t   diff(    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   `	  s    $c         C   s,   |  j  |  } | j |  j j |   d S(   sK    Shows a context menu at the given QPoint (in widget coordinates).
        N(   R  R=  RG   t   mapToGlobal(   R1   R   R  (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR  z	  s    (   t   __name__t
   __module__t   __doc__R   Rm   RG  R   R   R  R   RV   R  RH   R   RI  R2   RJ  R   R   RZ   R   R=   R  R  R   t   SignalR   R  R  R  t   objectRe  R   RN  R1  RG   RQ   RJ   RL   R  R  R  R  R  t   Key_AR  t   Key_PR  t   Key_NR  t   Key_HR   R/   R0   t   Key_Endt   Key_Et   sett   keyst   Key_CR  R  t   Key_VR   R  R;   R   R   R   R   R   t   include_other_outputt   other_output_prefixR   R   R   R   R   R   R   R  R   R  R  R  R}   R  R'  R*  t   propertyR   R,  R3  R   R6  R   t	   ClipboardR   Ry   RF  RG  Rq   RT  R   R   R   RY  R^  R_  R.  R`  Rb  R  Rc  Rd  Rf  Rg  Rh  Rs  Rv  Ry  R{  R  R}  R  R  R  R  R   RF   RP   R   R   Rp   Ri  R  R  RA  R  RX  R  R8  R  R  R  R  R  R  R!  R  R  R"  Rj  R(  R*  R  R  R  R  Rt  Rw  Rz  Rk  R   R   R   R  R  Rk  R  Rl  Rq  Rr  RC  RD  R   R   R  (    (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyR   ,   s@  															C											5																				
							
				"	-		 O	A																							0	C&		b				%			*		
A	(-   R  t	   functoolsR    R  t   os.pathRc  R/   t   textwrapR   R  t   unicodedataR   R4  t   qtconsole.qtR   R   t   traitlets.config.configurableR   t   qtconsole.rich_textR   t   qtconsole.utilR   R   R	   t   ipython_genutils.textR
   t	   traitletsR   R   R   R   t   ansi_code_processorR   t   completion_widgetR   t   completion_htmlR   t   completion_plainR   t	   kill_ringR   R   R   t   QWidgetR   (    (    (    s7   lib/python2.7/site-packages/qtconsole/console_widget.pyt   <module>   s.   "		