\d7dZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddZ dZd ZGd d e Zd Zed kr'ddlmZedddddlmZeedSdS)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 |}tj|}t|dst ||||_|j}|dd}||||dS)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 ..\python\lib\idlelib\grep.pygreprs~ ::<zfindfiles..9sX77tW557BGLL$//777777rN)r"walkr)folderr( recursive_ filenamesr's ` @r findfilesr/0s"$!D!D!DI77777 )777 7 7 7 7 7 7 7  EE  rcVeZdZdZdZdZdZfdZd dZdZ d Z d Z d d Z d Z xZS)r z$Dialog for searching multiple files.zFind in Files DialogGreprct||||_t||_t ||_dS)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__GsF v&&&    && rNcTtj||||r |jpd}nd}tj|\}}tj|\}}|sd}|jtj |d|zdS)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,777  ;$"DDDGMM$'' TW%%d++ d D c3:6677777rcztj||d|jd|_dS)z9Create base entry widgets and add widget for search path.z In files:rN)rcreate_entries make_entryr5globentr7s rrEzGrepDialog.create_entriesps3'---{DLAA!D rct|d|jd}|dddS)z0Add check button to recurse down subdirectories.rzRecurse down subdirectories)variablertopboth)sidefillN)r make_framer6pack)r7btns rcreate_other_buttonszGrepDialog.create_other_buttonsusM!!!$t{2444 e&)))))rchtj||d|jddS)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{""$$  F|!!  HMMOOO F//////z %dj11CJ LLt $ $ $CJJJCJ    s '0B%%B3c 8tj|\}}|s tj}t t |||j}||j }td|d|dd} |D]} t|d5} t| dD]_\} } | dd d kr | d d} || r-tj|d | d | d |dz }` d d d n #1swxYwY#t$$r} t| Yd } ~ d } ~ wwxYwt|rd |d ndd S#t&$rYd SwxYw)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_its4'---- YF)FGT[__5F5FGGHH k  "" 0300d000111    b333*q,5aOO**LFD#BCCyD00'+CRCy#{{400* # 0 0B1L1L&1L1LD1L1L1L M M M $  ****************#JJJJJJJJ *OOOOO) + + + + +    DD sa,F 1E A1E4 E E E E E  F E/E*%F *E//F FFr )__name__ __module__ __qualname____doc__titleiconneedwrapbuttonr4rrErRrUrWr_ __classcell__)r8s@rr r @s** "E DN'''''&8888,EEE ***KKK .%%%%%%%rr c2 ddlm}m}m m ddlm}m}ddlm }||}| dtt| ddd\}}| d|d|dz||||} | || d  fd } || d | } | dS)Nr)ToplevelTextSELEND)FrameButton)PyShellFileListzTest GrepDialog+rf)heightcdtddS)Nz1.0)r)tag_addr tag_remove)rrrrsrshow_grep_dialogz&_grep_dialog..show_grep_dialogsH S%%%% T UC(((((rzShow GrepDialog)rcommand)tkinterrrrr tkinter.ttkrridlelib.pyshellrr~mapintgeometryr=rP)parentrrrrrrKxyframerbuttonrrrrs @@@@r _grep_dialogrsn000000000000))))))))////// (6  CII   sFOO%%++C004 5 5DAqLL"Q""S""### OC E E#JJE JJLLL 4a DIIKKK)))))))) VE 1;K L L LF KKMMMMMr__main__)mainzidlelib.idle_test.test_grepF) verbosityexit)run)NN)r}r!r"r]rrrrridlelib.searchbaseridlelibrrrr/r rrzunittestridlelib.idle_test.htestrrrrsV  ))))))))######////// ((((.    }}}}}!}}}@0 zD &!%@@@@++++++C  r