Created
October 23, 2012 09:31
-
-
Save lewtds/3937877 to your computer and use it in GitHub Desktop.
HTML GUI demo
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
#/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