Skip to content

Instantly share code, notes, and snippets.

@lewtds
Created October 23, 2012 09:31
Show Gist options
  • Save lewtds/3937877 to your computer and use it in GitHub Desktop.
Save lewtds/3937877 to your computer and use it in GitHub Desktop.
HTML GUI demo
#/usr/bin/env python
from gi.repository import Gtk, WebKit
gui = """
<html>
<head>
<script>
function on_click() {
var title = prompt("WTF?");
window.document.title = title;
}
function foo(bar) {
document.write(bar)
}
</script>
</head>
<h1 id="hello">Hello World</h1>
<button onclick="on_click();">Click me!</button>
</html>
"""
def on_title_changed(view, frame, title):
print(title)
view.execute_script("foo('%s');" % title)
def main():
window = Gtk.Window()
window.connect("destroy", Gtk.main_quit)
view = WebKit.WebView()
view.load_html_string(gui, "#")
view.connect("title-changed", on_title_changed)
window.add(view)
window.show_all()
Gtk.main()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment