U :e7@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 searchphraser1/usr/local/python38/lib/python3.8/idlelib/grep.pygreps   rcCs t|dSN)print)msgrrr walk_error+src#s@tj|tdD],\}}fdd|DEdH|sq9s zfindfiles..)rwalkr)folderr" recursive_ filenamesrr r findfiles0s   r)cs\eZdZdZdZdZfddZdddZd d Zd d Z d dZ dddZ ddZ Z S)r zFind in Files DialogZGreprcs,t||||_t||_t||_dSr)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,Zglobentr.rrrr;ps zGrepDialog.create_entriescCs*t|d|jdd}|jddddS)NrzRecurse down subdirectories)variabler topZboth)Zsidefill)rZ make_framer-pack)r.Zbtnrrrcreate_other_buttonsus  zGrepDialog.create_other_buttonscCs t||jd|jdddS)Nz Search FilesT)Zisdef)rcreate_command_buttonsZ make_buttondefault_commandr<rrrrB|s z!GrepDialog.create_command_buttonscCsj|j}|sdS|j}|s.|jdSddlm}tj }z||j t_ | ||W5|t_ XdS)Nr) OutputWindow) rZgetprogr,rr>ZbellZidlelib.outwinrDsysstdoutrgrep_it)r.eventprogrrDsaverrrrCs     zGrepDialog.default_commandc CsJtj|\}}|stj}tt|||j}||j }t d|d|dd}z|D]}z|t |ddf} t | dD]T\} } | ddd kr| dd} || rtj|d | d | d |d7}qW5QRXWqbtk r} z t | W5d} ~ XYqbXqbt |r&d |d nd Wntk rDYnXdS)Nz Searching z in z ...rreplace)errors z: z Hits found: z' (Hint: right-click to open locations.)zNo hits.)rrr4curdirsortedr)r-rcloserZgetpatrr enumeratesearchrErFwriteOSErrorAttributeError) r.rIrr%ZfilepatZfilelistpathitsfnflinenolinerrrrrGs6    zGrepDialog.grep_it)N)N)__name__ __module__ __qualname__titleZiconZneedwrapbuttonr+r r;rArBrCrG __classcell__rrr/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+rM)Zheightcs,dtdddS)Nz1.0)r)Ztag_addrZ tag_removerrfrerr rrshow_grep_dialogs z&_grep_dialog..show_grep_dialogzShow GrepDialog)r Zcommand)tkinterrcrdrerf tkinter.ttkrgrhZidlelib.pyshellriramapintZgeometryr4r@) parentrcrdrgrhrir>xyframernZbuttonrrmr _grep_dialogs    rw__main__)mainzidlelib.idle_test.test_grepF) verbosityexit)run)NN)rrrErorrrprZidlelib.searchbaserZidlelibrrrr)r rwr^ZunittestryZidlelib.idle_test.htestr}rrrrs"