a  ze@sdZddlmZddlmZddlmZddZddZd d Z d d Z Gd ddeZ ddZ e dkrddlmZeddddddlmZee dS)zSearch dialog for Find, Find Again, and Find Selection functionality. Inherits from SearchDialogBase for GUI and uses searchengine to prepare search pattern. )TclError) searchengine)SearchDialogBasecCs.|}t|}t|ds(t|||_|jS)zReturn the new or existing singleton SearchDialog instance. The singleton dialog saves user entries and preferences across instances. Args: text: Text widget containing the text to be searched. _searchdialog)_rootrgethasattr SearchDialogr)textrootenginer B/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/search.py_setup s    rcCs|dd}t|||S)a Open the search dialog. Module-level function to access the singleton SearchDialog instance and open the dialog. If text is selected, it is used as the search phrase; otherwise, the previous entry is used. No search is done with this command. sel.firstsel.last)rropen)r patr r rfinds rcCst||S)aSRepeat the search for the last pattern and preferences. Module-level function to access the singleton SearchDialog instance to search again using the user entries and preferences from the last dialog. If there was no prior search, open the search dialog; otherwise, perform the search without showing the dialog. )r find_againr r r rr&s rcCst||S)aSearch for the selected pattern in the text. Module-level function to access the singleton SearchDialog instance to search using the selected text. With a text selection, perform the search without displaying the dialog. Without a selection, use the prior entry as the search phrase and don't display the dialog. If there has been no prior search, open the search dialog. )rfind_selectionrr r rr1s rc@s2eZdZdZddZd ddZddZd d ZdS) r z%Dialog for finding a pattern in text.cCs t||jd|jdddS)z=Create the base search dialog and add a button for Find Next.z Find NextT)ZisdefN)rcreate_widgetsZ make_buttondefault_command)selfr r rrAs zSearchDialog.create_widgetsNcCs|jsdS||jdS)z3Handle the Find Next button as the default command.N)r getprogrr )reventr r rrGs zSearchDialog.default_commandc Cs|js||dS|js&dS|j|}|r|\}}|\}}d||f}d||f}z6|d} |d} | |kr| |kr|WdSWntyYn0| ddd| d||| d|j r|p|| dd S|dSd S) a2Repeat the last search. If no search was previously run, open a new search dialog. In this case, no search is done. If a search was previously run, the search dialog won't be shown and the options from the previous search (including the search pattern) will be used to find the next occurrence of the pattern. Next is relative based on direction. Position the window to display the located occurrence in the text. Return True if the search was successful and False otherwise. Fz%d.%drrsel1.0endinsertTN)r ZgetpatrrZ search_textspanindexZbellr tag_removetag_addZmark_setZisbackZsee) rr reslinemijfirstZlastZselfirstZsellastr r rrMs4            zSearchDialog.find_againcCs&|dd}|r|j|||S)a/Search for selected text with previous dialog preferences. Instead of using the same pattern for searching (as Find Again does), this first resets the pattern to the currently selected text. If the selected text isn't changed, then use the prior search phrase. rr)rr Z setcookedpatr)rr rr r rrys  zSearchDialog.find_selection)N)__name__ __module__ __qualname____doc__rrrrr r r rr >s  ,r c sddlm}m}ddlm}m}||}|dtt| ddd\}}| d||d f||}| ||d d   d d fdd} ||d| d} | dS)zDisplay search test box.r)ToplevelText)FrameButtonzTest SearchDialog+Nz+%d+%dZgray)Zinactiveselectbackgroundr z}This is a sample string. This is a sample string. This is a sample string. This is a sample string. This is a sample string. cs.dddtddddS)Nrrr)r$rrr#r rr r show_findsz!_search_dialog..show_findzSearch (selection ignored))r Zcommand) tkinterr/r0Z tkinter.ttkr1r2titlemapintZgeometrysplitpackr ) parentr/r0r1r2topxyframer6Zbuttonr rr_search_dialogs     rB__main__)mainzidlelib.idle_test.test_searchF) verbosityexit)runN)r.r7rZidlelibrZidlelib.searchbaserrrrrr rBr+ZunittestrDZidlelib.idle_test.htestrHr r r rs      I