[@sddlTddlmZddlmZddlZddZGdddeZd d Ze d krdd l m Z e endS) )*) SearchEngine)SearchDialogBaseNcCsY|j}tj|}t|ds?t|||_n|j}|j|dS)N_replacedialog)Z_rootrgethasattr ReplaceDialogropen)textrootengineZdialogr +/usr/lib/python3.4/idlelib/ReplaceDialog.pyreplaces   rc@seZdZdZdZddZddZddZd d Zd d d Z d ddZ d ddZ ddZ d ddZ dddZddZddZd ddZd S)rzReplace DialogReplacecCs&tj|||t||_dS)N)r__init__Z StringVarreplvar)selfr r r r rrszReplaceDialog.__init__cCstj||y|jd}Wntk r=d}YnXy|jd}Wntk rkd}YnX|p~|jd}|p|}|j||d|_dS)Nz sel.firstzsel.lastinsert)rr indexTclErrorshow_hitok)rr firstlastr r rr s     zReplaceDialog.opencCs-tj||jd|jd|_dS)Nz Replace with:r)rcreate_entriesZ make_entryrZreplent)rr r rr)s zReplaceDialog.create_entriescCs`tj||jd|j|jd|j|jd|jd|jd|jdS)NZFindrz Replace+Findrz Replace All)rcreate_command_buttonsZ make_buttonfind_it replace_itdefault_command replace_all)rr r rr-s  z$ReplaceDialog.create_command_buttonsNcCs|jddS)Nr)do_find)reventr r rr4szReplaceDialog.find_itcCs#|j|jr|jndS)N)r"r do_replace)rr#r r rr7szReplaceDialog.replace_itcCs5|j|jr1|jr1|jdq1ndS)Nr)r"rr$)rr#r r rr ;s zReplaceDialog.default_commandc Cs`|jjrVy|j|}Wq\tjk rR|jj|dd}Yq\Xn|}|S)za Helper function for expanding a regular expression in the replace field, if needed. zInvalid Replace ExpressionN)r ZisreexpandreerrorZ report_error)rmreplnewr r r_replace_expandAszReplaceDialog._replace_expandcCsB|jj}|sdS|jj}|j}|jj||}|sZ|jdS|jddd|jddd|d}|dj}|jj rd}d}nd}d} } |j x6|jj ||||d|}|sPn|\}} |jd|d|d} | j } |j | |}|dkrXPn| j\}}d||f} d||f} || kr|jd | nH|jd | | | kr|j| | n|r|j| |n|t|}d}qW|j| r4| r4|j| | n|jdS) Nselz1.0endhitrrz%d.0z%d.%dr)r getprogrrr search_textbell tag_removestartZiswrapundo_block_startZsearch_forwardgroupr+spanmark_setdeleterlenundo_block_stoprclose)rr#progr)r reslinecolrrrr(charsZorigr*ijr r rr!OsZ      !        zReplaceDialog.replace_allrc Cs|jjsdS|j}|jj|d|}|sH|jdS|\}}|j\}}d||f}d||f} |j|| d|_dS)NFz%d.%drT)r r/r r0r1r6rr) rrr r=r>r(rArBrrr r rr"s    zReplaceDialog.do_findc Cs|jj}|sdS|j}y&|jd}}|jd}Wntk rbd}YnX|s|jd}}}ntj|\}}|jd|d|d}|j||} |sdS|j | |j j} | dkrdS|j d||j | j r6|j||n| rO|j|| n|j|j||jdd|_dS) NFz sel.firstzsel.lastrz%d.0rrT)r r/r rrrZ get_line_colrmatchr+rr7r4r5r8rr:rr) rr<r rposrr>r?r@r(r*r r rr$s:        zReplaceDialog.do_replacecCs|j}|jd||jddd|jd|||jddd||krq|jd|n|jd|||jd|jdS)Nrr,z1.0r-r.)r r7r2tag_addZseeZupdate_idletasks)rrrr r r rrs   zReplaceDialog.show_hitcCs*tj|||jjddddS)Nr.z1.0r-)rr;r r2)rr#r r rr;szReplaceDialog.close)__name__ __module__ __qualname__titleZiconrr rrrrr r+r!r"r$rr;r r r rrs      1  rc st}|jdttttjd|j\}}}}|jd||dfdd}dd}t||_ |_ j j d d d fd d }t |ddd|} | j dS)NzTest ReplaceDialogz[x+]z+%d+%dcSsdS)Nr r r r rr4sz)_replace_dialog..undo_block_startcSsdS)Nr r r r rr:sz(_replace_dialog..undo_block_stoprzThis is a sample string. cs4jtdttjtdtdS)Nz1.0)rEZSELZENDrr2r )r r r show_replaces z%_replace_dialog..show_replacer rZcommand)ZTkrIlistmapintr&splitZgeometryZTextr4r:ZpackrZButton) parentr widthZheightxyr4r:rLZbuttonr )r r_replace_dialogs  3      rU__main__)run) ZtkinterZidlelibrZidlelib.SearchDialogBaserr&rrrUrFZidlelib.idle_test.htestrWr r r rs