0

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.

minghua
  • 5,981
  • 6
  • 45
  • 71
  • 1
    could be wrong here so just add it as a comment but I think add_event_listener expects 5 arguments, you provide 3 so one or more of those 3 have defaults but one doesn't: http://webkitgtk.org/reference/webkitdomgtk/stable/WebKitDOMEventTarget.html#webkit-dom-event-target-add-event-listener, can't find a python specific api documentation so you'll have to look into source code. Maybe control + click it in Eclipse or Netbeans to go to the definition of element.add_event_listener – HMR May 20 '14 at 01:41
  • great! exactly what I'm looking for. can you put it to an answer? thanks! – minghua May 21 '14 at 15:59

1 Answers1

0

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).

minghua
  • 5,981
  • 6
  • 45
  • 71