Created
October 21, 2011 08:55
-
-
Save 17twenty/1303387 to your computer and use it in GitHub Desktop.
Introspecction Issue
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 | |
import gi | |
from gi.repository import WebKit as webkit, Gtk as gtk, GLib, GObject | |
#dir(gtk) | |
#print dir(gtk.WindowType) | |
init_string=""" | |
<div id="testing">testing</div> | |
<div><button id="link">CLICK ME</button> | |
""" | |
class Browser: | |
def __init__(self): | |
self.mainloop = GLib.MainLoop() | |
self.window = gtk.Window(type=gtk.WindowType.TOPLEVEL) | |
self.window.set_position(gtk.WindowPosition.CENTER) | |
self.window.set_default_size(320, 240) | |
#self.window.fullscreen() | |
self.window.connect("destroy", self.on_quit) | |
vbox = gtk.VBox() | |
self.scroll_window = gtk.ScrolledWindow() | |
self.webview = webkit.WebView() | |
#print dir(self.webview) | |
#self.scroll_window.add(self.webview) | |
self.window.add(self.webview) | |
self.window.show_all() | |
self.webview.load_string(init_string, "text/html", "utf-8", '#') | |
doc = self.webview.get_dom_document() | |
self.webview.connect('document-load-finished', self.onLoad) | |
self.mainloop.run() | |
#print doc | |
#print dir(doc) | |
def onLoad(self, param1, param2): | |
print "STARTING" | |
doc = self.webview.get_dom_document() | |
div = doc.get_element_by_id('testing') | |
#print div | |
#print dir(div) | |
print div.get_inner_html() | |
div.set_inner_html('DYNAMIC TEXT') | |
link = doc.get_element_by_id('link') | |
print link | |
print dir(link) | |
link.set_inner_html('hello') | |
print GObject.signal_list_names(webkit.DOMHTMLButtonElement) | |
link.connect('clicked', self.onClick, link) | |
#div.connect_object('click-event', self.onClick, div) | |
def print_childs(self, elem): | |
childs = elem.get_child_nodes() | |
for c in range(childs.get_length()): | |
i=childs.item(c) | |
#print dir(i) | |
print "%s - %s\n" %(i.get_tag_name(), i.get_inner_html()) | |
self.print_childs(i) | |
def onClick(self, p1, p2, p3=None): | |
print "CLICKED - %s %s %s " % (str(p1), str(p2), str(p3)) | |
#return False | |
def on_quit(self, widget): | |
self.mainloop.quit() | |
if __name__ == "__main__": | |
browser = Browser() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment