
_y]c           @   sO   d  Z  d d l m Z m Z d e f d     YZ d e j f d     YZ d S(   sD    A generic Emacs-style kill ring, as well as a Qt-specific version.
i(   t   QtCoret   QtGuit   KillRingc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s&    A generic Emacs-style kill ring.
    c         C   s   |  j    d  S(   N(   t   clear(   t   self(    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyt   __init__   s    c         C   s   d |  _  g  |  _ d S(   s    Clears the kill ring.
        iN(   t   _indext   _ring(   R   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR      s    	c         C   s   |  j  j |  d S(   s,    Adds some killed text to the ring.
        N(   R   t   append(   R   t   text(    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyt   kill   s    c         C   s   t  |  j  |  _ |  j   S(   sr    Yank back the most recently killed text.

        Returns
        -------
        A text string or None.
        (   t   lenR   R   t   rotate(   R   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyt   yank    s    c         C   s0   |  j  d 8_  |  j  d k r, |  j |  j  Sd S(   s{    Rotate the kill ring, then yank back the new top.

        Returns
        -------
        A text string or None.
        i   i    N(   R   R   t   None(   R   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   *   s    (   t   __name__t
   __module__t   __doc__R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR      s   				
t
   QtKillRingc           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s/    A kill ring attached to Q[Plain]TextEdit.
    c         C   sr   t  | t j t j f  s! t  t t |   j   t   |  _	 d |  _ t |  _ | |  _ | j j |  j  d S(   sD    Create a kill ring attached to the specified Qt text edit.
        N(   t
   isinstanceR   t	   QTextEditt   QPlainTextEditt   AssertionErrort   superR   R   R   R   R   t
   _prev_yankt   Falset   _skip_cursort
   _text_editt   cursorPositionChangedt   connectt   _cursor_position_changed(   R   t	   text_edit(    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   >   s    !			c         C   s   |  j  j   d |  _ d S(   s    Clears the kill ring.
        N(   R   R   R   R   (   R   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   K   s    c         C   s   |  j  j |  d S(   s,    Adds some killed text to the ring.
        N(   R   R
   (   R   R	   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR
   Q   s    c         C   s0   | j    } | r, | j   |  j |  n  d S(   s5    Kills the text selected by the give cursor.
        N(   t   selectedTextt   removeSelectedTextR
   (   R   t   cursorR	   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyt   kill_cursorV   s    
c         C   sJ   |  j  j   } | rF t |  _ |  j j   } | j |  | |  _ n  d S(   s2    Yank back the most recently killed text.
        N(   R   R   t   TrueR   R   t
   textCursort
   insertTextR   (   R   R	   R"   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   ^   s    	c         C   s   |  j  r} |  j j   } | r} t |  _ |  j j   } | j t j	 j
 t j	 j d t |  j   | j |  | |  _  q} n  d S(   s;    Rotate the kill ring, then yank back the new top.
        t   nN(   R   R   R   R$   R   R   R%   t   movePositionR   t   QTextCursort   Leftt
   KeepAnchorR   R&   (   R   R	   R"   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   h   s    		c         C   s"   |  j  r t |  _  n	 d  |  _ d  S(   N(   R   R   R   R   (   R   (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   |   s    	(
   R   R   R   R   R   R
   R#   R   R   R   (    (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyR   6   s   					
	N(   R   t   qtconsole.qtR    R   t   objectR   t   QObjectR   (    (    (    s2   lib/python2.7/site-packages/qtconsole/kill_ring.pyt   <module>   s   (