ž ¬ÿf«c@s~dZddlZddlZdd„ZGdd„dƒZedkrzdd „ZejeƒZe d e eƒƒndS( u:Simple textbox editing widget with Emacs-like keybindings.iNcCsð|j|d|tj||dƒ|j||dtj||dƒ|j||dtj||dƒ|j|d|tj||dƒ|j||tjƒ|j||tjƒ|j||tjƒ|j||tj ƒdS(u^Draw a rectangle with corners at the provided upper-left and lower-right coordinates. iN( uvlineucursesu ACS_VLINEuhlineu ACS_HLINEuaddchu ACS_ULCORNERu ACS_URCORNERu ACS_LRCORNERu ACS_LLCORNER(uwinuulyuulxulryulrx((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyu rectangles%%%%u rectanglecBsh|EeZdZdZddd„Zdd„Zdd„Zdd „Zd d „Z dd d „Z dS(uTextboxudEditing 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 cCsm||_||_|jƒ\|_|_|jd|_|jd|_d|_d|_|jdƒdS(Ni( uwinu insert_modeugetmaxyxumaxyumaxxu stripspacesuNoneulastcmdukeypad(uselfuwinu insert_mode((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyu__init__+s    uTextbox.__init__cCst|j}xdtjj|jj||ƒƒtjjkrSt|j|dƒ}Pn|dkrcPn|d}q |S(uuGo to the location of the first blank on the given line, returning the index of the last non-blank character.ii(umaxxucursesuasciiuwinuinchuSPumin(uselfuyulast((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyu _end_of_line5s -  uTextbox._end_of_linec Cs×|jjƒ\}}||jks3||jkrÓ|jrN|jjƒ}ny|jj|ƒWntjk ryYnX|jrÓ|jjƒ\}}tj j |ƒrÐ|j |ƒ|jj ||ƒqÐqÓndS(N( uwinugetyxumaxyumaxxu insert_modeuinchuaddchucursesuerroruasciiuisprintu_insert_printable_charumove(uselfuchuyuxuoldchubackyubackx((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyu_insert_printable_charBs   uTextbox._insert_printable_charcCse|jjƒ\}}||_tjj|ƒra||jksN||jkra|j|ƒqan|tjj kr‰|jj |dƒnØ|tjj tj tjj tjfkr`|dkrÙ|jj ||dƒnY|dkrènJ|jr|jj |d|j|dƒƒn|jj |d|jƒ|tjj tjfkra|jjƒqan|tjjkr‚|jjƒnß|tjjkrÕ|jr¼|jj ||j|ƒƒqa|jj ||jƒnŒ|tjjtjfkrE||jkr|jj ||dƒqa||jkr+qa|jj |ddƒn|tjjkr[dS|tjjkr¬|jdkr€dS||jkra|jj |ddƒqanµ|tjjkr|dkrï|j|ƒdkrï|jjƒqa|jj ||ƒ|jjƒnO|tjjkr4|jjƒn-|tjjtjfkr»||jkra|jj |d|ƒ||j|dƒkr¸|jj |d|j|dƒƒq¸qan¦|tjjkrÝ|jj ƒn„|tjj!tj"fkra|dkra|jj |d|ƒ||j|dƒkr^|jj |d|j|dƒƒq^qandS(u!Process a single editing command.ii(#uwinugetyxulastcmducursesuasciiuisprintumaxyumaxxu_insert_printable_charuSOHumoveuSTXuKEY_LEFTuBSu KEY_BACKSPACEu stripspacesu _end_of_lineudelchuEOTuENQuACKu KEY_RIGHTuBELuNLuVTudeletelnuclrtoeoluFFurefreshuSOuKEY_DOWNuSIuinsertlnuDLEuKEY_UP(uselfuchuyux((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyu do_commandTsp *   ' !- -uTextbox.do_commandc Csãd}xÖt|jdƒD]Á}|jj|dƒ|j|ƒ}|dkr]|jr]qnx_t|jdƒD]J}|jr||krPn|ttj j |jj ||ƒƒƒ}qqW|jdkr|d}qqW|S(u.Collect and return the contents of the window.uiiu ( urangeumaxyuwinumoveu _end_of_lineu stripspacesumaxxuchrucursesuasciiuinch(uselfuresultuyustopux((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyugather”s/uTextbox.gathercCs`xS|jjƒ}|r'||ƒ}n|s3qn|j|ƒsFPn|jjƒq|jƒS(u2Edit in the widget window and collect the results.(uwinugetchu do_commandurefreshugather(uselfuvalidateuch((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyuedit¤su Textbox.editNF( u__name__u __module__u __qualname__u__doc__uFalseu__init__u _end_of_lineu_insert_printable_charu do_commandugatheruNoneuedit(u __locals__((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyuTextboxs  @ uTextboxu__main__cCs‡d\}}d \}}|j|d|dƒtj||||ƒ}t||d|d||||ƒ|jƒt|ƒjƒS( Ni iiiiuUse Ctrl-G to end editing.i(i i(ii(uaddstrucursesunewwinu rectangleurefreshuTextboxuedit(ustdscruncolsunlinesuulyuulxuwin((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyu test_editbox²s  & u test_editboxuContents of text box:( u__doc__ucursesu curses.asciiu rectangleuTextboxu__name__u test_editboxuwrapperustruprinturepr(((u3/opt/alt/python33/lib64/python3.3/curses/textpad.pyus   ž