Hello,
I've written a small script to do recursive searches of files, with an interface (so I don't have to remember all of the flags!). Anyway, everything works fine, except I can't seem to get it so that the textbox of the results (or any part of the frame, for that matter) refreshes as the results come in, rather than at the very end. I include the script below, but I've tried self.Refresh(), self.Update() on the frame, panel, textbox, etc... to no avail. I'd like to change the cursor to a watch too, but the panel.SetCursor() calls didn't work, because the frame didn't update. Any ideas?
thanks,
Brian Blais
···
--
-----------------
bblais@bryant.edu
http://web.bryant.edu/~bblais
#!/usr/bin/env python
import sys, os
from wax import *
class MainFrame(Frame):
def __init__(self,parent=None,title='',direction='H',
size=(800,800),params=None):
Frame.__init__(self,parent,title,direction,size)
def Body(self):
self.CenterOnScreen()
self.CreateMenu()
panel=Panel(self,direction='vertical')
p=Panel(self,direction='horizontal')
l=Label(p,'Search String')
p.AddComponent(l,align='c',expand='h')
self.search_tb = TextBox(p, multiline=0, wrap=0)
p.AddComponent(self.search_tb,align='c',expand='h')
p.Pack()
panel.AddComponent(p,align='c',expand='h')
p=Panel(self,direction='horizontal')
l=Label(p,'File Filter')
p.AddComponent(l,align='c',expand='h')
self.filter_tb = TextBox(p, '*',multiline=0, wrap=0)
p.AddComponent(self.filter_tb,align='c',expand='h')
p.Pack()
panel.AddComponent(p,align='c',expand='h')
self.recursive_cb=CheckBox(panel,"Recursive")
self.recursive_cb.SetValue(True)
panel.AddComponent(self.recursive_cb,align='c',expand='h')
self.case_cb=CheckBox(panel,"Case Senstive")
self.case_cb.SetValue(True)
panel.AddComponent(self.case_cb,align='c',expand='h')
panel.AddComponent(Button(panel,"Go!",event=self.Search),align='c',expand='h')
self.results_tb = TextBox(panel, multiline=1, wrap=0,size=(600,400))
panel.AddComponent(self.results_tb,align='c',expand='h')
panel.Pack()
self.AddComponent(panel, expand='both', border=3)
self.Pack()
self.panel=panel
if len(sys.argv)>1:
self.search_tb.SetValue(sys.argv[1])
if len(sys.argv)>2:
self.filter_tb.SetValue(sys.argv[2])
def Search(self,event=None):
search_string=self.search_tb.GetValue()
recursive=self.recursive_cb.GetValue()
case_sensitive=self.case_cb.GetValue()
file_filter=self.filter_tb.GetValue()
if not search_string:
return
cmd="grep -H -n "
if not case_sensitive:
cmd+="-i "
if recursive:
cmd+="-r "
if file_filter:
cmd+="--include=%s " % file_filter
cmd+="-e '%s' * " % search_string
else:
cmd+="-e '%s' %s " % (search_string,file_filter)
s=""
fid=os.popen(cmd,'r')
self.results_tb.SetValue(fid.read())
fid.close()
def CreateMenu(self):
menubar = MenuBar()
menu1 = Menu(self)
menu1.Append("&Quit", self.Quit, "Quit",hotkey="Ctrl+Q")
menubar.Append(menu1, "&File")
self.SetMenuBar(menubar)
def Quit(self,event):
self.Close()
app = Application(MainFrame, title="Greppy!")
app.Run()