Search code examples
pythonwebkitpygobjectgobjectgobject-introspection

webkit (webkitgtk3) function prototype as seen in python from pywebkit


pywebkit makes calls from python into webkit by introspection. The prototype of called functions are bound at runtime. A little problem for developers is that you will not see the prototype in source code. How do you find the function prototype? Specifically "add_event_listener"?

This piece of python code is from pyjs.org pyjs/runners/giwebkit.py:

702     def addEventListener(self, element, event_name, cb):
703         listener = Callback(element, cb, False)
704         element.add_event_listener(event_name, listener, False)

When running on fedora 20 it gives this error:

File "/.../pyjs/runners/giwebkit.py", line 704, in addEventListener
    element.add_event_listener(event_name, listener, False)
TypeError: add_event_listener() takes exactly 5 arguments (4 given)

How to find out what are the arguments and their types passed to function "element.add_event_listener()"? Can I insert a piece of python code to print it out?

I searched to find the prototype to add_event_listener(), but could not find the answer easily. So I'm thinking whether from the calling code we can do something.

Thanks.

Edit: Change the original title "python print function prototype and/or arguments, specifically for add_event_listener from webkitgtk3" to better reflect the real question.


Solution

  • This is from what HMR suggested in the comment. It involves two steps: Step 1, go get the webkit api:

    http://webkitgtk.org/reference/webkitdomgtk/stable/WebKitDOMEventTarget.html#webkit-dom-event-target-add-event-listener

    Then manually map that interface to the python interface (I think by removing the *target from the beginning of arguments list).