text defaultand skip files that fail to decodein worst casesusers may need to run grep times if encodings might existelse opens may raise exceptionsand opening in binary mode might fail to match encoded text against search stringtbdbetter to issue an error if any file fails to decodebut utf- -bytes/char format created in notepad may decode without error per utf- and search strings won' be foundtbdcould allow input of multiple encoding namessplit on commatry each one for every filewithout open loadencode""from pp gui shellgui formrows import makeformrow nonmodal dialogget dirnnamefilenamepattgrepkey popup toplevel(popup title('pyedit grep'var makeformrow(popuplabel='directory root'width= browse=falsevar makeformrow(popuplabel='filename pattern'width= browse=falsevar makeformrow(popuplabel='search string'width= browse=falsevar makeformrow(popuplabel='content encoding'width= browse=falsevar set('current dir var set('py'initial values var set(sys getdefaultencoding()for file contentnot filenames cb lambdaself ondogrep(var get()var get()var get()var get()button(popuptext='go',command=cbpack(def ondogrep(selfdirnamefilenamepattgrepkeyencoding)""on go in grep dialogpopulate scrolled list with matches tbdshould producer thread be daemon so it dies with app""import threadingqueue make non-modal un-closeable dialog mypopup tk(mypopup title('pyedit grepping'status label(mypopuptext='grep thread searching for% grepkeystatus pack(padx= pady= mypopup protocol('wm_delete_window'lambdanoneignore close start producer threadconsumer loop myqueue queue queue(threadargs (filenamepattdirnamegrepkeyencodingmyqueuethreading thread(target=self grepthreadproducerargs=threadargsstart(self grepthreadconsumer(grepkeyencodingmyqueuemypopupdef grepthreadproducer(selffilenamepattdirnamegrepkeyencodingmyqueue)""in non-gui parallel threadqueue find find results listcould also queue matches as foundbut need to keep windowfile content and file names may both fail to decode heretbdcould pass encoded bytes to find(to avoid filename decoding excs in os walk/listdirbut which encoding to use complete gui programs