On Dec 3, 2007, at 9:18 AM, Mark Stahler wrote:
John Finlay wrote:
Nathaniel Smith wrote:
On Sun, Dec 02, 2007 at 09:34:40PM -0800, Aravind Vijayakumar wrote:
Since you are opening the file afresh each time in refreshLog,
won't
you be reading the first line each time?
The .read() method in Python reads the whole file, not just the
first
line.
read() will also read from the current position so you can keep
reading as new data is added. An alternative is to not open the
file in refreshLog but when initializing and then read it in
refreshLog which is called by timeout_add - something like:
Code:
textview = self.gui.get_widget("bottom_textview")
# Methods that need to be run on start
file = open('log.txt')
self.refreshLog()
# Timer to autorefresh log
timer = gobject.timeout_add(500, self.refreshLog)
timer.start()
def refreshLog(self):
string = file.read()
if string:
buffer = textview.get_buffer()
mark = buffer.create_mark("end", buffer.get_end_iter())
textview.scroll_to_mark(mark, 0)
buffer.insert_at_cursor(string)
buffer.delete_mark_by_name("end")
return True
John
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Thank you all for the replies. I was not aware of the problems with
the threading in GTK+.
I got it working perfectly using the gobject timeout with Johns
modified routine. I now only have to insert new text from the log
and dont have to reread the whole thing.
You have it working now so this isn't really relevant. However, I had
success using gnome.vfs.monitor_add. It can call your event handler
in several situations, I used MONITOR_EVENT_CHANGED to find out when
my log files changed. I keep track of the current file position each
time so I open, seek to that position, read, close, record the new
position and add the data to the text buffer. No polling necessary.
And I assume that the gnome.vfs call is doing a select so it should
be much more efficient.
Thanks!
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/