B €/g^¡=c@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) ÚFormatParagraphcCó ||_dS©N©Úeditwin©Úselfr©r ú&/usr/lib64/python3.7/idlelib/format.pyÚ__init__ózFormatParagraph.__init__cCstjdddddd|_dS)NZ extensionsrz max-widthÚintiH)ZtypeZdefault)rZ GetOptionÚ max_width)Zclsr r r Úreload"szFormatParagraph.reloadcCs d|_dSrr©r r r r Úclose'rzFormatParagraph.closeNc Csà|dkr|jn|}|jj}|j ¡\}}|rF|rF| ||¡}t|ƒ}nt|| d¡ƒ\}}}}|rpt|||ƒ}n t ||ƒ}|  ddd¡||krÆ|  d|¡|  ¡|  ||¡| ||¡| ¡n |  d|¡| d¡dS)NÚinsertÚselú1.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Únewdatar r r Úformat_paragraph_event*s(          z&FormatParagraph.format_paragraph_eventr)Ú__name__Ú __module__Ú __qualname__r Z classmethodrrr-r r r r rs rc CsFtt| d¡ƒ\}}| d|d|¡}x:| d|dd¡rbt|ƒrb|d}| d|d|¡}q*W|}t|ƒ}t|ƒ}x¡óz#reformat_comment..iÚiÿÿÿÿc3s|]}ˆ|VqdSrr rA)r+r r rC°rD)r4r>r2Úmaxr )r*r'r+Z format_widthr,Z block_suffixr )r+rBr rœs   rcCst d|¡dk S)Nz^\s*$)r:Úmatch©r5r r r r3²sr3cCst d|¡ ¡S)Nz ^([ \t]*)©r:rGÚgrouprHr r r r9·sr9cCs"t d|¡}|dkrdS| d¡S)Nz ^([ \t]*#*)rEr1rI)r5Úmr r r r»s rz[ \t]*cCs$t |¡}| ¡t| ¡ |¡ƒfSr)Ú_line_indent_rerGrr4rJr<)r5ÚtabwidthrKr r r Úget_line_indentÊs rNc@sheZdZdd„Zdd„Zdd„Zddd „Zdd d „Zdd d „Zddd„Z ddd„Z ddd„Z dd„Z dS)Ú FormatRegioncCrrrr r r r r ×rzFormatRegion.__init__cCsr|jj}|j ¡\}}|r<|r<| |d¡}| |d¡}n| d¡}| d¡}| ||¡}| d¡}||||fS)Nz linestartz-1c lineend +1czinsert linestartzinsert lineend +1cr6)rrrrrr2)r rr(r)ÚheadÚtailÚcharsr?r r r Ú get_regionÚs     zFormatRegion.get_regioncCsz|jj}d |¡}||kr&| ¡dS| ddd¡| d|¡| ¡| ||¡| ||¡|  ¡|  d|d¡dS)Nr6rrrr) rrr>Zbellr!r"r#r$rr%Ztag_add)r rPrQrRr?rZnewcharsr r r Ú set_regionðs     zFormatRegion.set_regionNc Cs€| ¡\}}}}xZtt|ƒƒD]J}||}|rt||jjƒ\}} | |jj} |j | ¡||d…||<qW| ||||¡dS©Nr) rSr;r4rNrrMÚ indentwidthÚ _make_blanksrT© r r&rPrQrRr?Úposr5ÚrawÚ effectiver r r Úindent_region_events  z FormatRegion.indent_region_eventc Cs†| ¡\}}}}x`tt|ƒƒD]P}||}|rt||jjƒ\}} t| |jjdƒ} |j | ¡||d…||<qW|  ||||¡dS)Nrr) rSr;r4rNrrMrFrVrWrTrXr r r Údedent_region_events z FormatRegion.dedent_region_eventcCsR| ¡\}}}}x,tt|ƒdƒD]}||}d|||<q"W| ||||¡dS)Nr1ú##r©rSr;r4rT©r r&rPrQrRr?rYr5r r r Úcomment_region_event s z!FormatRegion.comment_region_eventcCsŠ| ¡\}}}}xdtt|ƒƒD]T}||}|s0q|dd…dkrN|dd…}n|dd…dkrj|dd…}|||<qW| ||||¡dS)Nr7r^r1z#rr_r`r r r Úuncomment_region_event,s  z#FormatRegion.uncomment_region_eventc Cs–| ¡\}}}}| ¡}|dkr$dSx\tt|ƒƒD]L}||}|r2t||ƒ\} } t| |ƒ\} } d| d| || d…||<q2W| ||||¡dS)Nz r8r)rSÚ _asktabwidthr;r4rNZdivmodrT) r r&rPrQrRr?rMrYr5rZr[ZntabsZnspacesr r r Útabify_region_event?s$z FormatRegion.tabify_region_eventcCs`| ¡\}}}}| ¡}|dkr$dSx&tt|ƒƒD]}|| |¡||<q2W| ||||¡dSrU)rSrcr;r4r<rT)r r&rPrQrRr?rMrYr r r Úuntabify_region_eventNsz"FormatRegion.untabify_region_eventcCstdd|jj|jjdddS)Nz Tab widthzColumns per tab? (2-16)r7é©ÚparentZ initialvalueZminvalueZmaxvalue)rrrrVrr r r rcYszFormatRegion._asktabwidthrrrrrr) r.r/r0r rSrTr\r]rarbrdrercr r r r rOÔs   rOc@s$eZdZdd„Zdd„Zdd„ZdS)ÚIndentscCrrrr r r r r grzIndents.__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)rhir)rÚusetabsrrrV)r r&rrjr r r Ú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)r7rfrgr)rrrrVrj)r r&rr@r r r Úchange_indentwidth_eventzsz Indents.change_indentwidth_eventN)r.r/r0r rkrlr r r r ridsric@seZdZdd„Zddd„ZdS)ÚRstripcCrrrr r r r r ‰rzRstrip.__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) Nrr1z%i.0z%i.endz%i.%izend-2cr6Zinterpzend-1crzend-3c)rrÚundor#rZfloatrr;rr4r=r$Zhasattrr%) r r&rrnZend_lineZcurZtxtrZZcutr r r Ú do_rstripŒs   zRstrip.do_rstripr)r.r/r0r ror r r r rmˆsrmZ__main__)Úmainzidlelib.idle_test.test_formatr7F)Z verbosityZexit)r:Ztkinter.messageboxrZtkinter.simpledialogrZidlelib.configrrrrr rr3r9rZcompilerLrNrOrirmr.Zunittestrpr r r r Zs(   C%$  $