\d'dZddlZddlmZmZddlmZddlmZddZ GddeZ d Z e d kr'dd l mZed d dddlmZee dSdS)zReplace dialog for IDLE. Inherits SearchDialogBase for GUI. Uses idlelib.searchengine.SearchEngine for search capability. Defines various replace related functions like replace, replace all, and replace+find. N) StringVarTclError)SearchDialogBase) searchenginec|}tj|}t|dst |||_|j}|||dS)zCreate or reuse a singleton ReplaceDialog instance. The singleton dialog saves user entries and preferences across instances. Args: text: Text widget containing the text to be searched. _replacedialog) insert_tagsN)_rootrgethasattr ReplaceDialogropen)textr rootenginedialogs ..\python\lib\idlelib\replace.pyreplacersj ::<>E7799D&&q$//C{6688DAqtQi'EdAY&Dd{{ h---- h...D==KKt,,,>KKsD,<===c#hh,CB)[//dD#Eb0:::c *   'T ' MM% & & & rFc@|jsdS|j}|j|d|}|s|dS|\}}|\}}d||fz}d||fz} ||| d|_dS)z|Search for and highlight next occurrence of pattern in text. No text replacement is done with this option. FNrOT)rrPrrQrRrYr#r$) rr$rr`rarCrerfr%r&s rr6zReplaceDialog.do_finds {""$$ 5yk%%dD"55  IIKKK5avvxx14)#$" eT"""trcr|j}|sdS|j} |dx}}|d}n#t$rd}YnwxYw|s|dx}x}}t j|\}}|d|zd|dzz}|||} |sdS| | |j } | dS| d|| | r|||| r||| |j||||dd|_dS) z6Replace search pattern in text with replacement value.Frr Nr!rNrLT)rrPrr"rr get_line_colr matchrFrrZrVrXr[r!r r]r#r$) rr_rr%posr&rarbrcrCrEs rr;zReplaceDialog.do_replaces{""$$ 5y **[11 1EC::j))DD   CCC  6!%H!5!5 5E 5D3 -c22 c$$q&(9:: JJuc " " 5""1dl&6&6&8&899 ;5 h&&&  7799 % KKt $ $ $  6 KKsD$4 5 5 5  eTZZ11222ts,A A"!A"c|j}|d||ddd|d|||ddd||kr|d|n|d|||d|dS)aHighlight text between first and last indices. Text is highlighted via the 'hit' tag and the marked section is brought into view. The colors from the 'hit' tag aren't currently shown when the text is displayed. This is due to the 'sel' tag being added first, so the colors in the 'sel' config are seen instead of the colors for 'hit'. r!rHrIrJrKN)rrZrStag_addseeupdate_idletasks)rr%r&rs rr#zReplaceDialog.show_hitsy h&&& ue,,, UE4((( ue,,, D== LL & & & & LLt , , ,  rcvtj|||jdddd|_dS)z%Close the dialog and remove hit tags.rKrIrJN)rr^rrSr r7s rr^zReplaceDialog.closes=tU+++ UE5111rN)F)__name__ __module__ __qualname____doc__titleiconrrr(r/r1r2r3rFr4r6r;r#r^ __classcell__)rs@rr r s$99 E D     "''''0III : : : $ $ $ $   6666p(@   .        rr c ddlm}m}m mddlm}m}||}|dtt| ddd\}}| d||dzfzd }d } ||} | || d |_| _ d d fd} || d| } | dS)Nr)ToplevelTextENDSEL)FrameButtonzTest ReplaceDialog+rLz+%d+%dcdSrqrrrrVz)_replace_dialog..undo_block_start rcdSrqrrrrr]z(_replace_dialog..undo_block_stoprrgray)inactiveselectbackgroundr!z"This is a sample sTring Plus MORE.cdtddS)NrI)rmrrS)r|r}rsr show_replacez%_replace_dialog..show_replace&s@ S%%%%  UC(((((rr)rcommand)tkinterrzr{r|r} tkinter.ttkr~rrvmapintgeometrysplitpackrVr]r! focus_set)parentrzr{r~rtopxyrVr]framerbuttonr|r}rs @@@r_replace_dialogr s000000000000)))))))) (6  CII"### sFOO%%++C004 5 5DAqLLQCL()))       E#JJE JJLLL 4 7 7 7D,D*DIIKKKKK>???NN))))))) VE < @ @ @F KKMMMMMr__main__)mainzidlelib.idle_test.test_replaceF) verbosityexit)runrq)rur@rrridlelib.searchbaseridlelibrrr rrrunittestridlelib.idle_test.htestrrrrrs  ''''''''////// ////"k k k k k $k k k \B zD )QUCCCC++++++C r