SHARE
TWEET

Browser

a guest May 27th, 2010 422 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import sys
  3. import gtk
  4. import webkit
  5. DEFAULT_URL = 'http://www.google.com' # Change this as you Wish
  6. class SimpleBrowser: # needs GTK, Python, Webkit-GTK
  7.     def __init__(self):
  8.         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  9.         self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
  10.         self.window.connect('delete_event', self.close_application)
  11.         self.window.set_default_size(800, 600)
  12.         vbox = gtk.VBox(spacing=5)
  13.         vbox.set_border_width(5)
  14.         self.txt_url = gtk.Entry()
  15.         self.txt_url.connect('activate', self._txt_url_activate)
  16.         self.scrolled_window = gtk.ScrolledWindow()
  17.         self.webview = webkit.WebView()
  18.         self.scrolled_window.add(self.webview)
  19.         vbox.pack_start(self.scrolled_window, fill=True, expand=True)
  20.         self.window.add(vbox)
  21.     def _txt_url_activate(self, entry):
  22.         self._load(entry.get_text())
  23.     def _load(self, url):
  24.         self.webview.open(url)
  25.     def open(self, url):
  26.         self.txt_url.set_text(url)
  27.         self.window.set_title('%s' % url)
  28.         self._load(url)
  29.     def show(self):
  30.         self.window.show_all()
  31.     def close_application(self, widget, event, data=None):
  32.         gtk.main_quit()
  33. if __name__ == '__main__':
  34.     if len(sys.argv) > 1:
  35.         url = sys.argv[1]
  36.     else:
  37.         url = DEFAULT_URL
  38.     gtk.gdk.threads_init()
  39.     browser = SimpleBrowser()
  40.     browser.open(url)
  41.     browser.show()
  42.     gtk.main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top