I lost characters at read
Eduardo Ferro
eferro at inicia.es
Mon Mar 19 09:26:14 EST 2001
Hi!
I am trying to create a window to log the contents of a file, to do this
i first read all the file and later i periodically read the file if it
grow up
The problem is that when my periodic callback read from file i lost one
or two characters per line and I don`t understand why
Me code is (the problem is at the checkFichero fuction):
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()
More information about the Python-list
mailing list