V Qc@sdZddlZddlZddlZddlZddlZddlmZdddf\ZZ Z dZ dZ d Z ie e6e e 6e e 6Zid e6d e 6d e 6Zied 6e d 6e d 6Zid e6d e 6de 6ZdZdfdYZdfdYZdfdYZdefdYZdefdYZdefdYZdZdZdZdZddlZd fd!YZd"Z d#Z!e"d$kre!ndS(%sSS1 -- a spreadsheet.iN(texpattLEFTtCENTERtRIGHTcCs |j|S(N(tljust(txtn((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR scCs |j|S(N(tcenter(RR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCs |j|S(N(trjust(RR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRstleftRtrighttwtecCs4d}x'|D]}|dk r ||7}q q W|S(Ni(tNone(tseqttotalR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytsums   tSheetcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZRS(cCsOi|_tj|_|jjd}|j|_|j|_t|_dS(Nt__main__(tcellstrexectRExect add_modulet cellvaluetcelltmulticellvalueR(tselftm((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt__init__"s    cCs9|j||}t|dr1|j|jS|SdS(Ntrecalc(tgetcellthasattrRR(RRtyR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR*scCs||kr||}}n||kr8||}}ng}xRt||dD]=}x4t||dD]}|j|j||qlWqRW|S(Ni(trangetappendR(Rtx1ty1tx2ty2RR R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR1s  !cCs|jj||fS(N(Rtget(RRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR<scCs||j||fR!t colnum2nameRR;tlentstrRt iteritemsRRRRAt isinstanceRR't align2action(RR<R=twidththeighttcolwidthtfullRttextt alignmentR Rtseptline((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytdisplaysP &!&!"  ! '  cCsdg}xn|jjD]]\\}}}t|drI|j}ndtj|}|jd|||fqW|jddj|S(Ns txmls%ss% %s ss (RRIRRUtcgitescapeR"tjoin(RtoutRR Rtcellxml((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRUs "  cCs\|j}t|d}|j||rN|jd rN|jdn|jdS(NR s (RUtopentwritetendswithtclose(RtfilenameRPtf((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytsaves   cCs0t|d}t|j||jdS(Ntr(R[t SheetParsert parsefileR^(RR_R`((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytloads(t__name__t __module__RRRRR(R*R-R0R1R+R6R7R8R9R:R>R?RRTRURaRe(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR s,                  2 RccBseZdZdZdZdZdZdZdZeZ dZ dZ d Z d Z d Zd Zd ZdZRS(cCs ||_dS(N(tsheet(RRh((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsAtj}|j|_|j|_|j|_|j|dS(N( Rt ParserCreatet startelementtStartElementHandlert endelementtEndElementHandlertdatatCharacterDataHandlert ParseFile(RR`tparser((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRds     cCsct|d|d}|rVx*|jD]\}}t|||%s(RsttypeRyRft align2xmlRQR(RRw((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRUXs  cCs8d|jkodknr*d|jS|jSdS(Niis %sIiI(Ryt _xml_long(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt_xml_int_s cCs d|jS(Ns%s(Ry(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRescCsdt|jS(Ns%s(treprRy(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt _xml_floathscCsdt|jS(Ns%s(RRy(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt _xml_complexks( RfRgRRRRARURRRR(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyREs      RcBs2eZdedZdZdZdZRS(s%scCs||_||_||_dS(N(RPRRQ(RRPRRQ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRps  cCs|jS(N(RP(RR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRwscCs|j|jfS(N(RPRQ(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRAzscCs-d}|t|j|jtj|jfS(Ns9%s(RRQRRVRWRP(Rts((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRU}s  (RfRgRRRRARU(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRns  RcBsDeZdedZdZdZdZdZdZRS(s%scCs;||_t|j|_||_||_|jdS(N(tformulat translatet translatedRRQR?(RRRRQ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs    cCs d|_dS(N(R Ry(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR?scCs|jdkry4|jddt|j|jd|_Wqtjd}t|drw|j |_qt ||_qXn|jS(Ns from __future__ import division s__value__ = eval(%s)t __value__iRf( RyR tr_execRRtr_evalR.texc_infoRRfRH(RRtexc((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs:y|j|j}Wnt|j}nX||jfS(N(RRyRHRQ(RRP((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRAs cCsdt|j|j|jfS(Ns,%s(RRQRR(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRUs cCsg}xtjd|jD]}tjd|} | dk r| j\} } t| } t| } || ko|knr|| ko|knrt| || |}qn|j |qWt dj ||j |j S(Ns(\w+)s^([A-Z]+)([1-9][0-9]*)$RB(tretsplitRtmatchR tgroupst colname2numR}tcellnameR"RRXRRQ(RR#R$R%R&R3R4RYtpartRtsxtsyRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR2s   8( RfRgRRR?RRARUR2(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs     c Csg}xtjd|D]}tjd|}|dkrM|j|q|j\}}}}t|}|dkrd||f}n"t|}d||||f}|j|qWdj|S(sTranslate a formula containing fancy cell names to valid Python code. Examples: B4 -> cell(2, 4) B4:Z100 -> cells(2, 4, 26, 100) s(\w+(?::\w+)?)s2^([A-Z]+)([1-9][0-9]*)(?::([A-Z]+)([1-9][0-9]*))?$s cell(%s, %s)scells(%s, %s, %s, %s)RBN(RRRR R"RRRX( RRYRRR#R$R%R&R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs    cCst|t|S(sETranslate a cell coordinate to a fancy cell name (e.g. (1, 1)->'A1').(RFRH(RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsI|j}d}x0|D](}|dt|tdd}qW|S(sCTranslate a column name to number (e.g. 'A'->1, 'Z'->26, 'AA'->27).iitAi(tuppertord(RRtc((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs   &cCsJd}x=|rEt|dd\}}t|td|}q W|S(s6Translate a column number to name (e.g. 1->'A', etc.).RBiiR(tdivmodtchrR(RRR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRFs  tSheetGUIcBseZdZddddZdZdZdZdZd Zd Z d Z d Z d Z dZ dZeZdZdZdZdZdZdZdZdZdZdZdZdZRS(s7Beginnings of a GUI for a spreadsheet. TO DO: - clear multiple cells - Insert, clear, remove rows or columns - Show new contents while typing - Scroll bars - Grow grid when window is grown - Proper menus - Undo, redo - Cut, copy and paste - Formatting and alignment s sheet1.xmli icCs*||_t|_tjj|r:|jj|n|jj\}}t||}t||}t j |_ |j j d|jt j |j dddd|_ t j|j |_t j|j ddd |j|_t j|j |_|jjd d d d dd|j jd d|jjd d|jjd dd d dd|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|j||d|_d|_ |j!d d |j"dS(slConstructor. Load the sheet from the filename argument. Set up the Tk widget tree. sSpreadsheet: %sRPtA1tfontt helveticaitboldtSavetcommandtsidetbottomtexpanditfilltbothR R Rssss ssN(RiR(#R_RRhtostpathtisfileReR>R;tTktroottwm_titletLabeltbeacontEntrytentrytButtonRat savebuttontFrametcellgridtpacktbindt return_eventtshift_return_eventt tab_eventtshift_tab_eventt delete_eventt escape_eventtmakegridR t currentxytcornerxyt setcurrenttsync(RR_trowstcolumnsR<R=((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs<     cCsr|j|jkr>|jdk r>|jj|j|jn|jj|j|j|jjdddS(Nitendtbreak( RRR RhR-R*RRtdelete(Rtevent((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR's ! cCs#|j\}}|j||dS(N(Rt load_entry(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR0scCs|jj||}|dkr*d}n1t|trId|j}n|j\}}|jjdd|jj d||jj dddS(NRBt=iR( RhRR RJRRRARRtinserttselection_range(RRR RRPRQ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR4s  c Cs||_||_i|_tj|jdd}|jdddddd|jd|jxt d |d D]}|jj |d d tj|jd t |dd}|jd|dddd ||j|df<||_ d|_ |jd|j|jd|j|jd|j|jd|jqvWxt d |d D]}tj|jd t|dd}|jddd|dd ||jd|fitminsizei@RPtWEs sstsunkentbgtwhitetfgtblackN(RRt gridcellsRRRtgrid_configureRt selectallR!tgrid_columnconfigureRFt _SheetGUI__xt _SheetGUI__yt selectcolumnt extendcolumnRHt selectrowt extendrowtpresstmotiontrelease(RRRRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR@sN   $  $    cCs*|jdd|jtjtjdS(Ni(Rt setcornerR.R/(RR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRrscCs<|j|\}}|j|d|j|tjdS(Ni(twhichxyRRR.R/(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRvscCsR|j|\}}|dkrN|j|jdd|j|tjndS(Nii(RRRRR.R/(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR{s cCs<|j|\}}|jd||jtj|dS(Ni(RRRR.R/(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsR|j|\}}|dkrN|jd|jd|jtj|ndS(Nii(RRRRR.R/(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCsD|j|\}}|dkr@|dkr@|j||ndS(Ni(RR(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsD|j|\}}|dkr@|dkr@|j||ndS(Ni(RR(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsh|jj|j|j}|dk rdt|tjrdy|j|j fSWqdt k r`qdXndS(Ni(ii( Rtwinfo_containingtx_rootty_rootR RJRRRRtAttributeError(RRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs|jj|jdS(N(RhRaR_(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRascCs|jdk r|jn|jt|||jd<|j|||jj||f|_d|_ |j j |j}|dk rd|ds@         Y )6   C