From: Alex T. <al...@tw...> - 2005-10-10 22:36:23
|
Cory Riddell wrote: >I used PythonCard to create a simple gui front end to a program that >dumps all of its output to a log file. What's the best way to show >that log file in a text control? I'd like it to be continuously >updated, just like the Unix tail command. > >Any advice? > > > There's probably a better way (or any number of better ways :-), but .... you can do it with a simple timer that reads from the file and appends to the text control will do it (That's assuming you don't mind the text control growing to keep all the content - if you don't want that you'll need to do a bit more to trim data off the front ....) I tried a very simple example, where there was just a TextArea, and the code just had > def on_initialize(self, event): > # if you have any initialization > # including sizer setup, do it here > self.f = open("log.txt") > self.tmr = timer.Timer(self.components.Log, -1) > self.tmr.start(1000) > pass > > def on_Log_timer(self, event): > t = self.f.read() > if t == "": return > self.components.Log.AppendText(t) > return this works for files being extended by saving from Emacs, and from "cat > log.txt" in Cygwin - but you should obviously check it with one of your log files while it is being extended. -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.11.14/127 - Release Date: 10/10/2005 |