#!python # # Intention of script: # Download a textfile from web # and present in a gtk window # # If the file is changed the # windows information shall # change and the window # reappear # import gtk import pycurl import StringIO import time from threading import Thread class Textwindow(gtk.Window): def __init__(self, parent=None): gtk.Window.__init__(self) try: self.set_screen(parent.get_screen()) except AttributeError: self.connect('destroy', lambda *w: gtk.main_quit()) self.set_default_size(200, 100) self.set_border_width(0) view = gtk.TextView() view.set_wrap_mode(gtk.WRAP_WORD) buffer = view.get_buffer() self.add(view) self.buffer = buffer def show_page(self, buffer, data): buffer.set_text("", 0) iter = buffer.get_iter_at_offset(0) buffer.insert(iter, data) def update(self, text): self.show_page(self.buffer, text) self.show_all() class checkforupdate(Thread): def __init__ (self,window): Thread.__init__(self) self.window = window def run(self): while 1: pyhandler = pycurl.Curl() string = StringIO.StringIO() getdata(string, pyhandler) if string.getvalue() != '': self.window.update(string.getvalue()) pyhandler.close() string.close() #Check for update from web every 2secs time.sleep(2) class guithread(Thread): def __init__(self): Thread.__init__(self) def run(self): gtk.main() def main(): window = Textwindow() current = checkforupdate(window) current.start() gui = guithread() gui.start() def getdata(string, pyhandler): pyhandler.setopt(pycurl.WRITEFUNCTION, string.write) pyhandler.setopt(pycurl.URL, "http://www.ehjelle.no/testdata.txt") pyhandler.perform() if __name__ == '__main__': main()