
,]c           @   s	  d  Z  d d l Z d d l Z d d l Z d d l j Z d d l Z d d l Z d d l	 Z	 d d l
 m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z m Z m Z d d l m Z m Z m Z d d l m Z m Z m Z m Z d d l  m! Z! m" Z" d d	 l# m$ Z$ d d
 l% m& Z& m' Z' m( Z( m) Z) m* Z* d d l+ m, Z, d d l+ m- Z. d d l/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 d d l4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 d d l9 m: Z: d e: e6 e8 f d     YZ; d e7 e; e5 f d     YZ< d e; f d     YZ= d S(   s(   Shell widgets: base, python and terminaliN(   t   getsavefilename(   t   Propertyt   QCoreApplicationt   Qtt   QTimert   Signalt   Slot(   t   QKeySequencet   QTextCharFormatt   QTextCursor(   t   QApplicationt   QMenut   QToolTip(   t   _t   DEBUGt   get_conf_patht   STDERR(   t   config_shortcutt   get_shortcut(   t   CONF(   t   builtinst	   is_stringt   is_text_stringt   PY3t   to_text_string(   t   encoding(   t   icon_manager(   t   add_actionst   create_actiont
   keybindingt   restore_keyevent(   t   GetHelpMixint   SaveHistoryMixint   TracebackLinksMixint   BrowseHistoryMixin(   t   ConsoleBaseWidgett   ShellBaseWidgetc           B   sK  e  Z d  Z e e  Z e   Z e e  Z e e e  Z	 e
 d1 d  Z d   Z d   Z d   Z d   Z d   Z d   Z e   d    Z d	   Z d
   Z e d e e  Z d   Z d   Z e   d    Z d   Z e   d    Z e   d    Z e   d    Z d   Z  d   Z! d   Z" e   d    Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d    Z- d!   Z. d"   Z/ d#   Z0 d$   Z1 d%   Z2 d&   Z3 d'   Z4 d(   Z5 e
 e
 e
 d)  Z6 e
 e
 d*  Z7 e
 e
 e
 d+  Z8 d,   Z9 d-   Z: d.   Z; d/   Z< d0   Z= RS(2   s   
    Shell base widget
    c         C   s!  t  j |  |  t j |  |  t j |   d |  _ t |  _ t |  sQ t	  |  j
   |  _ t j d d t d   |  _ d |  _ |  j   | |  _ g  |  _ | r |  j j |  n  d |  _ t |   |  _ |  j j t  |  j j j |  j  |  j   |  j t j d d   d S(   s6   
        parent : specifies the parent widget
        t   maint   historylog_filenames   history.logg        s   cursor/widthN(   R#   t   __init__R    R"   t   Nonet   current_prompt_post   Truet   new_input_lineR   t   AssertionErrort   load_historyt   historyR   t   getR   R&   t   menut   setup_context_menut   profilet   _ShellBaseWidget__buffert   appendt   _ShellBaseWidget__timestampR   t   _ShellBaseWidget__flushtimert   setSingleShott   timeoutt   connectt   flusht   setFocust   setCursorWidth(   t   selft   parentt   history_filenameR2   t   initial_message(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR'   7   s*    			
			
c         C   s   |  j  | r d n d  d S(   s   Enable/disable wrap modet	   characterN(   t   set_wrap_modeR(   (   R=   t   enable(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   toggle_wrap_modec   s    c         C   sv   |  j  |  |  j |  |  j   } | j t j  t   } | j | j    | j	 | j
    | j |  d S(   s   Set shell styles fontN(   t   setFontt   set_pythonshell_fontt
   textCursort   selectR	   t   DocumentR   t   setFontFamilyt   familyt   setFontPointSizet	   pointSizet   mergeCharFormat(   R=   t   fontt   cursort
   charformat(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   set_fontg   s    	c      
   C   s  t  |   |  _ t |  t d  d t d  d t j d  d |  j |  _ t |  t d  d t d  d t j d  d |  j	 |  _
 t |  t d  d t d  d t j d	  d |  j } t |  t d
  d t j d  d t d  d |  j } t |  t d  d t d  d t j d  d |  j |  _ t |  t d  d t d  d t j d  d |  j } t |  j |  j |  j
 | |  j d | d | f  d S(   s   Setup shell context menut   Cutt   shortcutt   icont   editcutt	   triggeredt   Copyt   editcopyt   Pastet	   editpastes   Save history log...t   filesavet   tipsE   Save current history log (i.e. all inputs and outputs) in a text filet   Deletet
   editdeletes
   Select Allt	   SelectAllt	   selectallN(   R   R0   R   R   R   t   imaRU   t   cutt
   cut_actiont   copyt   copy_actiont   pastet   save_historylogt   deletet   delete_actiont	   selectAllR   R(   (   R=   t   paste_actiont   save_actiont   selectall_action(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR1   t   s8    c         C   s`   |  j    } |  j j |  |  j j |  |  j j |  |  j j | j    | j   d S(   s   Reimplement Qt methodN(	   t   has_selected_textRf   t
   setEnabledRd   Rj   R0   t   popupt	   globalPost   accept(   R=   t   eventt   state(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   contextMenuEvent   s    c         C   s   |  j  d d  S(   NRP   t   eof(   t   get_text(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_current_line_from_cursor   s    c         C   s]   |  j  d  \ } } |  j d k r4 | | } } n |  j \ } } |  j | | | |  d S(   s6   Select current line (without selecting console prompt)Rw   N(   t   get_positionR)   R(   t   setSelection(   R=   t   linet   indext   plinet   pindex(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   _select_input   s
    c         C   s   |  j    d S(   se   
        Clear terminal window
        Child classes reimplement this method to write prompt
        N(   t   clear(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   clear_terminal   s    c         C   sF   |  j  d k	 r( |  j |  j  d |  n |  j |  |  j d  d S(   s   Set input buffert   eolRw   N(   R)   R(   t   replace_textt   insertt   set_cursor_position(   R=   t   text(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   _set_input_buffer   s    c         C   sF   d } |  j  d k	 rB |  j |  j  d  } | j t j d  } n  | S(   s   Return input buffert    R   s   
N(   R)   R(   Rx   t   replacet   ost   linesep(   R=   t   input_buffer(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   _get_input_buffer   s
    t   QStringc         C   sb   |  j    d d k r& |  j d  n  |  j | d t |  j d  |  _ |  j   t |  _ d S(   sH   
        Print a new prompt and save its (line, index) position
        i   i    s   
t   promptRP   N(   t   get_cursor_line_columnt   writeR*   Rz   R)   t   ensureCursorVisiblet   FalseR+   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt
   new_prompt   s    
c         C   s3   |  j  d k r |  j d  n |  j |  j   d S(   sf   
        Check if selected text is r/w,
        otherwise remove read-only parts of selection
        Rw   N(   R)   R(   R   t   truncate_selection(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   check_selection   s    c         C   s<   |  j    r t j |   n t j d k s8 |  j   n  d S(   s/   Copy text to clipboard... or keyboard interruptt   darwinN(   Ro   R#   Re   t   syst   platformt	   interrupt(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRe      s    c         C   s   |  j  j   d S(   s   Keyboard interruptN(   t   sig_keyboard_interruptt   emit(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR      s    c         C   s*   |  j    |  j   r& t j |   n  d S(   s   Cut textN(   R   Ro   R#   Rc   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRc      s    
c         C   s*   |  j    |  j   r& t j |   n  d S(   s   Remove selected textN(   R   Ro   R#   t   remove_selected_text(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRi      s    
c         C   s   t  d  } |  j j t  t |  | |  j d t  d   \ } } |  j j t  | r t j |  } y< t	 j
 t |  j    |  | |  _ t j d d |  Wq t k
 r q Xn  d S(   s.   Save current history log (all text in console)s   Save history logs
   %s (*.log)s   History logsR%   R&   N(   R   t   redirect_stdioR   R   R    R&   R*   t   ospt   normpathR   R   R   t   get_text_with_eolR   t   sett   EnvironmentError(   R=   t   titlet   filenamet
   _selfilter(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRh      s    		c         C   s   |  j  |  d S(   t   on_enterN(   t   execute_command(   R=   t   command(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s*   |  j  j |  |  j |  t |  _ d  S(   N(   t   executeR   t   add_to_historyR*   R+   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s,   |  j  d  |  j d  |  _ t |  _ d S(   s   On new input lineRw   RP   N(   R   Rz   R)   R   R+   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   on_new_line  s    c         C   s'   |  j  r |  j   n  t j |   d S(   s3   Reimplemented slot to handle multiline paste actionN(   R+   R   R#   Rg   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRg     s    	c         C   s$   |  j  |  r d S|  j |  d S(   s   
        Reimplement Qt Method
        Basic keypress event handler
        (reimplemented in InternalShell to add more sophisticated features)
        N(   t   preprocess_keyeventt   postprocess_keyevent(   R=   Rt   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   keyPressEvent#  s    c         C   s   | j    t j @} | j    t j @} | j   t j k r t j t j B| j    @r | rw t j d k rw |  j   n | r |  j	   n  | j
   t S|  j r t | j    s | j   t j t j t j t j f k r |  j   n  t S(   sU   Pre-process keypress event:
        return True if event is accepted, false otherwiseR   (   t	   modifiersR   t   ControlModifiert   MetaModifiert   keyt   Key_CR   R   R   Re   Rs   R*   R+   t   lenR   t   Key_Upt   Key_Downt   Key_Leftt	   Key_RightR   R   (   R=   Rt   t   ctrlt   meta(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR   .  s    
$!c         C   s  t  |  \ } } } } } t |  rV |  j   r@ |  j   n  |  j |  j d  n  |  j d  } | t j t j	 f k r |  j
   r |  j   q|  j |  j   d t n| t j k r | r | r |  j |  j    n| t j k r4|  j   r|  j   |  j   q|  j
   r|  j   qn| t j k rS|  j |  nf| t j k ro|  j   nJ| t j k r| r|  j   n(| t j k r|  j | k rd S| r|  j n |  j } | | rd n d d d n| t j k r@|  j   r	d S| r|  j n |  j } | | r0d n d d d	 ny| t j  k sd| t j! k rw| rw|  j" | |  nB| t j# k s| t j$ k r| r|  j% | |  n| t j! k r1|  j
   s|  j& d  n  |  j' |  d
 } |  j' |  j  d
 }	 | |	 k r|  j( |  q|  j) d t  n| t j$ k r|  j
   s\|  j& d  n  |  j' |  d
 } |  j' d  d
 }
 | |
 k  r|  j* |  q|  j) d t+  n| t j, t j- f k rt. j/ |  |  n| t j0 k r| r|  j1   n| t j0 k r|  j2   n| t j3 k r<| r<|  j4   n}| t j5 k r^| r^|  j6   n[| t j7 k r| r|  j8   n9| t j9 k r| r|  j:   n| t j; k r| r|  j<   n | t j= k r| r|  j>   n | t j? k r|  j   r|  j@ |  n | t jA k r>|  j   r>|  jB |  n{ | t jC k rj|  j   rj|  jD |  nO t |  r|  jE   rt+ |  _F |  j |  |  jG |  n t. j/ |  |  d S(   sc   Post-process keypress event:
        in InternalShell, this is method is called when shell is readyRw   RP   t   at_endNt   wordRA   t	   directiont   leftt   righti   t   backwardR   (H   R   R   Ro   R   t   restrict_cursor_positionR)   Rz   R   t
   Key_Returnt	   Key_Entert   is_cursor_on_last_linet
   _key_entert   insert_textt   get_selected_textR*   t
   Key_Insertt   setOverwriteModet   overwriteModet
   Key_DeleteR   t   stdkey_cleart   Key_Backspacet   _key_backspacet   Key_Tabt   _key_tabt	   Key_Spacet   _key_ctrl_spaceR   t   extend_selection_to_nextt   move_cursor_to_nextR   t   is_cursor_at_endt   Key_HomeR   t	   _key_homet   Key_EndR   t   _key_endR   t   get_coordinatest	   stdkey_upt   browse_historyt   stdkey_downR   t
   Key_PageUpt   Key_PageDownR#   R   t
   Key_Escapet
   clear_linet   _key_escapet   Key_LR   t   Key_VRg   t   Key_XRc   t   Key_Zt   undot   Key_Yt   redot   Key_ARk   t   Key_Questiont   _key_questiont   Key_ParenLeftt   _key_parenleftt
   Key_Periodt   _key_periodt
   isReadOnlyt   hist_wholelinet
   _key_other(   R=   Rt   R   R   R   t   shiftt   cursor_positiont   methodt   y_cursort   y_promptt   y_end(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR   E  s    
		$$	c         C   s7   |  j  } |  j d d t |  j |  |  j   d  S(   Ns   
R   (   R   R   R*   R   R:   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    	c         C   s
   t   d  S(   N(   t   NotImplementedError(   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s)   |  j    r% |  j | | |  j  n  d  S(   N(   R   t   stdkey_homeR)   (   R=   R   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s#   |  j    r |  j | |  n  d  S(   N(   R   t
   stdkey_end(   R=   R   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   _key_pageup  s    c         C   s
   t   d  S(   N(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   _key_pagedown  s    c         C   s
   t   d  S(   N(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s
   t   d  S(   N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s8  t  j |  j  r} t j |  j  \ } } g  | D] } | j d d  ^ q1 } | d |  j d k r |  j d | d <q n	 |  j } g  | D]" } | r | j d  r | ^ q } xQ t |  t	 j
 d d  k r| d =x | d j d  r | d =q W| d =q Wy t j | |  j  Wn t k
 r3n X| S(   s3   Load history from a .py file in user home directorys   
R   i   t   #t
   historylogt   max_entriesi    (   R   t   isfileR?   R   t	   readlinesR   t   INITHISTORYt
   startswithR   R   R/   t
   writelinesR   (   R=   t
   rawhistoryR   R|   R.   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR-     s$    %	"!c         C   s=   |  j    |  j | d t d t t r9 t j |  n  d S(   s   Simulate stderrR:   t   errorN(   R:   R   R*   R   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   write_error  s    
c         C   s   | r |  j    n  t |  s. t |  } n  |  j j |  t j   } | sV | ro |  j  d | d |  n? | |  j d k r |  j  d |  | |  _ |  j j d  n  d S(   s   Simulate stdout and stderrR
  R   g?i2   N(	   R:   R   R   R3   R4   t   timeR5   R6   t   start(   R=   R   R:   R
  R   t   ts(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    	c         C   s   t  rl y d j |  j  } Wq~ t k
 rh d j |  j  } y | j t j   d  } Wqi qi Xq~ Xn d j |  j  } g  |  _ |  j | d t d | d | t	 j
   |  j   t |  _ d S(   s#   Flush buffer, write text to consoleR   i   R   R
  R   N(   R   t   joinR3   t	   TypeErrort   decodet   localet   getdefaultlocaleR   R*   R   t   processEventst   repaintR+   (   R=   R
  R   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR:     s    	

c         C   s0   | r |  j  | | |  n t j |  |  d S(   sf   
        Insert text at the current cursor position
        or at the end of the command line
        N(   t   append_text_to_shellR#   R   (   R=   R   R   R
  R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR   6  s    c         C   s   | r
 t  St j |  |  S(   sE   
        Reimplemented to stop Tab moving to the next window
        (   R   R#   t   focusNextPrevChild(   R=   t   next(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR  D  s    c         C   s    | j  | j   j d   d S(   s   Drag and Drop - Enter events
   text/plainN(   t   setAcceptedt   mimeDatat	   hasFormat(   R=   Rt   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   dragEnterEventN  s    c         C   s@   | j    j d  r2 | j t j  | j   n
 | j   d S(   s   Drag and Drop - Move events
   text/plainN(   R  R  t   setDropActionR   t
   MoveActionRs   t   ignore(   R=   Rt   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   dragMoveEventR  s    c         C   s   | j    j d  r} t | j    j    } |  j rC |  j   n  |  j | d t |  j   | j	 t
 j  | j   n
 | j   d S(   s   Drag and Drop - Drop events
   text/plainR   N(   R  R  R   R   R+   R   R   R*   R;   R  R   R  Rs   R  (   R=   Rt   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt	   dropEventZ  s    	
c         C   s
   t   d S(   s   Drop path listN(   R   (   R=   t   pathlist(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   drop_pathlistg  s    N(>   t   __name__t
   __module__t   __doc__R   t   boolR   R   t   strR   t   append_to_historyR   R(   R'   RD   RR   R1   Rv   Ry   R   R   R   R   R   R   R   R   R   Re   R   Rc   Ri   Rh   R   R   R   Rg   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R-   R  R   R:   R   R  R  R   R!  R#  (    (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR$   ,   sl   	+			 																																
			t   PythonShellWidgetc           B   si  e  Z d  Z e Z d d g Z d e j d e j	   f Z
 e e  Z e d# d  Z d   Z d   Z d   Z d	   Z e   d
    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ e d   Z, d!   Z- d"   Z. RS($   s   Python shell widgets   # -*- coding: utf-8 -*-s+   # *** Spyder Python Console History Log ***s   %s##---(%s)---i   c         C   sF   t  j |  | | | |  t j |   t j |   |  j   |  _ d  S(   N(   R$   R'   R!   R   t   create_shortcutst	   shortcuts(   R=   R>   R?   R2   R@   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR'   z  s
    c            s|   t    f d   d d d d d   } t    f d   d d d d d   } t    j d d	 d d
 d   } | | | g S(   Nc              s
     j    S(   N(   t   enter_array_inline(    (   R=   (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   <lambda>  R   t   contextt   array_buildert   names   enter array inlineR>   c              s
     j    S(   N(   t   enter_array_table(    (   R=   (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR.    R   s   enter array tablet   Consoles   Inspect current object(   R   t   inspect_current_object(   R=   t   array_inlinet   array_tablet	   inspectsc(    (   R=   s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR+    s    	c         C   s   g  |  j  D] } | j ^ q
 S(   s   
        Returns shortcut data, a list of tuples (shortcut, text, default)
        shortcut (QShortcut or QAction instance)
        text (string): action/shortcut description
        default (string): default key sequence
        (   R,  t   data(   R=   t   sc(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_shortcut_data  s    c      
   C   s   t  j |   t |  t d  d t j d  d |  j |  _ t |  t d  t t	 d d   d t j d  d t d  d |  j
 } t |  t d	  t t	 d d	   d t j d
  d t d  d |  j } t |  j |  j | | f  d S(   s#   Reimplements ShellBaseWidget methods   Copy without promptsRU   t   copywopRW   s
   Clear linet   consoleR_   R]   s   Clear shellt	   editclears$   Clear shell contents ('cls' command)N(   R$   R1   R   R   Rb   RU   t   copy_without_promptst   copy_without_prompts_actionR   R   R   R   R   R0   (   R=   t   clear_line_actiont   clear_action(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR1     s&    		c         C   s0   |  j    } |  j j |  t j |  |  d S(   s#   Reimplements ShellBaseWidget methodN(   Ro   R?  Rp   R$   Rv   (   R=   Rt   Ru   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRv     s    c         C   s   |  j    } | j t j  } xI t |  D]; \ } } | j d  sU | j d  r+ | d | | <q+ q+ Wt j j |  } t j   j	 |  d S(   s&   Copy text to clipboard without promptss   >>> s   ... i   N(
   R   t   splitR   R   t	   enumerateR  R  R
   t	   clipboardt   setText(   R=   R   t   linesR}   R|   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR>    s    c         C   sK   t  j |  |  t j   rG t |  \ } } } } } |  j |  n  d S(   s   Process keypress eventN(   R$   R   R   t	   isVisibleR   t   hide_tooltip_if_necessary(   R=   Rt   t   _eventt   _textR   t   _ctrlt   _shift(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s"   |  j    r |  j | 7_ n  d S(   s   1 character keyN(   t   is_completion_widget_visiblet   completion_text(   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   sr   |  j    r# |  j   |  j   nK |  j | k r6 d S|  j   rn |  j   |  j   rn |  j d  |  _ qn n  d S(   s   Action for Backspace keyNi(   Ro   R   R   R)   R   t   stdkey_backspaceRM  RN  (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    

c         C   sI   |  j    rE |  j   j   } | r2 |  j   qE |  j d t  n  d S(   s   Action for TAB keyt	   automaticN(   R   t   get_current_line_to_cursort   stript
   stdkey_tabt   show_code_completionR   (   R=   t
   empty_line(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s
    c         C   s#   |  j    s |  j d t  n  d S(   s   Action for Ctrl+SpaceRP  N(   RM  RT  R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   d S(   s   Action for PageUp keyN(    (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   d S(   s   Action for PageDown keyN(    (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   |  j    r |  j   n  d S(   s   Action for ESCAPE keyN(   RM  t   hide_completion_widget(   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   sm   |  j    r> |  j   } | r> | j   r> |  j |  q> n  |  j |  |  j   ri |  j d 7_ n  d S(   s   Action for '?'t   ?N(   RQ  t   get_last_objt   isdigitt   show_object_infoR   RM  RN  (   R=   R   t   last_obj(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   sm   |  j    |  j   r\ |  j   } | r\ | j   r\ |  j |  |  j | d t d Sn  |  j |  d S(   s   Action for '('t   callN(   RV  RQ  RX  RY  R   RZ  R*   (   R=   R   R[  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    
c         C   sO   |  j  |  |  j rK |  j   } | rK | j   rK |  j d t  qK n  d S(   s   Action for '.'RP  N(   R   t   codecompletion_autoRX  RY  RT  R*   (   R=   R   R[  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s
    	c         C   s   t  t j   j    } t | j    d k r |  j rF |  j   n  |  j   |  j	   } |  j
   | | } |  j   |  j |  |  j t |   n t j |   d S(   s3   Reimplemented slot to handle multiline paste actioni   N(   R   R
   RD  R   R   t
   splitlinesR+   R   R   Ry   RQ  R   t   execute_linest   move_cursorR$   Rg   (   R=   R   t   endRF  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRg     s    	

c         C   s
   t   d S(   s   Return dir(object)N(   R   (   R=   t   objtxt(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_dir0  s    c         C   s   d S(   s7   Return module completion list associated to object nameN(    (   R=   Rb  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_module_completion3  s    c         C   s
   t   d S(   s   Return shell globals() keysN(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_globals_keys6  s    c         C   s
   t   d S(   s'   Return shell current directory list dirN(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_cdlistdir9  s    c         C   s
   t   d S(   s   Is object callable?N(   R   (   R=   Rb  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt
   iscallable<  s    c         C   s
   t   d S(   s   Get func/method argument listN(   R   (   R=   Rb  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_arglist?  s    c         C   s
   t   d S(   s   Get object __doc__N(   R   (   R=   Rb  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt
   get__doc__B  s    c         C   s
   t   d S(   s#   Get object documentation dictionaryN(   R   (   R=   Rb  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   get_docE  s    c         C   s
   t   d S(   s   Get object sourceN(   R   (   R=   Rb  (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt
   get_sourceH  s    c         C   s
   t   d S(   s    Return True if object is definedN(   R   (   R=   Rb  t   force_import(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt
   is_definedK  s    c         C   s<  t  |  j    } |  j   } | s( d S| j d  r |  j |  } | j d  } d | d k r{ | d j d  } n  |  j | d | d d | d S| j d  rV|  j |  } | d k r d S| j d  } d	 | d k r| d
  | d j d	  } n  d | d k r5| d
  | d j d  } n  |  j | d | d d | d S|  j |  } | r| r| j	 d  r|  j | d | d S| j	 d  r,| r,t
 j d |  r,t t  |  j   t j } xM | D]> } | j |  r| | k r|  j | d | d | d SqWd Sn  | d k rA| } n  | j d  }	 |	 d k r|	 t |  d k r{d }
 n | |	 d }
 | |	  } |  j |  } | d k	 r|  j | d |
 d | d Sn  t | j d  | j d  g  } | d k r8|  j   } | r4|  j | d | | d d | n  d Sd S(   s3   Display a completion list based on the current lineNs   import t    t   ,iRN  RP  s   from t   (it   .s   [a-zA-Z_0-9]*$i   R   t   't   "(   R   RQ  RX  R  Rd  RB  t   show_completion_listR(   Rc  t   endswitht   ret   matcht   dirR   Re  t   keywordt   kwlistt   rfindR   t   maxRf  (   R=   RP  R   R[  t   obj_listt   wordst   obj_dirt   b_k_gt   objnamet   dot_posRN  t   completionst   q_pos(    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyRT  O  sv    		
$
c         C   s   | r g  | D] } d | ^ q } t  |  d k rB | d } n d d j |  d } |  j ro |  j   n  |  j |  |  j   n  d S(   s   Drop path lists   r'%s'i   i    t   [s   , t   ]N(   R   R  R+   R   R   R;   (   R=   R"  t   patht   filesR   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR#    s    	N(/   R$  R%  R&  R$   t   QT_CLASSR  R   R   R  t   ctimet	   SEPARATORR   R(  t   go_to_errorR   R(   R'   R+  R:  R1   Rv   R   R>  R   R   R   R   R   R   R   R   R   R   R   Rg   Rc  Rd  Re  Rf  Rg  Rh  Ri  Rj  Rk  Rm  RT  R#  (    (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR*  q  sH   				
																									Lt   TerminalWidgetc           B   s   e  Z d  Z e j d k r! d n d Z d e e g Z d e j d e e j	   f Z
 e e  Z e d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   
    Terminal widget
    t   ntt   remR  s&   %s *** Spyder Terminal History Log ***s   %s%s ---(%s)---i   c         C   s   t  j |  | | |  d  S(   N(   R$   R'   (   R=   R>   R?   R2   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR'     s    c         C   s   d S(   s   1 character keyN(    (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   sS   |  j    r# |  j   |  j   n, |  j | k r6 d S|  j   rO |  j   n  d S(   s   Action for Backspace keyN(   Ro   R   R   R)   R   RO  (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    
c         C   s   |  j    r |  j   n  d S(   s   Action for TAB keyN(   R   RS  (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   d S(   s   Action for Ctrl+SpaceN(    (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   |  j    d S(   s   Action for ESCAPE keyN(   R   (   R=   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   |  j  |  d S(   s   Action for '?'N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   |  j  |  d S(   s   Action for '('N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   |  j  |  d S(   s   Action for '.'N(   R   (   R=   R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR     s    c         C   s   | r g  | D] } d | ^ q } t  |  d k rB | d } n d j |  } |  j rg |  j   n  |  j |  |  j   n  d S(   s   Drop path lists   "%s"i   i    Rn  N(   R   R  R+   R   R   R;   (   R=   R"  R  R  R   (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR#    s    	(   R$  R%  R&  R   R1  t   COMR  R   R  R  R  R   R(  R  R   R'   R   R   R   R   R   R   R   R   R#  (    (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyR    s    								(>   R&  Ry  R  R   t   os.pathR  R   Rv  R   R  t   qtpy.compatR    t   qtpy.QtCoreR   R   R   R   R   R   t
   qtpy.QtGuiR   R   R	   t   qtpy.QtWidgetsR
   R   R   t   spyder.config.baseR   R   R   R   t   spyder.config.guiR   R   t   spyder.config.mainR   t   spyder.py3compatR   R   R   R   R   t   spyder.utilsR   R   Rb   t   spyder.utils.qthelpersR   R   R   R   t   spyder.widgets.mixinsR   R    R!   R"   t   spyder.widgets.sourcecode.baseR#   R$   R*  R  (    (    (    s3   lib/python2.7/site-packages/spyder/widgets/shell.pyt   <module>   s8   ."(""	  F	 8