Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Created August 19, 2019 05:13
Show Gist options
  • Save henriquegogo/f7e882842532473e42158bb3ee3165f8 to your computer and use it in GitHub Desktop.
Save henriquegogo/f7e882842532473e42158bb3ee3165f8 to your computer and use it in GitHub Desktop.
Mini python browser using Gnome Instrospection
#!/usr/bin/python
from gi import require_version
require_version('Gtk', '3.0')
require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2, Gdk
Gtk.init()
win = Gtk.Window()
win.set_default_size(800,600)
win.connect('destroy', Gtk.main_quit)
accel = Gtk.AccelGroup()
accel.connect(Gdk.keyval_from_name('l'), Gdk.ModifierType.CONTROL_MASK, 0, lambda a1,a2,a3,a4: entry.grab_focus())
win.add_accel_group(accel)
box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
win.add(box)
webview = WebKit2.WebView()
webview.connect('load-changed', lambda load_event, user_data:
entry.set_text(webview.get_uri()) if user_data == WebKit2.LoadEvent.FINISHED
else entry.set_text('Loading...'))
webview.load_uri('http://google.com')
box.pack_start(webview, True, True, 0)
entry = Gtk.Entry()
entry.connect('activate', lambda user_data: webview.load_uri(user_data.get_text()))
box.pack_start(entry, False, True, 0)
win.show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment