A͈dZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddZ dZd ZGd d e Zd Zed k(r ddlmZedddddlmZeeyy)zGrep dialog for Find in Files functionality. Inherits from SearchDialogBase for GUI and uses searchengine to prepare search pattern. N) StringVar BooleanVar) Checkbutton)SearchDialogBase) searchenginec|j}tj|}t|dst ||||_|j }|jdd}|j |||y)aOpen the Find in Files dialog. Module-level function to access the singleton GrepDialog instance and open the dialog. If text is selected, it is used as the search phrase; otherwise, the previous entry is used. Args: text: Text widget that contains the selected text for default search phrase. io: iomenu.IOBinding instance with default path to search. flist: filelist.FileList instance for OutputWindow parent. _grepdialogz sel.firstzsel.lastN)_rootrgethasattr GrepDialogr open)textioflistrootenginedialog searchphrases 3/opt/alt/python312/lib64/python3.12/idlelib/grep.pygreprse ::zfindfiles..9s67 )tW5GGLL$/ )sAAN)r"walkr)folderr( recursive_ filenamesr's ` @r findfilesr/0sJ"$!DI7 )7 7 7  "E 7s2AAAAcVeZdZdZdZdZdZfdZd dZdZ dZ d Z d d Z d Z xZS) r z$Dialog for searching multiple files.zFind in Files DialogGreprctt|||||_t||_t ||_y)a-Create search dialog for searching for a phrase in the file system. Uses SearchDialogBase as the basis for the GUI and a searchengine instance to prepare the search. Attributes: flist: filelist.Filelist instance for OutputWindow parent. globvar: String value of Entry widget for path to search. globent: Entry widget for globvar. Created in create_entries(). recvar: Boolean value of Checkbutton widget for traversing through subdirectories. N)super__init__rrglobvarrrecvar)selfrrr __class__s rr4zGrepDialog.__init__Gs2 v&    & rcdtj||||r|jxsd}nd}tjj |\}}tjj |\}}|sd}|jjtjj|d|zy)a_Make dialog visible on top of others and ready to use. Extend the SearchDialogBase open() to set the initial value for globvar. Args: text: Multicall object containing the text information. searchphrase: String phrase to search. io: iomenu.IOBinding instance containing file path. z.py*N) rrfilenamer"r#splitsplitextr5setr$) r7rrrr#dirbaseheadtails rrzGrepDialog.openZs dD,7 ;;$"DDGGMM$' TWW%%d+ dD c3:67rcvtj||jd|jd|_y)z9Create base entry widgets and add widget for search path.z In files:rN)rcreate_entries make_entryr5globentr7s rrEzGrepDialog.create_entriesps+''-{DLLA!D rc|t|jd|jd}|jddy)z0Add check button to recurse down subdirectories.rzRecurse down subdirectories)variablertopboth)sidefillN)r make_framer6pack)r7btns rcreate_other_buttonszGrepDialog.create_other_buttonsus6!!$t{{24 e&)rcjtj||jd|jdy)z. If entry values are populated, set OutputWindow as stdout and perform search. The search dialog is closed automatically when the search begins. Nr) OutputWindow) rgetprogr5r rKbellidlelib.outwinrYsysstdoutrgrep_it)r7eventprogr#rYsaves rrWzGrepDialog.default_commands{{""$ ||! HHMMO /zz %djj1CJ LLt $CJCJs ,-B%% B2c tjj|\}}|stj}t t |||j j}|j|jj}td|d|dd} |D]z} t|d5} t| dD]Q\} } | dd d k(r| d d} |j| s%tj j#|d | d | d |dz }S d d d |t|r d |d y dy #1swY$xYw#t$$r} t| Yd } ~ d } ~ wwxYw#t&$rYy wxYw)aSearch for prog within the lines of the files in path. For the each file in the path directory, open the file and search each line for the matching pattern. If the pattern is found, write the file and line information to stdout (which is an OutputWindow). Args: prog: The compiled, cooked search pattern. path: String containing the search path. z Searching z in z ...rreplace)errorsN z: z Hits found: z' (Hint: right-click to open locations.)zNo hits.)r"r#r=curdirsortedr/r6r closergetpatrr enumeratesearchr]r^writeOSErrorAttributeError) r7rar#r+filepatfilelistpathitsfnflinenoliners rr_zGrepDialog.grep_itsd''---YYF)FGT[[__5FGH kk  " 3'dV401  b3q,5aOLFD#BCyD0'+CRy#{{40 # 0 0B4r&D61L M $  -<4 !&NO +) +43#JJ   s`"E'( E51D:'/D:EE'3E':E ?E E$ EE'E$$E'' E32E3r )__name__ __module__ __qualname____doc__titleiconneedwrapbuttonr4rrErRrUrWr_ __classcell__)r8s@rr r @s:* "E DN'&8,E *K .%rr c ddlm}m}m ddlm}m}ddlm}||}|jdtt|jjddd\}}|jd|d|dz|| ||} | j|| d jjd d  fd } || d| } | jy)Nr)ToplevelTextSEL)FrameButton)PyShellFileListzTest GrepDialog+rf)height1.0z import grepcljddtjddy)Nrz1.end)r)tag_addr tag_remove)rrrsrshow_grep_dialogz&_grep_dialog..show_grep_dialogs- S%) T UG,rzShow GrepDialog)rcommand)tkinterrrr tkinter.ttkrridlelib.pyshellrr~mapintgeometryr=rPinsert)parentrrrrrrKxyframerbuttonrrrs @@@r _grep_dialogrs++)/ 6 CII sFOO%++C04 5DAqLL1QCqS "# C E #JE JJL a DIIKKK}%- E 1;K LF KKMr__main__)mainzidlelib.idle_test.test_grepF) verbosityexit)run)NN)r}r!r"r]rrrrridlelib.searchbaseridlelibrrrr/r rrzunittestridlelib.idle_test.htestrrrrso  )#/ (.  }!}@4 z &!%@+  r