It would be my pleasure to share with you some of the things I have learned.
The more information you can give about what your trying to do, and what
you're having a problem with would be great, but I'll throw some generals
at you, and your reply can give some code.
This is how I did it with my program in general.
I establish a variable that reads the total lines of the log file.
Let's call it self.InitLineCount with an initial value of zero. And a variable
so this is less confusing for the path to your log file. You'll also need to
import linecache
import linecache
self.InitLineCount = 0
self.LogPath = C:\yourdirectory\yoursubdir\logfile.txt
The next thing we need to do is set up a way of polling that
log file at a regular interval. I haven't done much with threading,
but wx.Timer works just fine for me. The function below creates
the timer, sets the interval something happens, and then bind that
"something" to the timer so it happens over and over. Create a
button and bind it to the event below:
def StartPolling(self, event):
self.Interval = wx.Timer(self, id=wx.NewId())
self.Bind(wx.EVT_TIMER, self.ProcessLog)
self.Interval.Start(1000) # 1000 = about 1 second
event.Skip()
You'll need another button to stop the wx.Timer. Maybe
instead of 2 buttons you use a check box, or something, but this
example is generalized.
def StopPolling (self, event):
try:
self.Interval.Stop()
del self.Interval
event.Skip()
except:
return
The try statement is important, if the timer doesn't exist because
it hasn't been started you'll get an error. this way, it will try to do
the following, and if it can't Python just shrugs and carries on.
Now for the actual log processing:
def ProcessLog(self, event):
self.CurrentLineCount = len(open(self.LogPath, 'rb').readlines())
if self.CurrentLineCount == self.InitLineCount:
pass
elif self.CurrentLineCount > self.InitLineCount:
self.DoSomething()
self.InitLineCount = self.CurrentLineCount
event.Skip()
def DoSomething(self):
# Do whatever it is you want to do here.
EXPLAINED:
You set self.InitLineCount to zero in the beginning. And when you
created the wx.Timer with whatever interval you wanted (100 would be
10 times a second, 500 half a second etc.) the "ProcessLog" function
happens.
The variable self.CurrentLineCount will be quantity of lines in the log
file. So if the log is 10 lines long, self.CurrentLineCount will be 10.
So there we go. If Current is equal to Init line count then don't do anything OR
If Current is greater than Init Line count go to "DoSomething"
After "DoSomething" happens it goes back to "ProcessLog" and makes
self.InitLineCount = self.CurrentLinecount and repeats checking the length
over and over and over again until you stop it.
If you have specific questions ask away, that code should work as is if you create
the variables and do the imports. It's also as basic as I could make it, you may
want to save the self.CurrentLineCount so the next time you start the program you
don't get a false "TRUE" since the self.CurrentLineCount will always be greater on
the very first pass.
Another aside: wx.Timer doesn't "do something" then wait the amount of time
you set in the interval. It waits the amount of time you set in the interval then it
"does something" Ultimately it may not make any diference, but I thought you
may wnat to know.
Good luck, hope it helps.
Steve
···
----- Original Message ----- From: "Alex Garbino" <agarbino@gmail.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Sunday, 17 August, 2008 20:08
Subject: Re: [wxpython-users] Thank you wxPython mailing list!
Hello Steve,
I'm trying to parse a real time log file too (GPS data), do you mind
sharing how you did the following:
First off, TopiView is meant to parse a log file in real time.
As new lines are added to the log, those lines are read, and
depending on the parameters the user sets those lines are
sorted to various frames with a text control widget in them.
The user can elect to set an audio trigger to alert the user
that a line of text has been matched.
Thanks!
Alex
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users