BUhi+dZddlZeje_ddlmZmZddlmZddl m Z ddZ GddeZ d Z ed k(r dd lmZed d dddlmZee yy)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|j}tj|}t|dst |||_|j }|jdd}|j |||y)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 sel.firstsel.last insert_tagsN)_rootrgethasattr ReplaceDialogropen)textr rootenginedialog searchphrases 6/opt/alt/python312/lib64/python3.12/idlelib/replace.pyreplacersf ::E779D&&q$/C{668DAqtQi'EdAY&Dd{ h- h.D=KKt,KKsD,<,<=c#h,CB)[[//dD#Eb0::c:*  T MM% & rc0|jjsy|j}|jj|d|}|s|j y|\}}|j \}}d||fz}d||fz} |j || d|_y)z|Search for and highlight next occurrence of pattern in text. No text replacement is done with this option. FNrLT)rrNrrOrPrWr\r#) r r#rr_r`r@rfrgrbrcs rr3zReplaceDialog.do_finds {{""$yykk%%dD"5 IIKavvx14)#$" eT"rc|jj}|sy|j} |jdx}}|jd}|s|jdx}x}}t j |\}}|jd|zd|dzz}|j||} |sy|j| |jj} | y|jd|j| jr|j|| r|j|| |j |j#|j%||jdd|_y#t$rd}Y6wxYw) z6Replace search pattern in text with replacement value.Fr r NrMrKrIT)rrNrindexrr get_line_colrmatchrCrrXrTrVrYrMr r[r\r#) r r^rrbposrcr`rardr@rBs rr8zReplaceDialog.do_replacesa{{""$yy **[1 1EC::j)D!%H!5 5E 5D3 --c2 c$$q&(9: JJuc """1dll&6&6&89 ; h&  779 KKt $  KKsD$4$4 5  eTZZ12+ C s$E77 FFcJ|j}|jd||jddd|jd|||jddd||k(r|jd|n|jd|||j d|j y)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'. rMrErFrGrHN)rrXrQtag_addseeupdate_idletasks)r rbrcrs rr\zReplaceDialog.show_hitsyy h& ue, UE4( ue, D= LL & LLt ,  rcxtj|||jjdddd|_y)z%Close the dialog and remove hit tags.rHrFrGN)rr]rrQr r4s rr]zReplaceDialog.closes0tU+ UE51rN)F)__name__ __module__ __qualname____doc__titleiconrrr%r,r.r/r0rCr1r3r8r\r] __classcell__)r!s@rrr!s[9 E D " '4 'I : $ 6p(@ . rrc ddlm}m}m mddlm}m}||}|jdtt|jjddd\}}|jd||dzfzd }d } ||} | j|| d |_| _jj!d dj# fd} || d| } | jy)Nr)ToplevelTextENDSEL)FrameButtonzTest ReplaceDialog+rIz+%d+%dcyrsrrrrTz)_replace_dialog..undo_block_start rcyrsrrrrr[z(_replace_dialog..undo_block_stoprrgray)inactiveselectbackgroundrMz"This is a sample sTring Plus MORE.chjdtjdy)NrF)rorrQ)r~rrsr show_replacez%_replace_dialog..show_replaces* S%%  UC(rr)rcommand)tkinterr|r}r~r tkinter.ttkrrrxmapintgeometrysplitpackrTr[rM focus_set)parentr|r}rrtopxyrTr[framerbuttonr~rrs @@@r_replace_dialogrs00) 6 CII"# sFOO%++C04 5DAqLLQCL()   #JE JJL  7D,D*DIIKKK>?NN) E < @F KKMr__main__)mainzidlelib.idle_test.test_replaceF) verbosityexit)runrs)rwr=errorr>rrridlelib.searchbaseridlelibrrrrrtunittestridlelib.idle_test.htestrrrrrsh  (('/ =$a $a HD z )QUC+ r