From: Kevin A. <al...@se...> - 2004-10-05 21:56:53
|
On Oct 5, 2004, at 2:19 PM, Alex Tweedly wrote: > > Two questions .... > > 1. Is this a bug ? > I think there's a bug in that findfiles only does a yield when it=20 > successfully finds the string that you're searching for. If you do a=20= > findfiles for some string that never occurs, the window is=20 > non-responsive until the search is complete. > > The "inner loop" is > =A0=A0=A0=A0=A0=A0=A0 for dir in self.dirpattern.split(';'): > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 for filename in util.dirwalk(dir, = patterns, self.recurse): > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if = self.SearchFile(filename): > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 found +=3D = 1 > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = self.statusBar.text =3D "Files found: %d" % found > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if = self.stopSearching: > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = break > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = wx.SafeYield(self) > > > I think the wx.SafeYield(self) should be outside the "if" block, so=20 > that it occurs for each file. Fixed > 2. What's the best way to protect yourself from recursive SafeYield=20= > calls ? > In this case it would be easy enough - just add a flag (or re-use=20 > StopSearching) which is set at the start of the search, and reset at=20= > the (normal) end; then the menu handler can check for a search already=20= > in progress, and avoid starting another.=A0 Since SafeYield is only=20 > called within the search, this would fix it for findfiles. That should have been a wx.SafeYield(self, True) call, the second arg=20 is yieldIfNeeded. > But in the general case, there could be SafeYield calls within many=20= > different processing loops. Is there a way to tell if you are "already=20= > yielded" ?=A0 > > (btw - is wx.SafeYield" documented somewhere ? ) > wx.SafeYield is a wxPython method, so it is documented in the new=20 wxPython-specific docs, but you can also look at the help for it in the=20= shell, just type wx.SafeYield( and it should popup. It is a bit=20 confusing to know when to use wx.Yield, wx.SafeYield, or=20 wx.YieldIfNeeded. In the case of findfiles you want to be able to click=20= a Cancel button to end the search, so I added one of those as well as=20 be able to start viewing a file or make other changes before the search=20= of all of the files is done so wx.SafeYield seems like the right choice=20= and setting the yieldIfNeeded flag to True should prevent a recursive=20 call problem. That's about as far as my knowledge goes, so further=20 questions should go to wxPython-users. ka |