Skip to content

Instantly share code, notes, and snippets.

@geekgonecrazy
Created August 26, 2011 20:58
Show Gist options
  • Save geekgonecrazy/1174429 to your computer and use it in GitHub Desktop.
Save geekgonecrazy/1174429 to your computer and use it in GitHub Desktop.
webkit based browser
#!/bin/python
import gtk
import webkit
import urllib
def homeclicked(btn):
view.open("https://10.10.10.48")
def title_changed(webview, frame, title):
window.set_title(title)
def load_progress_changed(webview, amount):
progress.set_fraction(amount / 100.0)
def load_started(webview, frame):
progress.show()
def load_finished(webview, frame):
progress.hide()
def refresh_clicked(btn):
view.reload()
def back_clicked(btn):
view.go_back()
def _nav_request_cb(view,frame,net_req):
uri=net_req.get_uri()
if uri=="http://cartoonnetwork.com":
uri="http://google.com"
page=urllib.urlopen(uri)
frame.load_string(page.read(), "text/html","iso-8859-15",page.geturl())
return 1
view = webkit.WebView()
Scrolledwindow = gtk.ScrolledWindow()
Scrolledwindow.add(view)
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.fullscreen()
home_image = gtk.Image()
home_image.set_from_file("Home.png")
reload_image = gtk.Image()
reload_image.set_from_file("Reload.png")
back_image = gtk.Image()
back_image.set_from_file("Back.png")
home = gtk.Button()
home.add(home_image)
refresh = gtk.Button()
refresh.add(reload_image)
#back = gtk.Button(stock = gtk.STOCK_GO_BACK)
back = gtk.Button()
back.add(back_image)
progress = gtk.ProgressBar()
nav = gtk.HBox()
nav.pack_start(home, False)
nav.pack_start(refresh, False)
nav.pack_start(back, False)
vbox = gtk.VBox()
vbox.pack_start(nav, False)
vbox.pack_start(Scrolledwindow)
status = gtk.HBox()
status.pack_start(progress)
vbox.pack_start(status, False)
window.add(vbox)
window.show_all()
home.connect("clicked", homeclicked)
view.connect("title-changed", title_changed)
view.connect("load-progress-changed", load_progress_changed)
view.connect("load-started", load_started)
view.connect("load-finished", load_finished)
refresh.connect("clicked", refresh_clicked)
back.connect("clicked", back_clicked)
view.connect("navigation-requested", _nav_request_cb)
view.open("https://10.10.10.48")
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment