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<scCsJ|dkr|dkstt|ts3t||j||ftlentstrRt iteritemsRRRRDR)R(RRR't align2action(RR?R@twidththeighttcolwidthtfullRttextt alignmentR Rtseptline((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytdisplaysR &!&!"  ! '  cCsdg}xn|jjD]]\\}}}t|drI|j}ndtj|}|jd|||fqW|jddj|S(Ns txmls%ss% %s ss (RRLRRWtcgitescapeR"tjoin(RtoutRR Rtcellxml((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRWs "  cCs\|j}t|d}|j||rN|jd rN|jdn|jdS(NR s (RWtopentwritetendswithtclose(RtfilenameRRtf((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytsaves   cCs0t|d}t|j||jdS(Ntr(R]t SheetParsert parsefileR`(RRaRb((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytloads(t__name__t __module__RRRRR+R-R0R3R4R.R9R:R;R<R=RARBRRVRWRcRg(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR s,                  2 RecBseZdZdZdZdZdZdZdZeZ dZ dZ d Z d Z d Zd Zd ZdZRS(cCs ||_dS(N(tsheet(RRj((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsAtj}|j|_|j|_|j|_|j|dS(N( Rt ParserCreatet startelementtStartElementHandlert endelementtEndElementHandlertdatatCharacterDataHandlert ParseFile(RRbtparser((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRfs     cCsct|d|d}|rVx*|jD]\}}t|||%s(RuttypeR{Rht align2xmlRSR(RRy((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRWXs  cCs8d|jkodknr*d|jS|jSdS(Niis %sIiI(R{t _xml_long(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt_xml_int_s cCs d|jS(Ns%s(R{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRescCsdt|jS(Ns%s(treprR{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt _xml_floathscCsdt|jS(Ns%s(RR{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt _xml_complexks( RhRiRRRRDRWRRRR(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyREs      RcBs2eZdedZdZdZdZRS(s%scCsUt|ttfst|tttfks6t||_||_||_ dS(N( R)RKtunicodeR(RRRRRRRS(RRRRRS((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRps   cCs|jS(N(RR(RR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRwscCs|j|jfS(N(RRRS(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRDzscCs-d}|t|j|jtj|jfS(Ns9%s(RRSRRXRYRR(Rts((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRW}s  (RhRiRRRRDRW(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRns  RcBsDeZdedZdZdZdZdZdZRS(s%scCsV|tttfkst||_t|j|_||_||_|j dS(N( RRRR(tformulat translatet translatedRRSRB(RRRRS((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs    cCs d|_dS(N(R R{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRBscCs|jdkry4|jddt|j|jd|_Wqtjd}t|drw|j |_qt ||_qXn|jS(Ns from __future__ import division s__value__ = eval(%s)t __value__iRh( R{R tr_execRRtr_evalR1texc_infoRRhRK(RRtexc((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs:y|j|j}Wnt|j}nX||jfS(N(RR{RKRS(RRR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRDs cCsdt|j|j|jfS(Ns,%s(RRSRR(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRWs 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]*)$RE(tretsplitRtmatchR tgroupst colname2numRtcellnameR"RRZRRS(RR#R$R%R&R6R7R[tpartRtsxtsyRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR5s   8( RhRiRRRBRRDRWR5(((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)REN(RRRR R"RRRZ( RR[RRR#R$R%R&R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs    cCs&|dkstt|t|S(sETranslate a cell coordinate to a fancy cell name (e.g. (1, 1)->'A1').i(R(RIRK(RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsk|j}d}xR|D]J}d|ko6dknsAt|dt|tdd}qW|S(sCTranslate a column name to number (e.g. 'A'->1, 'Z'->26, 'AA'->27).itAtZii(tupperR(tord(RRtc((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs   "&cCs\|dkstd}x=|rWt|dd\}}t|td|}qW|S(s6Translate a column number to name (e.g. 1->'A', etc.).iREiiR(R(tdivmodtchrR(RRR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRIs  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: %sRRtA1tfontt helveticaitboldtSavetcommandtsidetbottomtexpanditfilltbothR R Rssss ssN(RiR(#RaRRjtostpathtisfileRgRAR>tTktroottwm_titletLabeltbeacontEntrytentrytButtonRct savebuttontFrametcellgridtpacktbindt return_eventtshift_return_eventt tab_eventtshift_tab_eventt delete_eventt escape_eventtmakegridR t currentxytcornerxyt setcurrenttsync(RRatrowstcolumnsR?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 RjR0R-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(NREt=iR( RjRR R)RRRDRRtinserttselection_range(RRR RRRRS((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@RRtWEs sstsunkentbgtwhitetfgtblackN(RRt gridcellsRRRtgrid_configureRt selectallR!tgrid_columnconfigureRIt _SheetGUI__xt _SheetGUI__yt selectcolumnt extendcolumnRKt selectrowt extendrowtpresstmotiontrelease(RRRRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR@sN   $  $    cCs*|jdd|jtjtjdS(Ni(Rt setcornerR1R2(RR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRrscCs<|j|\}}|j|d|j|tjdS(Ni(twhichxyRRR1R2(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRvscCsR|j|\}}|dkrN|j|jdd|j|tjndS(Nii(RRRRR1R2(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR{s cCs<|j|\}}|jd||jtj|dS(Ni(RRRR1R2(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRscCsR|j|\}}|dkrN|jd|jd|jtj|ndS(Nii(RRRRR1R2(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 R)RRRRtAttributeError(RRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs|jj|jdS(N(RjRcRa(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRcscCs|jdk r|jn|jt|||jd<|j|||jj||f|_d|_ |j j |j}|dk rd|d(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs1|j|j\}}|j|d|dS(sCallback for the Tab key.iR(RRR(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs:|j|j\}}|jtd|d|dS(s-Callback for the Tab key with Shift modifier.iR(RRRR>(RRRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs cCs|j\}}|jj}d}|jdrFt|d}nGxDtttt fD]0}y||}Wn qYqYXt |}PqYW|dkr|rt |}n|dkr|j j ||n|j j||||jdS(s+Set the current cell from the entry widget.RiN(RRR'R t startswithRRRRRRRRjR-R+R(RRR RRRtclsR{((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs$  cCs|jjx|jjD]\\}}}|dks|dkrMqn|jj||}|dkr{d|ds@         Y )6   C