[webkit-gtk] GObject bindings ... how to add/remove DOM event listeners?

C Anthony Risinger anthony at xtfx.me
Sun Feb 5 01:43:42 PST 2012

On Sun, Feb 5, 2012 at 2:38 AM, C Anthony Risinger <anthony at xtfx.me> wrote:
> ****is it currently possible to use
> add_event_handler/remove_event_handler from Python?****
> the add/remove handlers are missing from all the EventTargets, but
> available on EventTargetIface, and everything i read suggests i'm
> simply using it incorrectly, esp. considering the change from signals
> was almost 1yr ago:
> https://lists.webkit.org/pipermail/webkit-gtk/2011-March/000450.html

per suggestion in IRC, here is the actual code in use:


import gi
gi.require_version('WebKit', '3.0')
from gi.repository import WebKit, Gtk, GObject

init_string = r'''
<div id="testing">testing</div>
<div><button id="link">CLICK ME</button>
<a href="http://www.google.com">hooray!</a>

class WK(object):
    def __init__(self):
        print '__init__'

        self.window = Gtk.Window()
        self.webview = WebKit.WebView()

        self.window.set_default_size(800, 600)
        self.window.connect('destroy', self.on_quit)


        self.webview.load_string(init_string, 'text/html', 'utf-8', '#')
        self.webview.connect('document-load-finished', self.on_load)

    def on_load(self, *args, **kwds):
        print 'on_load'

        doc = self.webview.get_dom_document()
        link = doc.get_element_by_id('link')

        # old way ...
        #link.connect('click-event', ll, 'testtest')

        # DOESN'T WORK (non-existent) ... how to achieve?
        link.add_event_listener('click', self.on_click, True, self)

    def on_click(self, *args, **kwds):
        print 'on_click', args, kwds

    def on_quit(self, widget):

if __name__ == '__main__':
    testevents = WK()

thanks much for your time,


C Anthony

More information about the webkit-gtk mailing list