[pygtk] Re: A Timer and refreshing TextView
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 pygtk@daa.com.au 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. Thanks! ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] A Timer and refreshing TextView
Hello, I am attempting to have a textview tail the end of a log file. So far I can load the log and scroll to the end however I am running into a problem have the log file refresh. Code: textview = self.gui.get_widget("bottom_textview") # Methods that need to be run on start self.refreshLog() # Timer to autorefresh log timer = threading.Timer(10, self.refreshLog) timer.start() def refreshLog(self): file = open('log.txt') string = file.read() buffer = textview.get_buffer() buffer.set_text(string) mark = buffer.create_mark("end", buffer.get_end_iter()) textview.scroll_to_mark(mark, 0) buffer.delete_mark_by_name("end") The code seems to run ok but the text in the TextView does not update. I loaded the log into vi and appended some text and saved it but the program would not reload it. Am I overlooking something simple? Is there another way to do the timer? Thanks for the help! Mark ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Textview to Tail a log file
Hi, I am new to GTK+ so please go easy on me. I am puzzled as to why my simple function is not working: def refreshLog(self): file = open('log.txt') string = file.read() textview = self.gui.get_widget("bottom_textview") textbuffer = textview.get_buffer() textbuffer.set_text(string) iter = textbuffer.get_end_iter() iter.forward_to_end() print iter.is_end() print textview.scroll_to_iter(iter, 0, True) is_end returns true so I know my iterator is at the end of the text file yep scroll_to_iter returns false and does not scroll at all. What is wrong? Could it be something in my glade file? The rest of the gui works. Thanks Mark ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/