B €/g^¡=ã@sÔddlZddlmZddlmZddlmZGdd„dƒZe ¡dd„Z d d „Z d d „Z d d„Z dd„Z dd„Ze d¡Zdd„ZGdd„dƒZGdd„dƒZGdd„dƒZedkrÐddlmZeddd d!dS)"éN)Úaskyesno)Ú askinteger)ÚidleConfc@s2eZdZdd„Zedd„ƒZdd„Zd dd „ZdS) ÚFormatParagraphcCs ||_dS)N)Úeditwin)Úselfr©rú&/usr/lib64/python3.7/idlelib/format.pyÚ__init__szFormatParagraph.__init__cCstjdddddd|_dS)NÚ extensionsrz max-widthÚintéH)ÚtypeÚdefault)rZ GetOptionÚ max_width)Úclsrrr Úreload"szFormatParagraph.reloadcCs d|_dS)N)r)rrrr Úclose'szFormatParagraph.closeNc Csà|dkr|jn|}|jj}|j ¡\}}|rF|rF| ||¡}t|ƒ}nt|| d¡ƒ\}}}}|rpt|||ƒ}n t ||ƒ}|  ddd¡||krÆ|  d|¡|  ¡|  ||¡| ||¡| ¡n |  d|¡| d¡dS)NÚinsertÚselz1.0ÚendÚbreak)rrÚtextÚget_selection_indicesÚgetÚget_comment_headerÚfind_paragraphÚindexÚreformat_commentÚreformat_paragraphÚ tag_removeÚmark_setÚundo_block_startÚdeleterÚundo_block_stopZsee) rÚeventÚlimitrÚfirstÚlastÚdataÚcomment_headerÚnewdatarrr Úformat_paragraph_event*s(          z&FormatParagraph.format_paragraph_event)N)Ú__name__Ú __module__Ú __qualname__r Ú classmethodrrr,rrrr rs rc CsFtt| d¡ƒ\}}| d|d|¡}x:| d|dd¡rbt|ƒrb|d}| d|d|¡}q*W|}t|ƒ}t|ƒ}x¡sz#reformat_comment..éÚéÿÿÿÿc3s|]}ˆ|VqdS)Nr)rLr:)r*rr rN°s)r7rEr5Úmaxr)r)r&r*Z format_widthr+Z block_suffixr)r*rMr rœs   rcCst d|¡dk S)Nz^\s*$)r?Úmatch)r:rrr r6²sr6cCst d|¡ ¡S)Nz ^([ \t]*))r?rSÚgroup)r:rrr r>·sr>cCs"t d|¡}|dkrdS| d¡S)Nz ^([ \t]*#*)rPr3)r?rSrT)r:Úmrrr r»s rz[ \t]*cCs$t |¡}| ¡t| ¡ |¡ƒfS)N)Ú_line_indent_rerSrr7rTrA)r:ÚtabwidthrUrrr Úget_line_indentÊs rXc@sheZdZdd„Zdd„Zdd„Zddd „Zdd d „Zdd d „Zddd„Z ddd„Z ddd„Z dd„Z dS)Ú FormatRegioncCs ||_dS)N)r)rrrrr r ×szFormatRegion.__init__cCsr|jj}|j ¡\}}|r<|r<| |d¡}| |d¡}n| d¡}| d¡}| ||¡}| d¡}||||fS)Nz linestartz-1c lineend +1czinsert linestartzinsert lineend +1cr;)rrrrrr5)rrr'r(ÚheadÚtailÚcharsrFrrr Ú get_regionÚs     zFormatRegion.get_regioncCsz|jj}d |¡}||kr&| ¡dS| ddd¡| d|¡| ¡| ||¡| ||¡|  ¡|  d|d¡dS)Nr;rz1.0rr) rrrEZbellr r!r"r#rr$Ztag_add)rrZr[r\rFrÚnewcharsrrr Ú set_regionðs     zFormatRegion.set_regionNc Cs€| ¡\}}}}xZtt|ƒƒD]J}||}|rt||jjƒ\}} | |jj} |j | ¡||d…||<qW| ||||¡dS)Nr) r]r@r7rXrrWÚ indentwidthÚ _make_blanksr_) rr%rZr[r\rFÚposr:ÚrawÚ effectiverrr Úindent_region_events  z FormatRegion.indent_region_eventc Cs†| ¡\}}}}x`tt|ƒƒD]P}||}|rt||jjƒ\}} t| |jjdƒ} |j | ¡||d…||<qW|  ||||¡dS)Nrr) r]r@r7rXrrWrRr`rar_) rr%rZr[r\rFrbr:rcrdrrr Údedent_region_events z FormatRegion.dedent_region_eventcCsR| ¡\}}}}x,tt|ƒdƒD]}||}d|||<q"W| ||||¡dS)Nr3z##r)r]r@r7r_)rr%rZr[r\rFrbr:rrr Úcomment_region_event s z!FormatRegion.comment_region_eventcCsŠ| ¡\}}}}xdtt|ƒƒD]T}||}|s0q|dd…dkrN|dd…}n|dd…dkrj|dd…}|||<qW| ||||¡dS)Nr<z##r3ú#r)r]r@r7r_)rr%rZr[r\rFrbr:rrr Úuncomment_region_event,s  z#FormatRegion.uncomment_region_eventc Cs–| ¡\}}}}| ¡}|dkr$dSx\tt|ƒƒD]L}||}|r2t||ƒ\} } t| |ƒ\} } d| d| || d…||<q2W| ||||¡dS)Nú r=r)r]Ú _asktabwidthr@r7rXÚdivmodr_) rr%rZr[r\rFrWrbr:rcrdZntabsZnspacesrrr Útabify_region_event?s$z FormatRegion.tabify_region_eventcCs`| ¡\}}}}| ¡}|dkr$dSx&tt|ƒƒD]}|| |¡||<q2W| ||||¡dS)Nr)r]rkr@r7rAr_)rr%rZr[r\rFrWrbrrr Úuntabify_region_eventNsz"FormatRegion.untabify_region_eventcCstdd|jj|jjdddS)Nz Tab widthzColumns per tab? (2-16)r<é)ÚparentÚ initialvalueÚminvalueÚmaxvalue)rrrr`)rrrr rkYszFormatRegion._asktabwidth)N)N)N)N)N)N) r-r.r/r r]r_rerfrgrirmrnrkrrrr rYÔs   rYc@s$eZdZdd„Zdd„Zdd„ZdS)ÚIndentscCs ||_dS)N)r)rrrrr r gszIndents.__init__cCsJ|j}|j}tddd|dd|dd|jdrF| |_d |_d S) Nz Toggle tabsz Turn tabs )ZonZoffz? Indent width )zwill bez remains atz 8.z! Note: a tab is always 8 columns)rpér)rÚusetabsrrr`)rr%rrvrrr Útoggle_tabs_eventjs zIndents.toggle_tabs_eventcCs<|j}tdd|j|jddd}|r8||jkr8|js8||_dS)Nz Indent widthz6New indent width (2-16) (Always use 8 when using tabs)r<ro)rprqrrrsr)rrrr`rv)rr%rrIrrr Úchange_indentwidth_eventzsz Indents.change_indentwidth_eventN)r-r.r/r rwrxrrrr rtdsrtc@seZdZdd„Zddd„ZdS)ÚRstripcCs ||_dS)N)r)rrrrr r ‰szRstrip.__init__Nc CsØ|jj}|jj}| ¡tt| d¡ƒƒ}xZtd|ƒD]L}| d|d|¡}t |ƒ}t |  ¡ƒ}||kr6|  d||fd|¡q6W| d¡dkrÌt |jdƒsÌx*| d ¡d krÊ| d ¡dkrÊ|  d ¡q¢W|  ¡dS) Nrr3z%i.0z%i.endz%i.%izend-2cr;Zinterpzend-1cz1.0zend-3c)rrÚundor"r Úfloatrr@rr7rCr#Úhasattrr$) rr%rrzZend_lineZcurZtxtrcZcutrrr Ú do_rstripŒs   zRstrip.do_rstrip)N)r-r.r/r r}rrrr ryˆsryÚ__main__)Úmainzidlelib.idle_test.test_formatr<F)Ú verbosityÚexit)r?Ztkinter.messageboxrZtkinter.simpledialogrZidlelib.configrrrrrrr6r>rÚcompilerVrXrYrtryr-Zunittestrrrrr Ús(   C%$  $