B XÙ&»ã@sŠddlZddlmZmZddlmZddlmZdd„ZGdd„deƒZ d d „Z e d kr†dd l m Z e d dddddlmZee ƒdS)éN)Ú StringVarÚTclError)ÚSearchDialogBase)Ú searchenginecCs<| ¡}t |¡}t|dƒs(t||ƒ|_|j}| |¡dS)NÚ_replacedialog)Z_rootrÚgetÚhasattrÚ ReplaceDialogrÚopen)ÚtextÚrootÚengineZdialog©rú2/opt/alt/python37/lib/python3.7/idlelib/replace.pyÚreplaces    rcseZdZdZdZ‡fdd„Zdd„Zdd„Zd d „Zdd d „Z d dd„Z d!dd„Z dd„Z d"dd„Z d#dd„Zdd„Zdd„Zd$dd„Z‡ZS)%r zReplace DialogÚReplacecstƒ ||¡t|ƒ|_dS)N)ÚsuperÚ__init__rÚreplvar)Úselfr r )Ú __class__rrr%s zReplaceDialog.__init__cCsˆt ||¡y| d¡}Wntk r2d}YnXy| d¡}Wntk rZd}YnX|ph| d¡}|pp|}| ||¡d|_dS)Nz sel.firstzsel.lastÚinsertT)rr ÚindexrÚshow_hitÚok)rr ÚfirstÚlastrrrr 5s    zReplaceDialog.opencCs"t |¡| d|j¡d|_dS)Nz Replace with:r)rÚcreate_entriesZ make_entryrZreplent)rrrrrLs zReplaceDialog.create_entriescCsJt |¡| d|j¡| d|j¡|jd|jdd| d|j¡dS)NZFindrz Replace+FindT)Zisdefz Replace All)rÚcreate_command_buttonsZ make_buttonÚfind_itÚ replace_itÚdefault_commandÚ replace_all)rrrrrQs  z$ReplaceDialog.create_command_buttonsNcCs| d¡dS)NF)Údo_find)rÚeventrrrr]szReplaceDialog.find_itcCs| |j¡r| ¡dS)N)r#rÚ do_replace)rr$rrrr as zReplaceDialog.replace_itcCs"| |j¡r| ¡r| d¡dS)NF)r#rr%)rr$rrrr!is zReplaceDialog.default_commandcCsL|j ¡rDy| |¡}WqHtjk r@|j |d¡d}YqHXn|}|S)NzInvalid Replace Expression)r ZisreÚexpandÚreÚerrorZ report_error)rÚmÚreplÚnewrrrÚ_replace_expandts  zReplaceDialog._replace_expandcCs¤|j ¡}|sdS|j ¡}|j}|j ||¡}|s@| ¡dS| ddd¡| ddd¡|d}|d ¡}|j  ¡r‚d}d}d}d} } |  ¡xà|jj ||||d|d }|s¶P|\}} | d |d |d¡} |   ¡} |  | |¡}|dkrôP|  ¡\}}d ||f} d ||f} || kr0| d | ¡n4| d | ¡| | krR| | | ¡|rd| | |¡|t|ƒ}d}q˜W| ¡| r˜| r˜| | | ¡| ¡dS) NÚselz1.0ÚendÚhitréTF)Úwraprz%d.0z%d.%dr)r Úgetprogrrr Ú search_textÚbellÚ tag_removeÚstartZiswrapÚundo_block_startZsearch_forwardÚgroupr,ÚspanÚmark_setÚdeleterÚlenÚundo_block_stoprÚclose)rr$Úprogr*r ÚresÚlineÚcolrrrr)ÚcharsZorigr+ÚiÚjrrrr"s\                 zReplaceDialog.replace_allFc Csv|j ¡sdS|j}|j |d|¡}|s4| ¡dS|\}}| ¡\}}d||f}d||f} | || ¡d|_dS)NFz%d.%dT)r r2r r3r4r9rr) rrr r@rAr)rDrErrrrrr#¼s     zReplaceDialog.do_findc Cs|j ¡}|sdS|j}y| d¡}}| d¡}Wntk rLd}YnX|sd| d¡}}}t |¡\}}| d|d|d¡}| ||¡} |sždS|  | |j  ¡¡} | dkr¼dS|  d|¡|  ¡|   ¡rä| ||¡| rô| || ¡| ¡| || d¡¡d|_dS)NFz sel.firstzsel.lastrz%d.0r0T)r r2r rrrZ get_line_colrÚmatchr,rr:r7r8r;rr=rr) rr?r rÚposrrArBrCr)r+rrrr%Ðs:      zReplaceDialog.do_replacecCsv|j}| d|¡| ddd¡| d||¡| ddd¡||krR| d|¡n| d||¡| d¡| ¡dS)Nrr-z1.0r.r/)r r:r5Útag_addZseeZupdate_idletasks)rrrr rrrrðs   zReplaceDialog.show_hitcCs t ||¡|j ddd¡dS)Nr/z1.0r.)rr>r r5)rr$rrrr>s zReplaceDialog.close)N)N)N)N)F)N)Ú__name__Ú __module__Ú __qualname__ÚtitleZiconrr rrrr r!r,r"r#r%rr>Ú __classcell__rr)rrr s     ;  r c sîddlm}m}m‰m‰ddlm}m}||ƒ}| d¡t t |  ¡  d¡dd…ƒ\}}|  d||df¡d d „}d d „} ||ƒ} |   ¡|| d d‰|ˆ_| ˆ_ˆ  ¡ˆ dd¡ˆ ¡‡‡‡fdd„} || d| d} |   ¡dS)Nr)ÚToplevelÚTextÚENDÚSEL)ÚFrameÚButtonzTest ReplaceDialogú+r0z+%d+%dé¯cSsdS)Nrrrrrr7sz)_replace_dialog..undo_block_startcSsdS)Nrrrrrr=sz(_replace_dialog..undo_block_stopZgray)Zinactiveselectbackgroundrz"This is a sample sTring Plus MORE.cs(ˆ ˆdˆ¡tˆƒˆ ˆdˆ¡dS)Nz1.0)rHrr5r)rPrQr rrÚ show_replace&sz%_replace_dialog..show_replacer)r Zcommand)ÚtkinterrNrOrPrQZ tkinter.ttkrRrSrLÚmapÚintZgeometryÚsplitÚpackr7r=rZ focus_set) ÚparentrNrOrRrSÚtopÚxÚyr7r=ÚframerVZbuttonr)rPrQr rÚ_replace_dialog s&    raÚ__main__)Úmainzidlelib.idle_test.test_replaceéF)Ú verbosityÚexit)Úrun)r'rWrrZidlelib.searchbaserZidlelibrrr rarIZunittestrcZidlelib.idle_test.htestrgrrrrÚs  o!