³ò
 ›\Kc           @   sv   d  Z  d d k Z d d k Z d „  Z d d	 d „  ƒ  YZ e d j o+ d „  Z e i e ƒ Z d Ge	 e ƒ GHn d S(
   s:   Simple textbox editing widget with Emacs-like keybindings.iÿÿÿÿNc         C   sð   |  i  | d | t i | | d ƒ |  i | | d t i | | d ƒ |  i | | d t i | | d ƒ |  i  | d | t i | | d ƒ |  i | | t i ƒ |  i | | t i ƒ |  i | | t i ƒ |  i | | t i	 ƒ 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.5/curses/textpad.pyt	   rectangle   s    %%%%t   Textboxc           B   s>   e  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   sd   | |  _  | i ƒ  \ |  _ |  _ |  i d |  _ |  i d |  _ d |  _ d  |  _ | i d ƒ d  S(   Ni   (   R
   t   getmaxyxt   maxyt   maxxt   stripspacest   Nonet   lastcmdt   keypad(   t   selfR
   (    (    s$   /usr/lib/python2.5/curses/textpad.pyt   __init__*   s    			c         C   sr   |  i  } xb t i |  i i | | ƒ ƒ t i j o t |  i  | d ƒ } Pn | d j o Pn | d } q | S(   s8   Go to the location of the first blank on the given line.i   i    (   R   t   asciiR
   t   incht   SPt   min(   R   t   yt   last(    (    s$   /usr/lib/python2.5/curses/textpad.pyt   _end_of_line3   s    	(c         C   s˜  |  i  i ƒ  \ } } | |  _ t i | ƒ oU | |  i j  p | |  i j  o1 y |  i  i | ƒ Wq t i	 j
 o q Xq”n| t i
 j o |  i  i | d ƒ në| t i t i t i t i f j o³ | d j o |  i  i | | d ƒ n^ | d j o nM |  i o( |  i  i | d |  i | d ƒ ƒ n |  i  i | d |  i ƒ | t i t i f j o |  i  i ƒ  q”n| t i j o |  i  i ƒ  nò| t i j oD |  i o  |  i  i | |  i | ƒ ƒ q”|  i  i | |  i ƒ nž| t i t i f j oZ | |  i j  o |  i  i | | d ƒ q”| |  i j o q”|  i  i | d d ƒ n+| t i j o d Sn| t i j oG |  i d j o d Sq”| |  i j  o |  i  i | d d ƒ q”n¼| t i j oX | d j o' |  i | ƒ d j o |  i  i ƒ  q”|  i  i | | ƒ |  i  i ƒ  nT| t i j o |  i  i ƒ  n3| t i t i f j oq | |  i j  o] |  i  i | d | ƒ | |  i | d ƒ j o( |  i  i | d |  i | d ƒ ƒ qèq”n© | t i  j o |  i  i! ƒ  nˆ | t i" t i# f j on | d j o] |  i  i | d | ƒ | |  i | d ƒ j o( |  i  i | d |  i | d ƒ ƒ qq”n d S(   s!   Process a single editing command.i    i   ($   R
   t   getyxR   R   t   isprintR   R   R   R   t   errort   SOHt   movet   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   t   chR   t   x(    (    s$   /usr/lib/python2.5/curses/textpad.pyt
   do_command?   sv    	 %
(
 #00c         C   sè   d } xÛ t  |  i d ƒ D]Æ } |  i i | d ƒ |  i | ƒ } | d j o |  i o q n x_ t  |  i d ƒ D]J } |  i o | | j o Pn | t t i |  i i	 | | ƒ ƒ ƒ } qt W|  i d j o | 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   t   resultR   t   stopR=   (    (    s$   /usr/lib/python2.5/curses/textpad.pyt   gather…   s      ,c         C   sf   xY |  i  i ƒ  } | o | | ƒ } n | p q n |  i | ƒ p Pn |  i  i ƒ  q |  i ƒ  S(   s2   Edit in the widget window and collect the results.(   R
   t   getchR>   R5   RD   (   R   t   validateR<   (    (    s$   /usr/lib/python2.5/curses/textpad.pyt   edit•   s    N(	   t   __name__t
   __module__t   __doc__R   R    R>   RD   R   RG   (    (    (    s$   /usr/lib/python2.5/curses/textpad.pyR      s   				F	t   __main__c         C   s‡   d \ } } d	 \ } } |  i  | d | d ƒ t i | | | | ƒ } t |  | d | d | | | | ƒ |  i ƒ  t | ƒ i ƒ  S(
   Ni	   i   i   i   i   s   Use Ctrl-G to end editing.i   (   i	   i   (   i   i   (   t   addstrR   t   newwinR   R5   R   RG   (   t   stdscrt   ncolst   nlinesR   R   R
   (    (    s$   /usr/lib/python2.5/curses/textpad.pyt   test_editbox£   s    &
s   Contents of text box:(    (
   RJ   R   R   R   R   RH   RQ   t   wrappert   strt   repr(    (    (    s$   /usr/lib/python2.5/curses/textpad.pys   <module>   s   			