� ��^c@s�dZddlZddlZddlZddlZddlZddlmZdddf\ZZ Z d�Z d�Z d �Z ie e6e e 6e e 6Zid e6d e 6d e 6Zied 6e d 6e d 6Zid e6d e 6de 6Zd�Zdfd��YZdfd��YZdfd��YZdefd��YZdefd��YZdefd��YZd�Zd�Zd�Zd�ZddlZd fd!��YZd"�Z d#�Z!e"d$kr�e!�ndS(%sSS1 -- a spreadsheet.i����N(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   tSheetcBs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z d �Z d �Z d �Zd �Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(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|d�r1|j|j�S|SdS(Ntrecalc(tgetcellthasattrRR(RRtyR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR*scCs�||kr||}}n||kr8||}}ng}xRt||d�D]=}x4t||d�D]}|j|j||��qlWqRW|S(Ni(trangetappendR(Rtx1ty1tx2ty2RR R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR1s  !cCs|jj||f�S(N(Rtget(RRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR<scCsJ|dkr|dkst�t|t�s3t�||j||ftlentstrRt iteritemsRRRRDR)R(RRR't align2action(RR?R@twidththeighttcolwidthtfullRttextt alignmentR Rtseptline((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytdisplay�sR &!&!"  ! '  cCs�dg}xn|jj�D]]\\}}}t|d�rI|j�}ndtj|�}|jd|||f�qW|jd�dj|�S(Ns txmls%ss% %s ss (RRLRRWtcgitescapeR"tjoin(RtoutRR Rtcellxml((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRW�s "  cCs\|j�}t|d�}|j|�|rN|jd� rN|jd�n|j�dS(NR s (RWtopentwritetendswithtclose(RtfilenameRRtf((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytsave�s   cCs0t|d�}t|�j|�|j�dS(Ntr(R]t SheetParsert parsefileR`(RRaRb((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pytload�s(t__name__t __module__RRRRR+R-R0R3R4R.R9R:R;R<R=RARBRRVRWRcRg(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR s,                  2 RecBs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�ZeZ d�Z d�Z d �Z d �Z d �Zd �Zd �Zd�ZRS(cCs ||_dS(N(tsheet(RRj((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�scCsAtj�}|j|_|j|_|j|_|j|�dS(N( Rt ParserCreatet startelementtStartElementHandlert endelementtEndElementHandlertdatatCharacterDataHandlert ParseFile(RRbtparser((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRf�s     cCsct|d|d�}|rVx*|j�D]\}}t|�||%s(RuttypeR{Rht align2xmlRSR�(RRy((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRWXs  cCs8d|jkodknr*d|jS|j�SdS(Niis %sI�i�I�(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.pyR�escCsdt|j�S(Ns%s(treprR{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt _xml_floathscCsdt|j�S(Ns%s(R�R{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyt _xml_complexks( RhRiRRRRDRWR�R�R�R�(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�Es      R�cBs2eZded�Zd�Zd�Zd�ZRS(s%scCsUt|ttf�st�|tttfks6t�||_||_||_ dS(N( R)RKtunicodeR(RRRRRR�RS(RRRR�RS((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|j�fS(Ns9%s(R�RSR�RXRYRR(Rts((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRW}s  (RhRiRRRRDRW(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�ns  R�cBsDeZded�Zd�Zd�Zd�Zd�Zd�ZRS(s%scCsV|tttfkst�||_t|j�|_||_||_|j �dS(N( RRRR(tformulat translatet translatedR�RSRB(RR�R�RS((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�s    cCs d|_dS(N(R R{(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRB�scCs�|jdkr�y4|jddt|j��|jd�|_Wq�tj�d}t|d�rw|j |_q�t |�|_q�Xn|jS(Ns from __future__ import division s__value__ = eval(%s)t __value__iRh( R{R tr_execR�R�tr_evalR1texc_infoRRhRK(RRtexc((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�s cCs:y|j|j}Wnt|j�}nX||jfS(N(R�R{RKRS(RRR((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRD�s cCsdt|j|j|jfS(Ns,%s(R�RSR�R�(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRW�s cCs�g}x�tjd|j�D]�}tjd|�} | dk r�| j�\} } t| �} t| �} || ko�|knr�|| ko�|knr�t| || |�}q�n|j |�qWt dj |�|j |j �S(Ns(\w+)s^([A-Z]+)([1-9][0-9]*)$RE(tretsplitR�tmatchR tgroupst colname2numRtcellnameR"R�RZR�RS(RR#R$R%R&R6R7R[tpartRtsxtsyRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR5�s   8( RhRiRRRBRRDRWR5(((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s     c Cs�g}x�tjd|�D]�}tjd|�}|dkrM|j|�q|j�\}}}}t|�}|dkr�d||f}n"t|�}d||||f}|j|�qWdj|�S(s�Translate 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(R�R�R�R R"R�R�RZ( R�R[R�RR#R$R%R&R�((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s    cCs&|dkst�t|�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.pyR��scCsk|j�}d}xR|D]J}d|ko6dknsAt�|dt|�td�d}qW|S(sCTranslate a column name to number (e.g. 'A'->1, 'Z'->26, 'AA'->27).itAtZii(tupperR(tord(R�Rtc((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s   "&cCs\|dkst�d}x=|rWt|dd�\}}t|td��|}qW|S(s6Translate a column number to name (e.g. 1->'A', etc.).iREiiR�(R(tdivmodtchrR�(RR�R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRI�s  tSheetGUIcBs�eZdZdddd�Zd�Zd�Zd�Zd�Zd �Zd �Z d �Z d �Z d �Z d�Z d�ZeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(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|j�t 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(R�iR�(#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.pyR�s<     cCsr|j|jkr>|jdk r>|jj|j|j�n|jj|j�|j�|jjdd�dS(Nitendtbreak( R�R�R RjR0R-R�R�tdelete(Rtevent((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�'s ! cCs#|j\}}|j||�dS(N(R�t load_entry(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�0scCs�|jj||�}|dkr*d}n1t|t�rId|j}n|j�\}}|jjdd�|jj d|�|jj dd�dS(NREt=iR�( RjRR R)R�R�RDR�R�tinserttselection_range(RRR RRRRS((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�4s  c Cs||_||_i|_tj|jdd�}|jdddddd�|jd|j�x�t d |d �D]�}|jj |d d �tj|jd t |�dd�}|jd|dddd �||j|df<||_ d|_ |jd|j�|jd|j�|jd|j�|jd|j�qvWx�t d |d �D]�}tj|jd t|�dd�}|jddd|dd �||jd|fitminsizei@RRtWEs sstsunkentbgtwhitetfgtblackN(R�R�t gridcellsR�R�R�tgrid_configureR�t selectallR!tgrid_columnconfigureRIt _SheetGUI__xt _SheetGUI__yt selectcolumnt extendcolumnRKt selectrowt extendrowtpresstmotiontrelease(RR�R�RRR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�@sN   $  $    cCs*|jdd�|jtjtj�dS(Ni(R�t setcornerR1R2(RR�((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�rscCs<|j|�\}}|j|d�|j|tj�dS(Ni(twhichxyR�RR1R2(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�vscCsR|j|�\}}|dkrN|j|jdd�|j|tj�ndS(Nii(RR�R�RR1R2(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�{s cCs<|j|�\}}|jd|�|jtj|�dS(Ni(RR�RR1R2(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��scCsR|j|�\}}|dkrN|jd|jd�|jtj|�ndS(Nii(RR�R�RR1R2(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s cCsD|j|�\}}|dkr@|dkr@|j||�ndS(Ni(RR�(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��scCsD|j|�\}}|dkr@|dkr@|j||�ndS(Ni(RR(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��scCsh|jj|j|j�}|dk rdt|tj�rdy|j|j fSWqdt k r`qdXndS(Ni(ii( R�twinfo_containingtx_rootty_rootR R)R�R�R�R�tAttributeError(RR�R ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR�s cCs|jj|j�dS(N(RjRcRa(R((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRc�scCs�|jdk r|j�n|j�t||�|jd<|j||�|jj�||f|_d|_ |j j |j�}|dk r�d|d(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s cCs1|j�|j\}}|j|d|�dS(sCallback for the Tab key.iR�(RR�R�(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s cCs:|j�|j\}}|jtd|d�|�dS(s-Callback for the Tab key with Shift modifier.iR�(RR�R�R>(RR�RR ((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyR��s cCs�|j\}}|jj�}d}|jd�rFt|d�}nGxDtttt fD]0}y||�}Wn qYqYXt |�}PqYW|dkr�|r�t |�}n|dkr�|j j ||�n|j j|||�|j�dS(s+Set the current cell from the entry widget.R�iN(R�R�R'R t startswithR�RR�R�R�R�R�RjR-R+R�(RRR RRRtclsR{((s./usr/lib64/python2.7/Demo/tkinter/guido/ss1.pyRs$  cCs�|jj�x�|jj�D]�\\}}}|dks|dkrMqn|jj||�}|dkr{d|ds@         �Y )6   �C