Finito.

Leonardo Robol [2010-01-14 14:02]
Finito.
Filename
Pala.py
diff --git a/Pala.py b/Pala.py
index 5852426..08c49cc 100755
--- a/Pala.py
+++ b/Pala.py
@@ -1,12 +1,39 @@
 #!/usr/bin/env python

-import gtk, gtkmozembed
+import gtk, gtkmozembed, gobject, threading, time, sys
+
+class PalaUpdater(gobject.GObject, threading.Thread):
+
+    def __init__(self):
+        threading.Thread.__init__(self)
+        gobject.GObject.__init__(self)
+        self.timeout = 3
+
+        gobject.signal_new("reload-page",
+                           PalaUpdater,
+                           gobject.SIGNAL_ACTION,
+                           None,
+                           ())
+
+    def Stop(self):
+        self.running = False
+
+    def run(self):
+        self.running = True
+        to_wait = self.timeout
+        print "ohi"
+        while(self.running):
+            time.sleep(self.timeout)
+            self.emit('reload-page')
+            print "Emitting reload-page"
+            sys.stdout.flush()

 class PalaApp():

     def __init__(self):

         self.default_padding = 5
+        self.timeout = 15000

         # Creo Finestra e WebView
         self.Window = gtk.Window(gtk.WINDOW_TOPLEVEL)
@@ -19,6 +46,8 @@ class PalaApp():

         label = gtk.Label("Pagina")
         self.UrlField = gtk.Entry()
+        self.UrlField.connect('activate',
+                              lambda w: self.LoadPage(self.UrlField.get_text()))
         self.CheckPageButton = gtk.Button("Controlla pagina")

         Toolbar = gtk.HBox()
@@ -32,14 +61,51 @@ class PalaApp():
         self.Window.resize(740,680)
         self.Window.show_all()

+        # Tengo traccia dell'url
+        self.WebView.connect('open-uri',
+                             lambda w, url: self.UrlField.set_text(url))
+
+        self.Window.connect('destroy', self.Quit)
+
+        # Mi segno l'id della connect del PalaUpdater
+        self.updating = False
+
+        self.CheckPageButton.connect('clicked', self.CheckPageButton_cb)
+
+    def GetUrl(self):
+        return self.WebView.get_location()
+
+    def Quit(self, w):
+        gtk.main_quit()
+
     def LoadPage(self, url):
         """Carica la pagina data nella webView"""
         self.UrlField.set_text(url)
         self.WebView.load_url(url)

+    def Reload(self):
+        # print "eheh %s" % self.updating
+        # self.LoadPage(self.GetUrl())
+        print "Faccio il reload"
+        self.WebView.reload(gtkmozembed.FLAG_RELOADBYPASSCACHE)
+        if self.updating:
+            gobject.timeout_add(self.timeout,
+                                self.Reload)
+
+
+    def CheckPageButton_cb(self, w):
+        if not self.updating:
+            self.updating = True
+            gobject.timeout_add(self.timeout,
+                                self.Reload)
+            self.CheckPageButton.set_label("Smetti di controllare la pagina")
+        else:
+            self.CheckPageButton.set_label("Controlla Pagina")
+            self.updating = False

 if __name__ == "__main__":

     pala = PalaApp()
     pala.LoadPage("http://www.dm.unipi.it")
+
     gtk.main()
ViewGit