ó
_y]c           @   sZ   d  d l  m Z d  d l m Z d  d l m Z d d l m Z d e f d „  ƒ  YZ d S(	   iÿÿÿÿ(   t   QtGui(   t   unicode_type(   t   Booli   (   t   ConsoleWidgett   HistoryConsoleWidgetc           B   s’   e  Z d  Z e e d e ƒZ d „  Z d „  Z d „  Z	 d „  Z
 d e d „ Z d e d „ Z d	 d
 „ Z d „  Z d „  Z d „  Z d „  Z RS(   s“    A ConsoleWidget that keeps a history of the commands that have been
        executed and provides a readline-esque interface to this history.
    t   configc         O   sA   t  t |  ƒ j | | Ž  g  |  _ i  |  _ d |  _ d |  _ d  S(   Ni    t    (   t   superR   t   __init__t   _historyt   _history_editst   _history_indext   _history_prefix(   t   selft   argst   kw(    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR      s
    			c         C   s¡   | d k r |  j n | } t t |  ƒ j | | | ƒ | r | j ƒ  } | r |  j sl |  j d | k r |  j j | ƒ n  i  |  _ t	 |  j ƒ |  _
 n  d S(   s%    Reimplemented to the store history. iÿÿÿÿN(   t   Nonet   input_bufferR   R   t
   do_executet   rstripR	   t   appendR
   t   lenR   (   R   t   sourcet   completet   indentt   history(    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR   '   s    #	c   
      C   s¯  |  j  ƒ  } |  j ƒ  j ƒ  | j ƒ  k r«|  j ƒ  rA | rA t S|  j ƒ  } |  j } t | t |  j	 ƒ ƒ } |  j	 |  | |  k rš t |  j
 ƒ |  _ n  |  j ƒ  } | j ƒ  } | j t j j ƒ | j ƒ  | k } |  j t |  j
 ƒ k s&|  j	 d k o| s&|  j |  j ƒ |  | |  k r6| |  |  _	 n  |  j |  j	 d | ƒ|  j  ƒ  }	 |  j	 r‡|	 j t j j d t |  j	 ƒ ƒn |	 j t j j ƒ |  j |	 ƒ t St S(   sj    Called when the up key is pressed. Returns whether to continue
            processing the event.
        R   t	   as_prefixt   n(   t   _get_prompt_cursort   _get_cursort   blockNumbert   _history_lockedt   Falset   _get_input_buffer_cursor_posR   t   minR   R   R	   R   t   positiont   movePositionR    t   QTextCursort
   EndOfBlockt   _get_edited_historyt   history_previoust   Rightt   _set_cursort   True(
   R   t   shift_modifiert   prompt_cursort   posR   R   t   ct   current_post   at_eolt   cursor(    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyt   _up_pressed>   s6    	!	c         C   s¯   |  j  ƒ  } |  j ƒ  j ƒ  | j ƒ  k r« |  j ƒ  rA | rA t S|  j |  j d | ƒ} |  j r§ | r§ |  j ƒ  } | j t	 j
 j d t |  j ƒ ƒ|  j | ƒ n  t St S(   sl    Called when the down key is pressed. Returns whether to continue
            processing the event.
        R   R   (   t   _get_end_cursorR   R   R   R    t   history_nextR   R   R$   R    R%   R)   R   R*   R+   (   R   R,   t
   end_cursort   replacedR2   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyt   _down_pressedv   s    
R   c         C   s–   |  j  } t } x[ | d k rl | d 8} |  j | ƒ } | rL | j | ƒ s_ | r | | k r t } Pq q W| r’ |  j ƒ  | |  _  | |  _ n  | S(   sŽ   If possible, set the input buffer to a previous history item.

        Parameters
        ----------
        substring : str, optional
            If specified, search for an item with this substring.
        as_prefix : bool, optional
            If True, the substring must match at the beginning (default).

        Returns
        -------
        Whether the input buffer was changed.
        i    i   (   R   R    R'   t
   startswithR+   t   _store_editsR   (   R   t	   substringR   t   indext   replaceR   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR(   –   s    	

	c         C   sŸ   |  j  } t } xd | t |  j ƒ k  ru | d 7} |  j | ƒ } | rU | j | ƒ sh | r | | k r t } Pq q W| r› |  j ƒ  | |  _  | |  _ n  | S(   s   If possible, set the input buffer to a subsequent history item.

        Parameters
        ----------
        substring : str, optional
            If specified, search for an item with this substring.
        as_prefix : bool, optional
            If True, the substring must match at the beginning (default).

        Returns
        -------
        Whether the input buffer was changed.
        i   (	   R   R    R   R	   R'   R9   R+   R:   R   (   R   R;   R   R<   R=   R   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR5   µ   s    	

	i
   c         C   s   |  j  | S(   s–    Get the local history list.

        Parameters
        ----------
        n : int
            The (maximum) number of history items to get.
        (   R	   (   R   R   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyt   history_tailÔ   s    c         C   sF   |  j  oE |  j |  j ƒ |  j k oE |  j ƒ  j ƒ  |  j ƒ  j ƒ  k S(   s5    Returns whether history movement is locked.
        (   t   history_lockR'   R   R   R   R   R4   (   R   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR   â   s
    	c         C   sA   | |  j  k r |  j  | S| t |  j ƒ k r6 t ƒ  S|  j | S(   sB    Retrieves a history item, possibly with temporary edits.
        (   R
   R   R	   R   (   R   R<   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR'   ë   s
    c         C   s.   t  | ƒ |  _ i  |  _ t |  j ƒ |  _ d S(   sG    Replace the current history with a sequence of history items.
        N(   t   listR	   R
   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyt   _set_historyô   s    	c         C   sN   |  j  } |  j t |  j ƒ k s7 |  j |  j | k rJ | |  j |  j <n  d S(   sE    If there are edits to the current input buffer, store them.
        N(   R   R   R   R	   R
   (   R   t   current(    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR:   û   s    	(   t   __name__t
   __module__t   __doc__R   R    R+   R?   R   R   R3   R8   R(   R5   R>   R   R'   RA   R:   (    (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyR      s   			8	 					N(	   t   qtconsole.qtR    t   ipython_genutils.py3compatR   t	   traitletsR   t   console_widgetR   R   (    (    (    s?   lib/python2.7/site-packages/qtconsole/history_console_widget.pyt   <module>   s   