B €/g^¾ã@sšdZddlmZddlmZddlmZdd„Zdd„Zd d „Z d d „Z Gd d„deƒZ dd„Z e dkr–ddlmZeddddddlmZee ƒdS)z¨Search 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|dƒs(t||ƒ|_|jS)zÜReturn 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)Z_rootrÚgetÚhasattrÚ SearchDialogr)ÚtextÚrootÚengine©r ú&/usr/lib64/python3.7/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. z sel.firstzsel.last)rrÚopen)r Úpatr r r Úfinds 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_again)r r r r r&s rcCst|ƒ |¡S)a“Search 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. )rÚfind_selection)r r r r r1s rc@s2eZdZdZdd„Zd dd„Zdd„Zd d „ZdS) rz%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)rÚcreate_widgetsZ make_buttonÚdefault_command)Úselfr r r rAs zSearchDialog.create_widgetsNcCs|j ¡sdS| |j¡dS)z3Handle the Find Next button as the default command.N)r Úgetprogrr )rZeventr r r rGs zSearchDialog.default_commandc Cs|j ¡s| |¡dS|j ¡s&dS|j |¡}|rð|\}}| ¡\}}d||f}d||f}y4| d¡} | d¡} | |kr”| |kr”| ¡dSWntk rªYnX|  ddd¡|  d||¡|  d|j  ¡rÜ|pÞ|¡|  d¡d 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.%dz sel.firstzsel.lastÚselz1.0ÚendÚinsertTN)r ZgetpatrrZ search_textÚspanÚindexZbellrÚ tag_removeÚtag_addZmark_setZisbackZsee) rr ZresÚlineÚmÚiÚjÚfirstZlastZselfirstZsellastr r r rMs4          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. z sel.firstzsel.last)rr Z setcookedpatr)rr rr r r rys  zSearchDialog.find_selection)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrr r r r r>s  ,rc s¾ddlm}m}ddlm}m}||ƒ}| d¡tt|  ¡  d¡dd…ƒ\}}|  d||d f¡||ƒ}|  ¡||d d ‰ˆ  ¡ˆ  d d ¡‡fdd„} ||d| d} |   ¡dS)zDisplay search test box.r)ÚToplevelÚText)ÚFrameÚButtonzTest SearchDialogú+éNz+%d+%dé¯Zgray)Zinactiveselectbackgroundrz}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.ˆ ddd¡tˆƒ ˆ¡ˆ ddd¡dS)Nrz1.0r)rrrrr )r r r Ú show_find—sz!_search_dialog..show_findzSearch (selection ignored))r Zcommand) Útkinterr(r)Z tkinter.ttkr*r+ÚtitleÚmapÚintZgeometryÚsplitZpackr) Úparentr(r)r*r+ÚtopÚxÚyÚframer/Zbuttonr )r r Ú_search_dialog‡s     r:Ú__main__)Úmainzidlelib.idle_test.test_searchéF)Ú verbosityÚexit)ÚrunN)r'r0rZidlelibrZidlelib.searchbaserrrrrrr:r$Zunittestr<Zidlelib.idle_test.htestr@r r r r Ús      I