Hi!

I use this code to try to log  the contents of a file at a scrolled
window. It read all the file and include the contents in the window,
and later program a callback with the timeout_add function.
When the callback is called, it read the file (because it could grow
up) and add the new readed text to the window and to a list.

The problem is that when i add some text to the open file, when the
callback read the contents it dont`read the first one or two
characters added... and it add a newline character to the string
readed (i supose that it is the normal behaviour but i need to add
only the real contents)

Any suggestions would be apreciated
Thanks in adavance



class LogWindow:
        '''Clase para mostrar a modo de log lo leido de un fichero de texto'''

        def __init__(self,gtkContainer,fich,maxLineas):
                self.maxLineas = maxLineas
                self.numLineas = 0
                self.intervalo = 1000
                self.fich = fich
                self.gtkScrolledWindow = GtkScrolledWindow()
                gtkContainer.add(self.gtkScrolledWindow)
                self.gtkText = GtkText()
                self.gtkScrolledWindow.add_with_viewport(self.gtkText)
                self.gtkScrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
                
                self.gtkScrolledWindow.show_all()
                self.lstLineas = []
                self.timer = timeout_add(self.intervalo,self.checkFichero)

        def checkFichero(self):
                self.gtkText.freeze()
                linea = self.fich.read()
                while linea != '':
                        print '"%s"', % linea
                        self.lstLineas.append(linea)
                        self.gtkText.insert_defaults(linea)
                        linea = self.fich.read()

                self.gtkText.thaw()
                print 'checkFichero'
                return 'true'
                

#--------------------------------------------------------------------------------------------------
def main():
        gtkWindowMain = GtkWindow(type='toplevel')
        gtkWindowMain.connect('destroy',mainquit)
        fich = open('menu.txt','r')
        logWin = LogWindow(gtkWindowMain,fich,50)
        gtkWindowMain.show_all()
        mainloop()
#--------------------------------------------------------------------------------------------------
        

if __name__ == '__main__':
        main()



-- 
Hasta otra!

        Eduardo Ferro Aldama     [EMAIL PROTECTED] 
        (Linux User 44335)

La web del GLUB http://glub.ehu.es/
Grupo Linux Usuarios de Bizkaia

windows2000 "El insulto final"

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to