mς &U²Ic@spdZdkZdkZd„Zdfd„ƒYZedjo+d„ZeieƒZdGe eƒGHndS(s:Simple textbox editing widget with Emacs-like keybindings.NcCsπ|i|d|ti||dƒ|i||dti||dƒ|i||dti||dƒ|i|d|ti||dƒ|i ||ti ƒ|i ||ti ƒ|i ||ti ƒ|i ||tiƒdS(s^Draw a rectangle with corners at the provided upper-left and lower-right coordinates. iN(twintvlinetulytulxtcursest ACS_VLINEtlrythlinet ACS_HLINEtlrxtaddcht ACS_ULCORNERt ACS_URCORNERt ACS_LRCORNERt ACS_LLCORNER(RRRRR ((t+/data/zmath/lib/python2.4/curses/textpad.pyt rectangles%%%%tTextboxcBs>tZdZd„Zd„Zd„Zd„Zed„ZRS(sdEditing 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 cCsd||_|iƒ\|_|_|id|_|id|_d|_d|_|idƒdS(Ni( Rtselftgetmaxyxtmaxytmaxxt stripspacestNonetlastcmdtkeypad(RR((Rt__init__*s   cCst|i}xdti|ii||ƒƒtijot|i|dƒ}Pn|djoPn|d}q W|S(s8Go to the location of the first blank on the given line.iiN( RRtlasttasciiRtinchtytSPtmin(RRR((Rt _end_of_line3s ( cCs˜|iiƒ\}}||_ti|ƒoU||i jp||i jo1y|ii |ƒWqt i j oqXq”n|tijo|ii|dƒnλ|tit itit ifjo³|djo|ii||dƒn^|djonM|io(|ii|d|i|dƒƒn|ii|d|i ƒ|tit ifjo|iiƒq”n|tijo|iiƒnς|tijoD|io |ii||i|ƒƒq”|ii||i ƒnž|tit ifjoZ||i jo|ii||dƒq”||i joq”|ii|ddƒn+|tijodSn|tijoG|i djodSq”||i jo|ii|ddƒq”nΌ|tijoX|djo'|i|ƒdjo|iiƒq”|ii||ƒ|iiƒnT|ti jo|ii!ƒn3|ti"t i#fjoq||i jo]|ii|d|ƒ||i|dƒjo(|ii|d|i|dƒƒqθq”n©|ti$jo|ii%ƒnˆ|ti&t i'fjon|djo]|ii|d|ƒ||i|dƒjo(|ii|d|i|dƒƒqq”ndS(s!Process a single editing command.iiN((RRtgetyxRtxtchRRtisprintRRR RterrortSOHtmovetSTXtKEY_LEFTtBSt KEY_BACKSPACERR!tdelchtEOTtENQtACKt KEY_RIGHTtBELtNLtVTtdeletelntclrtoeoltFFtrefreshtSOtKEY_DOWNtSItinsertlntDLEtKEY_UP(RR$RR#((Rt do_command?sx   %   (  #0 0cCsθd}xΫt|idƒD]Ζ}|ii|dƒ|i|ƒ}|djo|i oqnx_t|i dƒD]J}|i o||joPn|t t i |ii||ƒƒƒ}qtW|idjo|d}qqW|S(s.Collect and return the contents of the window.tiis N(tresulttrangeRRRRR(R!tstopRRR#tchrRR(RRCRARR#((Rtgather…s ,cCshx[|iiƒ}|o||ƒ}n|pqn|i|ƒpPn|iiƒqW|iƒS(s2Edit in the widget window and collect the results.iN(RRtgetchR$tvalidateR?R8RE(RRGR$((Rtedit•s( t__name__t __module__t__doc__RR!R?RERRH(((RRs  F t__main__cCs‡d\}}d \}}|i|d|dƒti||||ƒ}t ||d|d||||ƒ|i ƒt |ƒi ƒS( Ni iiiisUse Ctrl-G to end editing.i(i i(ii( tncolstnlinesRRtstdscrtaddstrRtnewwinRRR8RRH(RORRRMRRN((Rt test_editbox£s  & sContents of text box:( RKRRRRRIRRtwrappertstrtrepr(RRRRTRRR((Rt?s 