B uW@sddlZddlZddlZddlmZmZddlmZddlm Z ddl m Z dddZ dd Z d d ZGd d d e ZddZedkrddlmZeddddddlmZeedS)N) StringVar BooleanVar) Checkbutton)SearchDialogBase) searchenginecCsN|}t|}t|ds*t||||_|j}|dd}||||dS)N _grepdialogz sel.firstzsel.last)Z_rootrgethasattr GrepDialogropen)textioflistrootengineZdialog searchphraser//opt/alt/python37/lib/python3.7/idlelib/grep.pygreps   rcCs t|dS)N)print)msgrrr walk_error+src#sBx9szfindfiles..)rwalkr)folderr recursive_ filenamesr)rr r findfiles0s  r'cs\eZdZdZdZdZfddZdddZd d Zd d Z d dZ dddZ ddZ Z S)r zFind in Files DialogZGreprcs,t||||_t||_t||_dS)N)super__init__rrglobvarrrecvar)selfrrr) __class__rrr)Gs zGrepDialog.__init__Nc Csht||||r|jpd}nd}tj|\}}tj|\}}|sJd}|jtj |d|dS)Nz.py*) rr filenamerrsplitsplitextr*setr) r,r rr rdirbaseheadtailrrrr Zs  zGrepDialog.opencCs"t||d|jd|_dS)Nz In files:r)rcreate_entriesZ make_entryr*Zglobent)r,rrrr8ps zGrepDialog.create_entriescCs*t|d|jdd}|jddddS)NrzRecurse down subdirectories)variabler topZboth)Zsidefill)rZ make_framer+pack)r,Zbtnrrrcreate_other_buttonsuszGrepDialog.create_other_buttonscCs t||jd|jdddS)Nz Search FilesT)Zisdef)rcreate_command_buttonsZ make_buttondefault_command)r,rrrr>|s z!GrepDialog.create_command_buttonscCsj|j}|sdS|j}|s.|jdSddlm}tj }z||j t_ | ||Wd|t_ XdS)Nr) OutputWindow) rZgetprogr*rr:ZbellZidlelib.outwinr@sysstdoutrgrep_it)r,Zeventprogrr@Zsaverrrr?s     zGrepDialog.default_commandc CsRtj|\}}|stj}tt|||j}||j }t d|d|dd}yx|D]}yt |ddj} xbt | dD]T\} } | ddd kr| dd} || rtj|d | d | d |d7}qWWdQRXWqdtk r} z t | Wdd} ~ XYqdXqdWt |r.d |d nd Wntk rLYnXdS)Nz Searching z in z ...rreplace)errors z: z Hits found: z' (Hint: right-click to open locations.)zNo hits.)rrr1curdirsortedr'r+rcloserZgetpatrr enumeratesearchrArBwriteOSErrorAttributeError) r,rDrr#ZfilepatZfilelistZpathitsfnflinenolinerrrrrCs0     zGrepDialog.grep_it)N)N)__name__ __module__ __qualname__titleZiconZneedwrapbuttonr)r r8r=r>r?rC __classcell__rr)r-rr @s   r c sddlm}m}mmddlm}m}ddlm }||}| dt t | ddd\}}| d|d|d||||} | || d d fd d } || d | d} | dS)Nr)ToplevelTextSELEND)FrameButton)PyShellFileListzTest GrepDialog+rG)Zheightcs,dtdddS)Nz1.0)r)Ztag_addrZ tag_remover)r_r^rr rrshow_grep_dialogs z&_grep_dialog..show_grep_dialogzShow GrepDialog)r Zcommand)tkinterr\r]r^r_ tkinter.ttkr`raZidlelib.pyshellrbrZmapintZgeometryr1r<) parentr\r]r`rarbr:xyframerfZbuttonr)r_r^rr r _grep_dialogs    ro__main__)mainzidlelib.idle_test.test_grepF) verbosityexit)run)NN)rrrArgrrrhrZidlelib.searchbaserZidlelibrrrr'r rorWZunittestrqZidlelib.idle_test.htestrurrrrs"