shakaran

Webkit threads

Jun 17th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from gi.repository import Gtk
  2. from gi.repository import Gdk
  3. from gi.repository import GObject
  4. from gi.repository import GLib
  5. from gi.repository import WebKit
  6. import threading
  7. import time
  8.  
  9. # Use threads                                      
  10. Gdk.threads_init()
  11.  
  12. class App(object):
  13.     def __init__(self):
  14.         window = Gtk.Window()
  15.         webView = WebKit.WebView()
  16.         window.add(webView)
  17.         window.show_all()
  18.        
  19.         #webView.load_uri('http://www.google.com') # Here it works on main thread
  20.        
  21.         self.window = window
  22.         self.webView = webView
  23.  
  24.     def run(self):
  25.         Gtk.main()
  26.  
  27.     def show_html(self):
  28.         print 'show html'
  29.                    
  30.         time.sleep(1)
  31.         print 'after sleep'
  32.        
  33.         # Update widget in main thread            
  34.         GLib.idle_add(self.webView.load_uri, 'http://www.google.com') # Here it doesn't work
  35.  
  36. app = App()
  37.  
  38. thread = threading.Thread(target=app.show_html)
  39. thread.start()
  40.  
  41. app.run()
  42. Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment