ó
jQ=`c           @   st   d  Z  d d l Z d d l Z d „  Z d d	 d „  ƒ  YZ e d k rp d „  Z e j e ƒ Z d Ge	 e ƒ GHn  d S(
   s:   Simple textbox editing widget with Emacs-like keybindings.iÿÿÿÿNc         C   sð   |  j  | d | t j | | d ƒ |  j | | d t j | | d ƒ |  j | | d t j | | d ƒ |  j  | d | t j | | d ƒ |  j | | t j ƒ |  j | | t j ƒ |  j | | t j ƒ |  j | | t j	 ƒ d S(   s^   Draw a rectangle with corners at the provided upper-left
    and lower-right coordinates.
    i   N(
   t   vlinet   cursest	   ACS_VLINEt   hlinet	   ACS_HLINEt   addcht   ACS_ULCORNERt   ACS_URCORNERt   ACS_LRCORNERt   ACS_LLCORNER(   t   wint   ulyt   ulxt   lryt   lrx(    (    s$   /usr/lib/python2.7/curses/textpad.pyt	   rectangle   s    %%%%t   Textboxc           B   sJ   e  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z
 RS(   sd  Editing widget using the interior of a window object.
     Supports the following Emacs-like key bindings:

    Ctrl-A      Go to left edge of window.
    Ctrl-B      Cursor left, wrapping to previous line if appropriate.
    Ctrl-D      Delete character under cursor.
    Ctrl-E      Go to right edge (stripspaces off) or end of line (stripspaces on).
    Ctrl-F      Cursor right, wrapping to next line when appropriate.
    Ctrl-G      Terminate, returning the window contents.
    Ctrl-H      Delete character backward.
    Ctrl-J      Terminate if the window is 1 line, otherwise insert newline.
    Ctrl-K      If line is blank, delete it, otherwise clear to end of line.
    Ctrl-L      Refresh screen.
    Ctrl-N      Cursor down; move down one line.
    Ctrl-O      Insert a blank line at cursor location.
    Ctrl-P      Cursor up; move up one line.

    Move operations do nothing if the cursor is at an edge where the movement
    is not possible.  The following synonyms are supported where possible:

    KEY_LEFT = Ctrl-B, KEY_RIGHT = Ctrl-F, KEY_UP = Ctrl-P, KEY_DOWN = Ctrl-N
    KEY_BACKSPACE = Ctrl-h
    c         C   sm   | |  _  | |  _ | j ƒ  \ |  _ |  _ |  j d |  _ |  j d |  _ d |  _ d  |  _ | j d ƒ d  S(   Ni   (	   R
   t   insert_modet   getmaxyxt   maxyt   maxxt   stripspacest   Nonet   lastcmdt   keypad(   t   selfR
   R   (    (    s$   /usr/lib/python2.7/curses/textpad.pyt   __init__+   s    				c         C   s{   |  j  } xk t rv t j j |  j j | | ƒ ƒ t j j k rY t |  j  | d ƒ } Pn | d k ri Pn  | d } q W| S(   su   Go to the location of the first blank on the given line,
        returning the index of the last non-blank character.i   i    (   R   t   TrueR   t   asciiR
   t   incht   SPt   min(   R   t   yt   last(    (    s$   /usr/lib/python2.7/curses/textpad.pyt   _end_of_line5   s    		-c         C   sÖ   |  j  j ƒ  \ } } | |  j k  s3 | |  j k  rÒ |  j rN |  j  j ƒ  } n  y |  j  j | ƒ Wn t j k
 rx n X|  j rÒ |  j  j ƒ  \ } } t j	 j
 | ƒ rÏ |  j | ƒ |  j  j | | ƒ qÏ qÒ n  d  S(   N(   R
   t   getyxR   R   R   R   R   R   t   errorR   t   isprintt   _insert_printable_chart   move(   R   t   chR    t   xt   oldcht   backyt   backx(    (    s$   /usr/lib/python2.7/curses/textpad.pyR&   B   s    		c         C   se  |  j  j ƒ  \ } } | |  _ t j j | ƒ ra | |  j k  sN | |  j k  ra|  j | ƒ qan | t j j	 k r‰ |  j  j
 | d ƒ nØ| t j j t j t j j t j f k r`| d k rÙ |  j  j
 | | d ƒ nY | d k rè nJ |  j r|  j  j
 | d |  j | d ƒ ƒ n |  j  j
 | d |  j ƒ | t j j t j f k ra|  j  j ƒ  qan| t j j k r‚|  j  j ƒ  nß| t j j k rÕ|  j r¼|  j  j
 | |  j | ƒ ƒ qa|  j  j
 | |  j ƒ nŒ| t j j t j f k rE| |  j k  r|  j  j
 | | d ƒ qa| |  j k r+qa|  j  j
 | d d ƒ n| t j j k r[d S| t j j k r¬|  j d k r€d S| |  j k  ra|  j  j
 | d d ƒ qanµ| t j j k r| d k rï|  j | ƒ d k rï|  j  j ƒ  qa|  j  j
 | | ƒ |  j  j ƒ  nO| t j j k r4|  j  j ƒ  n-| t j j t j f k r»| |  j k  ra|  j  j
 | d | ƒ | |  j | d ƒ k r¸|  j  j
 | d |  j | d ƒ ƒ q¸qan¦ | t j j k rÝ|  j  j  ƒ  n„ | t j j! t j" f k ra| d k ra|  j  j
 | d | ƒ | |  j | d ƒ k r^|  j  j
 | d |  j | d ƒ ƒ q^qan  d S(   s!   Process a single editing command.i    i   (#   R
   R#   R   R   R   R%   R   R   R&   t   SOHR'   t   STXt   KEY_LEFTt   BSt   KEY_BACKSPACER   R"   t   delcht   EOTt   ENQt   ACKt	   KEY_RIGHTt   BELt   NLt   VTt   deletelnt   clrtoeolt   FFt   refresht   SOt   KEY_DOWNt   SIt   insertlnt   DLEt   KEY_UP(   R   R(   R    R)   (    (    s$   /usr/lib/python2.7/curses/textpad.pyt
   do_commandT   sp    	*	'	!--c         C   sã   d } xÖ t  |  j d ƒ D]Á } |  j j | d ƒ |  j | ƒ } | d k r] |  j r] q n  x_ t  |  j d ƒ D]J } |  j r | | k r Pn  | t t j	 j	 |  j j
 | | ƒ ƒ ƒ } qq W|  j d k r | d } q q W| S(   s.   Collect and return the contents of the window.t    i   i    s   
(   t   rangeR   R
   R'   R"   R   R   t   chrR   R   R   (   R   t   resultR    t   stopR)   (    (    s$   /usr/lib/python2.7/curses/textpad.pyt   gather”   s    /c         C   sa   xT |  j  j ƒ  } | r' | | ƒ } n  | s3 q n  |  j | ƒ sF Pn  |  j  j ƒ  q W|  j ƒ  S(   s2   Edit in the widget window and collect the results.(   R
   t   getchRD   R=   RJ   (   R   t   validateR(   (    (    s$   /usr/lib/python2.7/curses/textpad.pyt   edit¤   s    N(   t   __name__t
   __module__t   __doc__t   FalseR   R"   R&   RD   RJ   R   RM   (    (    (    s$   /usr/lib/python2.7/curses/textpad.pyR      s   
			@	t   __main__c         C   s‡   d \ } } d	 \ } } |  j  | d | d ƒ t j | | | | ƒ } t |  | d | d | | | | ƒ |  j ƒ  t | ƒ j ƒ  S(
   Ni	   i   i   i   i   s   Use Ctrl-G to end editing.i   (   i	   i   (   i   i   (   t   addstrR   t   newwinR   R=   R   RM   (   t   stdscrt   ncolst   nlinesR   R   R
   (    (    s$   /usr/lib/python2.7/curses/textpad.pyt   test_editbox²   s    &
s   Contents of text box:(    (
   RP   R   t   curses.asciiR   R   RN   RX   t   wrappert   strt   repr(    (    (    s$   /usr/lib/python2.7/curses/textpad.pyt   <module>   s   	ž		