Created
August 12, 2016 13:36
-
-
Save alex-eri/53518825b2a8a50dd1695c69ee5058cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from gi.repository import Gtk, Gdk, WebKit | |
class Browser(Gtk.Window): | |
def __init__(self, *args, **kwargs): | |
super(Browser, self).__init__(*args, **kwargs) | |
self.connect("destroy", Gtk.main_quit) | |
self.set_size_request(1200,700) | |
self.webview = WebKit.WebView() | |
self.webview.load_uri("file:///{}/index.html".format(os.path.dirname(os.path.realpath(__file__)))) | |
scrolled_window = Gtk.ScrolledWindow() | |
scrolled_window.add(self.webview) | |
self.add(scrolled_window) | |
scrolled_window.show_all() | |
self.show() | |
class Inspector(Gtk.Window): | |
def __init__(self, view, *args, **kwargs): | |
super(Inspector, self).__init__(*args, **kwargs) | |
self.set_size_request(1200,700) | |
self.webview = view | |
settings = WebKit.WebSettings() | |
settings.set_property('enable-developer-extras', True) | |
view.set_settings(settings) | |
self.webview = WebKit.WebView() | |
self.inspector = view.get_inspector() | |
self.inspector.connect("inspect-web-view", self.inspect) | |
self.scrolled_window = Gtk.ScrolledWindow() | |
self.add(self.scrolled_window) | |
self.scrolled_window.show() | |
self.webview = WebKit.WebView() | |
self.scrolled_window.add(self.webview) | |
def inspect(self,inspector,view,*a,**kw): | |
self.scrolled_window.show_all() | |
self.show() | |
return self.webview | |
if __name__ == "__main__": | |
Gtk.init(sys.argv) | |
browser = Browser() | |
inspector = Inspector(browser.webview) | |
Gtk.main() |
@programmin1, I'm also wondering how to do this with WebKit2
. The docs don't show similar inspector-related signals.
@dlenski I got the inspector to show in Tunesviewer, you can see the code here: https://github.com/programmin1/tunesviewer/tree/master/src - look in webkitview and inspector Python files.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was very helpful, but unfortunately it does not work anymore with Ubuntu 17.10 and the new WebKit2 module.
'gi.repoisitory.WebKit2' object has no attribute 'WebSettings', and there are other differences...
You would think
from gi.repository import Gtk, Gdk, WebKit2 as WebKit
would do it but many of the attributes aren't there... do you know of an example using the WebKit2 bindings?