ó
è¾bc           @   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   sS   e  Z d  Z e d „ Z 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   s?   | |  _  | |  _ |  j ƒ  d |  _ d  |  _ | j d ƒ d  S(   Ni   (   R
   t   insert_modet   _update_max_yxt   stripspacest   Nonet   lastcmdt   keypad(   t   selfR
   R   (    (    s$   /usr/lib/python2.7/curses/textpad.pyt   __init__+   s    		
		c         C   s3   |  j  j ƒ  \ } } | d |  _ | d |  _ d  S(   Ni   (   R
   t   getmaxyxt   maxyt   maxx(   R   R   R   (    (    s$   /usr/lib/python2.7/curses/textpad.pyR   3   s    c         C   s…   |  j  ƒ  |  j } xk t r€ t j j |  j j | | ƒ ƒ t j j k rc t |  j | d ƒ } Pn | d k rs 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   R   t   TrueR   t   asciiR
   t   incht   SPt   min(   R   t   yt   last(    (    s$   /usr/lib/python2.7/curses/textpad.pyt   _end_of_line8   s    
		-c         C   s
  |  j  ƒ  |  j j ƒ  \ } } d  } x¿ | |  j k  sF | |  j k  ræ |  j ra |  j j ƒ  } n  y |  j j | ƒ Wn t	 j
 k
 r‹ n X|  j s© t	 j j | ƒ r­ Pn  | } |  j j ƒ  \ } } | d  k r( | | f } q( q( W| d  k	 r|  j j | Œ  n  d  S(   N(   R   R
   t   getyxR   R   R   R   R   R   R   t   errorR   t   isprintt   move(   R   t   chR!   t   xt   backyxt   oldch(    (    s$   /usr/lib/python2.7/curses/textpad.pyt   _insert_printable_charF   s$    
!	c         C   so  |  j  ƒ  |  j j ƒ  \ } } | |  _ t j j | ƒ rk | |  j k  sX | |  j k  rk|  j	 | ƒ qkn | t j j
 k r“ |  j j | d ƒ nØ| t j j t j t j j t j f k rj| 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 rk|  j j ƒ  qkn| t j j k rŒ|  j j ƒ  nß| t j j k rß|  j rÆ|  j j | |  j | ƒ ƒ qk|  j j | |  j ƒ nŒ| t j j t j f k rO| |  j k  r#|  j j | | d ƒ qk| |  j k r5qk|  j j | d d ƒ n| t j j k red S| t j j k r¶|  j d k rŠd S| |  j k  rk|  j j | d d ƒ qknµ| t j j k r| d k rù|  j | ƒ d k rù|  j j ƒ  qk|  j j | | ƒ |  j j ƒ  nO| t j j k r>|  j j ƒ  n-| t j j t j f k rÅ| |  j k  rk|  j j | d | ƒ | |  j | d ƒ k rÂ|  j j | d |  j | d ƒ ƒ qÂqkn¦ | t j j  k rç|  j j! ƒ  n„ | t j j" t j# f k rk| d k rk|  j j | d | ƒ | |  j | d ƒ k rh|  j j | d |  j | d ƒ ƒ qhqkn  d S(   s!   Process a single editing command.i    i   ($   R   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_command_   sr    
	*	'	!--c         C   sí   d } |  j  ƒ  xÖ t |  j d ƒ D]Á } |  j j | d ƒ |  j | ƒ } | d k rg |  j rg q$ n  x_ t |  j d ƒ D]J } |  j rš | | k rš Pn  | t t	 j
 j
 |  j j | | ƒ ƒ ƒ } q{ W|  j d k r$ | d } q$ q$ W| S(   s.   Collect and return the contents of the window.t    i   i    s   
(   R   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#   R,   RD   RJ   R   RM   (    (    (    s$   /usr/lib/python2.7/curses/textpad.pyR      s   				A	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   	«		