
,]c           @   s  d  Z  d d l m 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 m Z d d l 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 d d	 l m Z d d
 l m Z m Z d d l m  Z  m! Z! m" Z" d d l# m$ Z$ d d l% m& Z& e" j' e d d  Z( e( rYd d l
 m) Z) n d d l
 m* Z* d e+ f d     YZ, d e+ f d     YZ- d e+ f d     YZ. d e+ f d     YZ/ d e+ f d     YZ0 d S(   s   Mix-in classes

These classes were created to be able to provide Spyder's regular text and
console widget features to an independant widget based on QTextEdit for the
IPython console plugin.
i(   t   escapeN(   t   QPointt   Qt(   t   QCursort   QTextCursort   QTextDocument(   t   QApplicationt   QToolTip(   t
   QT_VERSION(   t   getargspecfromtextt   getobjt   getsignaturefromtext(   t   _(   t   is_text_stringt   to_text_string(   t   encodingt
   sourcecodet   programs(   t   get_error_match(   t   NumpyArrayDialogs   5.5s   >=(   t   QRegularExpression(   t   QRegExpt   BaseEditMixinc           B   s  e  Z d    Z d   Z d   Z e d d5 d5 d  Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d d  Z d   Z d   Z d   Z d d  Z d   Z d d d  Z d   Z d d d  Z d   Z d   Z d   Z d 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* d5 d+  Z+ d,   Z, e- e- e e e d-  Z. d.   Z/ d/ e e d0  Z0 e e d1  Z1 d2   Z2 d3   Z3 d4   Z4 RS(6   c         C   s   d  |  _ d |  _ d  S(   NiX  (   t   Nonet	   eol_charst   calltip_size(   t   self(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   __init__/   s    	c         C   s   d S(   s   Return line number area widthi    (    (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_linenumberarea_width4   s    c         C   s   g  } | j  d  d } t j | d d d d t |  d } xv | D]n } t |  } | j d d  } x: d	 d
 d d d d g D]  } | j | d | d  } q W| j |  qI Wd j |  } | | f S(   Nt   (i    t   widthi2   t   subsequent_indentt    i   s   &nbsp;t   =t   ,t   )t   *s   **s,   <span style='color: red; font-weight: bold'>s   </span>s   <br>(   t   splitt   textwrapt   wrapt   lenR    t   replacet   appendt   join(   R   t   textt   formatted_linest   namet   rowst   rt   chart	   signature(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   _format_signature;   s    	s   #2D62FFc         C   s%  | d k s t |  d k r" d S| d k r@ |  j d  } n  | |  _ | rg |  j |  \ } } n\ t | t  r d j |  } n  | j d d  } t |  |  j	 k r | |  j	  d } n  |  j
   } | j   }	 | j   }
 d |
 |	 | f } d	 |
 |	 d
 k r|	 d n |	 f } | d | d | | d } |  j d  \ } } | d k	 rd } t |  j   j | d   } |  j |  j   } n  |  j t | |   } | j | j   |  j    | j | j   | j   d  | r|  j j | | |  n t j | |  d S(   s   Show calltipi    Nt   cursors   
    s   
s   <br>s    ...s;   <div style='font-family: "%s"; font-size: %spt; color: %s'>s0   <div style='font-family: "%s"; font-size: %spt'>i	   i   s   <b>%s</b></div>s   <hr>s   </div>i   (   R   R(   t   get_positiont   calltip_positionR3   t
   isinstancet   listR+   R)   R   t   fontt	   pointSizet   familyt   get_coordinatesR   t   documentt   findBlockByNumbert
   cursorRectt   topt   mapToGlobalR   t   setXt   xR   t   setYt   yt   calltip_widgett   show_tipR   t   showText(   R   t   titleR,   R2   t   colort   at_linet   at_positiont   wrapped_textlinesR9   t   sizeR;   t   format1t   format2t   tiptextt   cxt   cyR4   t   point(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   show_calltipK   s>    	#!c         C   s   t  |  s t |  } n  t j |  } | d k	 oB |  j d k	 } | |  _ | r |  j   j t  |  j	 d k	 r |  j	 j
 |  q n  d S(   sA   Set widget end-of-line (EOL) characters from text (analyzes text)N(   R   R   R   t   get_eol_charsR   R   R=   t   setModifiedt   Truet   sig_eol_chars_changedt   emit(   R   R,   R   t   is_document_modified(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   set_eol_chars{   s    	c         C   s!   |  j  d k	 r |  j  St j Sd S(   s/   Return line separator based on current EOL modeN(   R   R   t   ost   linesep(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_line_separator   s    c         C   sY   t  |  j    } | j   } |  j   } | j |  } | j d  rU | | 7} n  | S(   sM   Same as 'toPlainText', replace '
' 
        by correct end-of-line characterss   
(   R   t   toPlainTextt
   splitlinesR_   R+   t   endswith(   R   t   utextt   linesR^   t   txt(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_text_with_eol   s    c         C   s   |  j    } | d k r n | d k r: | j t j  na | d k rY | j t j  nB | d k rx | j t j  n# | d k r | j t j  n | S| j   S(   sY   Get offset in character for the given subject from the start of
           text edit areaR4   t   solt   eolt   eoft   sof(   t
   textCursort   movePositionR   t   StartOfBlockt
   EndOfBlockt   Endt   Startt   position(   R   t   subjectR4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR5      s    c         C   sS   |  j  |  } |  j   } | j |  |  j |  j   } | j   | j   f S(   N(   R5   Rk   t   setPositionR?   t   centerRC   RE   (   R   Rq   R4   RT   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR<      s
    c         C   s"   |  j    } | j   | j   f S(   s$   Return cursor (line, column) numbers(   Rk   t   blockNumbert   columnNumber(   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_cursor_line_column   s    c         C   s   |  j    j   d S(   s   Return cursor line numberi   (   Rk   Ru   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_cursor_line_number   s    c         C   sC   |  j  |  } |  j   } | j |  |  j |  |  j   d S(   s   Set cursor positionN(   R5   Rk   Rs   t   setTextCursort   ensureCursorVisible(   R   Rq   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   set_cursor_position   s
    i    c         C   sR   | d k r t  j n t  j } x- t t |   D] } |  j | t  j  q1 Wd S(   s/   Move cursor to left or right (unit: characters)i    N(   R   t   Rightt   Leftt   ranget   abst
   moveCursort
   MoveAnchor(   R   t   charst	   directiont   _i(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   move_cursor   s    c         C   s&   |  j    } | j t j  | j   S(   s*   Return True if cursor is on the first line(   Rk   Rl   R   Rm   t   atStart(   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   is_cursor_on_first_line   s    c         C   s&   |  j    } | j t j  | j   S(   s)   Return True if cursor is on the last line(   Rk   Rl   R   Rn   t   atEnd(   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   is_cursor_on_last_line   s    c         C   s   |  j    j   S(   s/   Return True if cursor is at the end of the text(   Rk   R   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   is_cursor_at_end   s    c         C   sb   |  j  |  | } |  j   } | j t j  | | j   k  r^ | j |  |  j   | k  Sd S(   s*   Return True if cursor is before *position*N(   R5   Rk   Rl   R   Ro   Rq   Rs   (   R   Rq   t   char_offsetR4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   is_cursor_before   s    c         C   s  | d k s t   | d k re | d k r@ |  j t j |  q| d k r|  j t j |  qn | d k r | d k r |  j t j |  q| d k r|  j t j |  qnS | d k r| d k r |  j t j |  q| d k r|  j t j |  qn  d  S(	   Nt	   charactert   wordt   linet   leftt   rightt   downt   up(   R   R   R   (	   t   AssertionErrorR   R   t   PreviousCharactert   NextCharactert   PreviousWordt   NextWordt	   NextBlockt   PreviousBlock(   R   t   whatR   t	   move_mode(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   __move_cursor_anchor   s     R   R   c         C   s   |  j  | | t j  d S(   ss   
        Move cursor to next *what* ('word' or 'character')
        toward *direction* ('left' or 'right')
        N(   t"   _BaseEditMixin__move_cursor_anchorR   R   (   R   R   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   move_cursor_to_next   s    c         C   s'   |  j    } | j   |  j |  d S(   s   Clear current selectionN(   Rk   t   clearSelectionRy   (   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   clear_selection   s    
c         C   s   |  j  | | t j  d S(   sx   
        Extend selection to next *what* ('word' or 'character')
        toward *direction* ('left' or 'right')
        N(   R   R   t
   KeepAnchor(   R   R   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   extend_selection_to_next  s    c         C   sN   |  j  |  } |  j  |  } |  j   } | j |  | j | t j  | S(   N(   R5   Rk   Rs   R   R   (   R   t   position_fromt   position_toR4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   __select_text  s    c         C   s=   y t  |  j    j   | SWn t k
 r8 |  j   SXd S(   s)   Return text line at line number *line_nb*N(   R   R`   Ra   t
   IndexErrorR_   (   R   t   line_nb(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_text_line  s    c         C   s   |  j  | |  } t | j    } | d k o9 | d k } | r | r x | j d  rh | d  } qL Wx  | j d  r | d  } ql Wn  | S(   s   
        Return text between *position_from* and *position_to*
        Positions may be positions or 'sol', 'eol', 'sof', 'eof' or 'cursor'
        Rj   Ri   s   
iu    (   t   _BaseEditMixin__select_textR   t   selectedTextRb   (   R   R   R   R4   R,   t   all_text(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_text!  s    c         C   s|   |  j  |  | } |  j   } | j t j  | | j   k  rt | j |  | j t j t j  t	 | j
    Sd Sd S(   s5   Return character at *position* with the given offset.t    N(   R5   Rk   Rl   R   Ro   Rq   Rs   R|   R   R   R   (   R   Rq   t   offsetR4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_character0  s    
c         C   s&   |  j    s" |  j   j |  n  d S(   s   Insert text at cursor positionN(   t
   isReadOnlyRk   t
   insertText(   R   R,   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   insert_text=  s    c         C   s-   |  j  | |  } | j   | j |  d  S(   N(   R   t   removeSelectedTextR   (   R   R   R   R,   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   replace_textB  s    
c         C   s    |  j  | |  } | j   d  S(   N(   R   R   (   R   R   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   remove_textG  s    c            s     j    } | j   r@ | j t | j   | j   g   nD   f d   } | t j  r | t j  rq d S| j	 t j
  n  | j t j  t | j    } t j d | t j  } | r | d Sd S(   s1   Return current word, i.e. word at cursor positionc            s6     j    } | j |  t j  t | j    j   S(   N(   Rk   Rl   R   R   R   R   t   strip(   t   movet   curs(   R   (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   is_space]  s    Ns   ([^\d\W]\w*)i    (   Rk   t   hasSelectionRs   t   mint   selectionStartt   selectionEndR   R   R   Rl   t   WordLeftt   selectt   WordUnderCursorR   R   t   ret   findallt   UNICODE(   R   R4   R   R,   t   match(    (   R   s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_current_wordK  s    c         C   s,   |  j    } | j t j  t | j    S(   s   Return current line's text(   Rk   R   R   t   BlockUnderCursorR   R   (   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_current_linem  s    c         C   s   |  j  |  j d  S(   s!   Return text from prompt to cursorR4   (   R   t   current_prompt_pos(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_current_line_to_cursors  s    c         C   s   |  j  |  } | j   d S(   s,   Return line number at *coordinates* (QPoint)i   (   t   cursorForPositionRu   (   R   t   coordinatesR4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_line_number_atw  s    c         C   s;   |  j  |  } | j t j  t | j    j d d  S(   s%   Return line at *coordinates* (QPoint)u    R   (   R   R   R   R   R   R   R)   (   R   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_line_at|  s    c         C   s/   |  j  |  } | j t j  t | j    S(   s%   Return word at *coordinates* (QPoint)(   R   R   R   R   R   R   (   R   R   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_word_at  s    c         C   sT   t  |  j   j |  j    } | j d d |  j  } t |  t | j    S(   s*   Return line indentation (character number)s   	R    (   R   R=   R>   R,   R)   t   tab_stop_width_spacesR(   t   lstrip(   R   t   block_nbR,   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_block_indentation  s    !c         C   sk   |  j    } | j   | j   } } |  j   j |  } |  j   j |  } t | j   | j   g  S(   s'   Return selection bounds (block numbers)(   Rk   R   R   R=   t	   findBlockt   sortedRu   (   R   R4   t   startt   endt   block_startt	   block_end(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_selection_bounds  s
    c         C   s   t  t |  j   j     S(   s%   Returns True if some text is selected(   t   boolR   Rk   R   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   has_selected_text  s    c         C   s(   t  |  j   j    j d |  j    S(   s   
        Return text selected by current text cursor, converted in unicode
        
        Replace the unicode line separator character \u2029 by 
        the line separator characters returned by get_line_separator
        u    (   R   Rk   R   R)   R_   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_selected_text  s    c         C   s   |  j    j   d S(   s   Delete selected textN(   Rk   R   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   remove_selected_text  s    c         C   s   |  j    } | j   | d k	 r7 t | j    } n  | j   | d k	 rw t j t |  t |  t |   } n  | j |  | j	   d S(   s   Replace selected text by *text*
        If *pattern* is not None, replacing selected text using regular
        expression text substitutionN(
   Rk   t   beginEditBlockR   R   R   R   R   t   subR   t   endEditBlock(   R   R,   t   patternR4   t   seltxt(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR)     s    

c         C   sB  t  | j    } t  |  j    } y t j |  } Wn t j k
 rN d SX| t j @r t	 | j
   | j   g  } | |  } g  | j | d |  D] } | ^ q }	 |	 r |	 d }
 q d Sn0 t | j
   | j   g  } | j | |  }
 |
 r>|
 j   \ } } |  j   } | j |  | j | t j  | Sd S(   sh   Reimplement QTextDocument's find method
        
        Add support for *multiline* regular expressionsNi    i(   R   R   R`   R   t   compilet   sre_constantst   errorR   t   FindBackwardR   R   R   t   finditert   maxt   searcht   spanRk   Rs   R   R   (   R   t   regexpR4   t   findflagR   R,   t   regobjR   t   _mt   matchesR   t   pos1t   pos2t   fcursor(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   find_multiline_pattern  s*    
(c         C   s  |  j    } t j   } | s. | t j B} n  | rD | t j B} n  t j g }	 | r |	 t j t j g 7}	 | r t	 | j
    r t | j   | j   g  }
 | j |
  q | j t j  q n |	 t j g 7}	 | r t	 |  } n t j t	 |   } t rEt | r d j |  n |  } | r| j t j  qn< t | r]d j |  n | | rot j n t j t j  } x |	 D] } | j |  | rd | k r|  j | | |  } n |  j   j  | | |  } | d k	 r| j"   r|  j# |  t$ SqWt% S(   s	   Find textu   \b{}\bs   \nN(&   Rk   R   t   FindFlagR   t   FindCaseSensitivelyR   t   NoMoveR   Rp   R   R   R   R   R   Rs   Rl   R   Ro   R   R    t   QT55_VERSIONR   t   formatt   setPatternOptionst   CaseInsensitiveOptionR   R   t   CaseSensitivet   CaseInsensitivet   RegExp2R   R=   t   findR   t   isNullRy   RX   t   False(   R   R,   t   changedt   forwardt   caset   wordsR   R4   R   t   movest   new_positionR   R   t   found_cursor(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt	   find_text  sL    	'c         C   s   t  S(   s>   Needs to be overloaded in the codeeditor where it will be True(   R  (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt	   is_editor  s    R   c         C   s   t  |  } | s d S| s. t j |  } n  | sI t  |  j    } n  y1 | rd t j |  } n t j | t j  } Wn t j k
 r d SXd } x! | j	 |  D] } | d 7} q W| S(   s0   Get the number of matches for the searched text.i    i   N(
   R   R   R    R`   R   t
   IGNORECASER   R   R   R   (   R   R   t   source_textR  R   R   t   number_matchesR   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_number_matches  s"    c         C   sO   |  j    j   } |  j d d d |  } |  j | d | d | d | } | S(   s.   Get number of the match for the searched text.R   Rj   R   R  R  R   (   Rk   Rq   R   R  (   R   R   R  R   Rq   R  t   match_number(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_match_number1  s    c         C   s   |  j  t  d S(   R    N(   t   _enter_arrayRX   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   enter_array_inline;  s    c         C   s   |  j  t  d S(   R    N(   R  R  (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   enter_array_table?  s    c         C   sM  |  j  d  |  j  d  } |  j   } t |  | |  } | j   } | |  j   d } | j   | j   | j   d } | | j   d d } t | |  } | j	 |  j
 |   |  j   r |  j   } d }	 n t } d }	 | rI| j   rI| j   |	 }
 |
 d k rI|  j   } | j   | j |
  | j   qIn  d S(	   R    R4   Rg   i   i   i   s   
R   N(   R5   R?   R   R   R   R@   t   bottomt   heightR   R   RA   R
  t   is_python_likeRX   t   exec_R,   Rk   R   R   R   (   R   t   inlineR   t   rectt   dlgRC   RE   t   post   python_like_checkt   suffixR,   R4   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR  C  s*    $	
N(5   t   __name__t
   __module__R   R   R3   R  R   RU   R\   R_   Rf   R5   R<   Rw   Rx   R{   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R)   R   RX   R	  R
  R  R  R  R  R  (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR   -   sf   			/																		
					"							
		
			8	
		t   TracebackLinksMixinc           B   s>   e  Z d  Z d Z d Z d   Z d   Z d   Z d   Z	 RS(   R    c         C   s   t  |  _ |  j t  d  S(   N(   R  t$   _TracebackLinksMixin__cursor_changedt   setMouseTrackingRX   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR   i  s    	c         C   sj   |  j  j |  |  |  j | j    } t |  rf |  j   rf |  j d k	 rf |  j j |  qf n  d S(   s   Go to errorN(	   t   QT_CLASSt   mouseReleaseEventR   R  R   R   t   go_to_errorR   RZ   (   R   t   eventR,   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR$  n  s
    c         C   s   |  j  | j    } t |  rZ |  j sL t j t t j   t	 |  _ n  | j
   d S|  j ry t j   t |  _ n  |  j j |  |  d S(   s+   Show Pointing Hand Cursor on error messagesN(   R   R  R   R!  R   t   setOverrideCursorR   R   t   PointingHandCursorRX   t   acceptt   restoreOverrideCursorR  R#  t   mouseMoveEvent(   R   R&  R,   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR+  v  s    	
	
c         C   s6   |  j  r t j   t |  _  n  |  j j |  |  d S(   s.   If cursor has not been restored yet, do it nowN(   R!  R   R*  R  R#  t
   leaveEvent(   R   R&  (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR,    s    	
N(
   R  R  t   __doc__R   R#  R%  R   R$  R+  R,  (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR   d  s   			t   GetHelpMixinc           B   sG   e  Z d    Z d   Z d   Z d   Z e e d  Z e d  Z RS(   c         C   s   d  |  _ t |  _ d  S(   N(   R   t   helpR  t   help_enabled(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR     s    	c         C   s   | |  _  d S(   s   Set Help DockWidget referenceN(   R/  (   R   t   help_plugin(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   set_help  s    c         C   s   | |  _  d  S(   N(   R0  (   R   t   state(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   set_help_enabled  s    c         C   s   d } |  j  d d  } t j d |  } | rT | j | d  rT | | d 7} n  |  j  d d  } t j d |  } | r | j | d  r | | d 7} n  | r |  j | d	 t n  d  S(
   NR   Rg   R4   s   ([a-zA-Z_]+[0-9a-zA-Z_\.]*)iRh   s    ([0-9a-zA-Z_\.]+[0-9a-zA-Z_\.]*)i    t   force(   R   R   R   Rb   t
   startswitht   show_object_infoRX   (   R   R,   t   text1t   tl1t   text2t   tl2(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   inspect_current_object  s    c         C   s  t  |  } |  j p | } | rV |  j d k	 rV |  j j j t  |  j j j   n  | r |  j d k	 r |  j j j   r t	 |  d  r |  j j
 |   n |  j j
 |  j    |  j j | d t |  j   n  | r|  j r|  j |  } | d k	 r| r|  j |  } | j d  d } d } }	 t | t  rLg  } n  | rld d j |  d } nB |  j |  }
 |
 d k	 rt |
  } | st |
 |  }	 qn  | s|	 r| r| | } n |	 } |  j t d  | d	 t d
 d qqqn  d S(   s:   Show signature calltip and/or docstring in the Help plugint   get_doct   ignore_unknownt   .iR   R   R#   t	   ArgumentsR2   RJ   s   #2D62FFN(   R   R0  R/  R   t
   dockwidgett
   setVisibleRX   t   raise_t	   isVisiblet   hasattrt	   set_shellt   parentt   set_object_textR  t   setFocust   calltipst
   iscallablet   get_arglistR%   R7   R   R+   t
   get__doc__R	   R   RU   R   (   R   R,   t   callR5  R0  RK  t   arglistR.   t   argspecR2   t   docRQ   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR7    sD    
	c         C   s   t  |  j   d | S(   sB   
        Return the last valid object on the current line
        t   last(   R
   R   (   R   RR  (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   get_last_obj  s    (	   R  R  R   R2  R4  R<  R  R7  RS  (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR.    s   				4t   SaveHistoryMixinc           B   s>   e  Z d Z d Z g  Z d Z d  d  Z d   Z d   Z	 RS(   R   c         C   s   | |  _  |  j   d  S(   N(   t   history_filenamet   create_history_filename(   R   RU  (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR     s    	c         C   sQ   |  j  rM t j |  j   rM y t j |  j |  j   WqM t k
 rI qM Xn  d S(   s=   Create history_filename with INITHISTORY if it doesn't exist.N(   RU  t   ospt   isfileR   t
   writelinest   INITHISTORYt   EnvironmentError(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyRV    s
    c         C   s+  t  |  } | d	 k s' | j d  r+ d S| j d  rG | d  } n  d |  _ t |  j  d k r| |  j d | k r| d S|  j j |  t j	 | } |  j
 |  j k r |  j j |  j
  |  j | } n  y t j | |  j
 d d Wn t k
 r n X|  j d k	 r'|  j j |  j
 |  n  d S(
   s   Add command to historyR   s   
t	   TracebackNii    t   modet   ab(   R   s   
(   R   R6  Rb   R   t   histidxR(   t   historyR*   R]   R^   RU  t   HISTORY_FILENAMESt	   SEPARATORR   t   writeR[  t   append_to_historyRZ   (   R   t   commandR,   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   add_to_history  s&    	(N(
   R  R  R   RZ  Rb  Ra  Rd  R   RV  Rf  (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyRT    s   	t   BrowseHistoryMixinc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   g  |  _  d  |  _ t |  _ d  S(   N(   R`  R   R_  R  t   hist_wholeline(   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyR     s    		c         C   s   |  j  |  j d  d S(   s4   Clear current line (without clearing console prompt)Ri   N(   R   R   (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt
   clear_line  s    c         C   s   |  j  d  r$ |  j r$ t |  _ n  |  j   } |  j | |  j |  \ } |  _ | d k	 r |  j r |  j   |  j |  q |  j	 d  } |  j
 d d  |  j |  |  j |  n  d S(   s   Browse historyRh   R4   N(   R   Rh  R  R   t   find_in_historyR_  R   Ri  R   R5   R   R{   (   R   t   backwardt   tocursorR,   t   cursor_position(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   browse_history  s    	
c         C   sD  | d k r t |  j  } n  | r* d n d } | } t |  d k sQ |  j r | | 7} | t |  j  k s t |  j  d k r d t |  j  f S| d k  r d } n  t |  _ |  j | | f Sxv t t |  j   D]U } | | | d t |  j  } |  j | } | j |  r | t |  | f Sq Wd | f Sd S(   s7   Find text 'tocursor' in history, from index 'start_idx'ii   i    R   N(   R   R(   R`  Rh  RX   R~   R6  (   R   Rl  t	   start_idxRk  t   stept   idxt   indext   entry(    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyRj  .  s$    
*		c         C   s   d |  _ d S(   s3   Reset the position from which to search the historyN(   R   R_  (   R   (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   reset_search_posF  s    (   R  R  R   Ri  Rn  Rj  Rt  (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyRg    s
   				(1   R-  t   xml.sax.saxutilsR    R]   t   os.patht   pathRW  R   R   R&   t   qtpy.QtCoreR   R   t
   qtpy.QtGuiR   R   R   t   qtpy.QtWidgetsR   R   t   qtpyR   t   spyder_kernels.utils.dochelpersR	   R
   R   t   spyder.config.baseR   t   spyder.py3compatR   R   t   spyder.utilsR   R   R   t   spyder.utils.miscR   t   spyder.widgets.arraybuilderR   t   check_versionR   R   R   t   objectR   R   R.  RT  Rg  (    (    (    s4   lib/python2.7/site-packages/spyder/widgets/mixins.pyt   <module>   s6     9(T0