Ñò
$8Zc           @   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.6/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   | |  _  | |  _ | i ƒ  \ |  _ |  _ |  i d |  _ |  i d |  _ d |  _ d  |  _ | i d ƒ d  S(   Ni   (	   R
   t   insert_modet   getmaxyxt   maxyt   maxxt   stripspacest   Nonet   lastcmdt   keypad(   t   selfR
   R   (    (    s$   /usr/lib/python2.6/curses/textpad.pyt   __init__+   s    				c         C   s   |  i  } xq t oi t i i |  i i | | ƒ ƒ t i i j o t |  i  | d ƒ } Pn | d j o 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.6/curses/textpad.pyt   _end_of_line5   s    	 .c         C   sá   |  i  i ƒ  \ } } | |  i j  p | |  i j  o¨ |  i o |  i  i ƒ  } n y |  i  i | ƒ Wn t i j
 o n X|  i oP |  i  i ƒ  \ } } t i	 i
 | ƒ o$ |  i | ƒ |  i  i | | ƒ 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.6/curses/textpad.pyR&   B   s     

c         C   sŸ  |  i  i ƒ  \ } } | |  _ t i i | ƒ o5 | |  i j  p | |  i j  o |  i | ƒ q›n6| t i i	 j o |  i  i
 | d ƒ n| t i i t i t i 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 i t i f j o |  i  i ƒ  q›n+| t i i j o |  i  i ƒ  n| t i i j oD |  i o  |  i  i
 | |  i | ƒ ƒ q›|  i  i
 | |  i ƒ n°| t i i t i f j oZ | |  i j  o |  i  i
 | | d ƒ q›| |  i j o q›|  i  i
 | d d ƒ n:| t i i j o d S| t i i j oD |  i d j o d S| |  i j  o |  i  i
 | d d ƒ q›nË| t i i j oX | d j o' |  i | ƒ d j o |  i  i ƒ  q›|  i  i
 | | ƒ |  i  i ƒ  n`| t i i j o |  i  i ƒ  n<| t i 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 i j o |  i  i  ƒ  n‹ | t i 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
   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.6/curses/textpad.pyt
   do_commandT   sp    	 +
(
 #00c         C   së   d } xÞ t  |  i d ƒ D]É } |  i i | d ƒ |  i | ƒ } | d j o |  i o q n xb t  |  i d ƒ D]M } |  i o | | j o Pn | t t i	 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   (   R   t   resultR    t   stopR)   (    (    s$   /usr/lib/python2.6/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   getchRD   R=   RJ   (   R   t   validateR(   (    (    s$   /usr/lib/python2.6/curses/textpad.pyt   edit¤   s    N(   t   __name__t
   __module__t   __doc__t   FalseR   R"   R&   RD   RJ   R   RM   (    (    (    s$   /usr/lib/python2.6/curses/textpad.pyR      s   
			@	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   R=   R   RM   (   t   stdscrt   ncolst   nlinesR   R   R
   (    (    s$   /usr/lib/python2.6/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.6/curses/textpad.pyt   <module>   s   	ž		