;
Σβ"Ic               @   sw   d  Z  d d l Z d d l Z d   Z Gd   d  Z e d k o/ d   Z e j e  Z e	 d e
 e   n d S(	   u:   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(   u^   Draw a rectangle with corners at the provided upper-left
    and lower-right coordinates.
    i   N(
   u   vlineu   cursesu	   ACS_VLINEu   hlineu	   ACS_HLINEu   addchu   ACS_ULCORNERu   ACS_URCORNERu   ACS_LRCORNERu   ACS_LLCORNER(   u   winu   ulyu   ulxu   lryu   lrx(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu	   rectangle   s    %%%%c             B   sP   |  Ee  Z d  Z d d  Z d   Z d   Z d   Z d   Z d d  Z
 d S(	   ud  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   (	   u   winu   insert_modeu   getmaxyxu   maxyu   maxxu   stripspacesu   Noneu   lastcmdu   keypad(   u   selfu   winu   insert_mode(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   __init__+   s    				c             C   sx   |  j  } xh t j j |  j j | |   t j j k o t |  j  | d  } Pn | d k o Pn | d } q | S(   uu   Go to the location of the first blank on the given line,
        returning the index of the last non-blank character.i   i    (   u   maxxu   cursesu   asciiu   winu   inchu   SPu   min(   u   selfu   yu   last(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   _end_of_line5   s    	.c          	   C   sβ   |  j  j   \ } } | |  j k  p | |  j k  o© |  j o |  j  j   } n y |  j  j |  Wn t j k
 o Yn X|  j oP |  j  j   \ } } t j	 j
 |  o$ |  j |  |  j  j | |  qΪ qή n d  S(   N(   u   winu   getyxu   maxyu   maxxu   insert_modeu   inchu   addchu   cursesu   erroru   asciiu   isprintu   _insert_printable_charu   move(   u   selfu   chu   yu   xu   oldchu   backyu   backx(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   _insert_printable_charB   s     

c             C   s  |  j  j   \ } } | |  _ t j j |  o5 | |  j k  p | |  j k  o |  j |  qn6| t j j	 k o |  j  j
 | d  n| t j j t j t j j t j f k oΆ | d k o |  j  j
 | | d  n^ | d k o nM |  j o( |  j  j
 | d |  j | d   n |  j  j
 | d |  j  | t j j t j f k o |  j  j   qn+| t j j k o |  j  j   n| t j j k oD |  j o  |  j  j
 | |  j |   q|  j  j
 | |  j  n°| t j j t j f k oZ | |  j k  o |  j  j
 | | d  q| |  j k o q|  j  j
 | d d  n:| t j j k o d S| t j j k oD |  j d k o d S| |  j k  o |  j  j
 | d d  qnΛ| t j j k oX | d k o' |  j |  d k o |  j  j   q|  j  j
 | |  |  j  j   n`| t j j k o |  j  j   n<| t j j t j f k oq | |  j k  o] |  j  j
 | d |  | |  j | d  k o( |  j  j
 | d |  j | d   qιqn― | t j j k o |  j  j    n | t j j! t j" f k on | d k o] |  j  j
 | d |  | |  j | d  k o( |  j  j
 | d |  j | d   qqn d S(   u!   Process a single editing command.i    i   (#   u   winu   getyxu   lastcmdu   cursesu   asciiu   isprintu   maxyu   maxxu   _insert_printable_charu   SOHu   moveu   STXu   KEY_LEFTu   BSu   KEY_BACKSPACEu   stripspacesu   _end_of_lineu   delchu   EOTu   ENQu   ACKu	   KEY_RIGHTu   BELu   NLu   VTu   deletelnu   clrtoeolu   FFu   refreshu   SOu   KEY_DOWNu   SIu   insertlnu   DLEu   KEY_UP(   u   selfu   chu   yu   x(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu
   do_commandT   sp    	 +
(
 #00c             C   sλ   d } xή t  |  j d  D]Ι } |  j j | d  |  j |  } | d k o |  j o q n xb t  |  j d  D]M } |  j o | | k o Pn | t t j	 j	 |  j j
 | |    } qt W|  j d k o | d } q q W| S(   u.   Collect and return the contents of the window.u    i   i    u   
(   u   rangeu   maxyu   winu   moveu   _end_of_lineu   stripspacesu   maxxu   chru   cursesu   asciiu   inch(   u   selfu   resultu   yu   stopu   x(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   gather   s      /c             C   sf   xY |  j  j   } | o | |  } n | p q n |  j |  p Pn |  j  j   q |  j   S(   u2   Edit in the widget window and collect the results.(   u   winu   getchu
   do_commandu   refreshu   gather(   u   selfu   validateu   ch(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   edit€   s    NF(   u   __name__u
   __module__u   __doc__u   Falseu   __init__u   _end_of_lineu   _insert_printable_charu
   do_commandu   gatheru   Noneu   edit(   u
   __locals__(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   Textbox   s   

			@	u   Textboxu   __main__c             C   s   d \ } } d	 \ } } |  j  | d | d  t j | | | |  } t |  | d | d | | | |  |  j   t |  j   S(
   Ni	   i   i   i   i   u   Use Ctrl-G to end editing.i   (   i	   i   (   i   i   (   u   addstru   cursesu   newwinu	   rectangleu   refreshu   Textboxu   edit(   u   stdscru   ncolsu   nlinesu   ulyu   ulxu   win(    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   test_editbox²   s    &
u   Contents of text box:(   u   __doc__u   cursesu   curses.asciiu	   rectangleu   Textboxu   __name__u   test_editboxu   wrapperu   stru   printu   repr(    (    (    u+   /mit/python/lib/python3.0/curses/textpad.pyu   <module>   s   			