[webkit-gtk] Bug#749251: cyclograph-gtk2: depends on python-webkit which is deprecated

Carlos Garcia Campos cgarcia at igalia.com
Thu Jun 26 23:34:55 PDT 2014


El jue, 26-06-2014 a las 21:16 +0200, Emilio Pozuelo Monfort escribió:
> Hi,
> 
> Sorry for the late reply.
> 
> On 17/06/14 21:35, Federico Brega wrote:
> > 2014-06-09 20:40 GMT+02:00 Emilio Pozuelo Monfort <pochu at debian.org>:
> >>> >> For the second issue there is no documentation for python which makes
> >>> >> the transition to webkit2 a little slow.
> >>> >> Do you have any example about how to execute javascript and get
> >>> >> results back in python?
> >> >
> >> > There is webkit_web_view_run_javascript() and
> >> > webkit_web_view_run_javascript_finish(), see
> >> >
> >> > http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript
> >> >
> >> > Is that what you need?
> > Hello Emilio,
> > 
> > thank you for your help. I had already seen the page you linked, but
> > it is C code. It should be straightforward to translate int python but
> > it doesn't work, that's why I asked for a python example.
> > We tried to make it work with webkit2 but result_js.get_value() throws
> > a type error:
> > TypeError: Couldn't find conversion for foreign struct 'JavaScriptCore.Value'
> > I attached a minimal example to better explain how we're using the library.
> > Do you have any suggestion? Is it the case to report a bug of
> > gir1.2-webkit2-3.0?
> 
> I don't know about that. Perhaps somebody from the upstream ml can shed some
> light. Cc'ing it.
> 
> [ for webkit-gtk@: Federico is porting his app from python-webkit (the old
> static libwebkitgtk-1.0 python bindings) to gir1.2-webkit2-3.0, see the code
> below. ]

Yes, the problem is that webkit_javascript_result_get_value() returns a
JSValueRef, but there's no gobject-introspection for JavaScriptCore API.
I don't think it worked in WebKit1 either, but in WebKit1
webkit_web_view_run_script didn't return anything, so if you are porting
from WebKit1, maybe you can just ignore the return value for now. I have
some comments about the code, see below.

> Regards,
> Emilio
> 
> > Regards
> > 
> > --
> > Federico
> > 
> > 
> > example.py
> > 
> > 
> > from gi.repository import Gtk, WebKit2
> > 
> > def get_res(view, result):
> >     result_js = view.run_javascript_finish(result)
> >     if result_js is None:
> >         return
> >     v = result_js.get_value()
> >     print(v)
> > 
> > view = WebKit2.WebView()
> > 
> > sw = Gtk.ScrolledWindow() 
> > sw.add(view) 

In WebKit2 you shouldn't use a GtkScrolledWindow, the web view is
scrollable by itself.

> > win = Gtk.Window()
> > win.connect("delete-event", Gtk.main_quit) 
> > win.add(sw)
> > win.set_default_size(400, 200)
> > win.show_all() 
> > 
> > view.load_uri("http://w3.org/")
> > 
> > view.run_javascript("document.URL", None, get_res)

Note that load_uri is asynchronous too, so it's not guaranteed that the
js will be executed when the page is loaded, you should probably connect
to load-changed signal and run the js when the load has finished.

> > Gtk.main()
> 
> _______________________________________________
> webkit-gtk mailing list
> webkit-gtk at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-gtk
> 

-- 
Carlos Garcia Campos
http://pgp.rediris.es:11371/pks/lookup?op=get&search=0xF3D322D0EC4582C3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <https://lists.webkit.org/pipermail/webkit-gtk/attachments/20140627/e6de0a65/attachment.sig>


More information about the webkit-gtk mailing list