ó
‹²,]c           @   sl   d  Z  d d l m Z d d l m Z d d l m Z m Z d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d	 S(
   sµ   
A generic Emacs-style kill ring, as well as a Qt-specific version.

Adapted from qtconsole/kill_ring.py of the
`Jupyter QtConsole Project <https://github.com/jupyter/qtconsole>`_.
iÿÿÿÿ(   t   QObject(   t   QTextCursor(   t	   QTextEditt   QPlainTextEditt   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(    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyt   __init__   s    c         C   s   d |  _  g  |  _ d S(   s    Clears the kill ring.
        iÿÿÿÿN(   t   _indext   _ring(   R   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/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(    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/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   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/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   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   7   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/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   sl   t  | t t 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   R   t   AssertionErrort   superR   R   R   R	   R   t
   _prev_yankt   Falset   _skip_cursort
   _text_editt   cursorPositionChangedt   connectt   _cursor_position_changed(   R   t	   text_edit(    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   L   s    			c         C   s   |  j  j ƒ  d |  _ d S(   s    Clears the kill ring.
        N(   R	   R   R   R   (   R   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   Y   s    c         C   s   |  j  j | ƒ d S(   s,    Adds some killed text to the ring.
        N(   R	   R   (   R   R   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   _   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   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyt   kill_cursord   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"   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   l   s    	c         C   s{   |  j  rw |  j j ƒ  } | rw t |  _ |  j j ƒ  } | j t j	 t j
 d t |  j  ƒ ƒ| j | ƒ | |  _  qw 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   Leftt
   KeepAnchorR   R&   (   R   R   R"   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   v   s    			c         C   s"   |  j  r t |  _  n	 d  |  _ d  S(   N(   R   R   R   R   (   R   (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   Š   s    	(
   R   R   R   R   R   R   R#   R   R   R   (    (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyR   D   s   					
	N(   R   t   qtpy.QtCoreR    t
   qtpy.QtGuiR   t   qtpy.QtWidgetsR   R   t   objectR   R   (    (    (    sB   lib/python2.7/site-packages/spyder/widgets/sourcecode/kill_ring.pyt   <module>   s
   )