I think you want to wait for the 'document-load-finished' signal. But to have your signal handler run, the Gtk main loop needs to be running. (The webview is probably also doing its loading in the main loop; note that a dialog runs its own loop, which would explain why that worked but the sleep didn't.) So you can start the main loop after loading the URL, and then stop it after you do the printing.

Robert


from gi.repository import Gtk, WebKit

def do_print(view, frame):
   operation = Gtk.PrintOperation()
   operation.set_export_filename('webkit-print.pdf')
   frame.print_full(operation, Gtk.PrintOperationAction.EXPORT)
   Gtk.main_quit()

if __name__ == "__main__":
   view = WebKit.WebView()
   view.connect('document-load-finished', do_print)
view.load_uri('http://en.wikipedia.org/wiki/Portable_Document_Format')
   Gtk.main()


On Sat, Aug 2, 2014 at 5:10 PM, Henning Sprang <[email protected]> wrote:
Hi,

I'm totally new to Webkit and GTK programming, anf playing around with
a PDF writing functionality,
and I'm mostly there.

The code below actually does it - the problem being that the call to
frame.print_()
is opening an actual print dialog window, which I don't need.

But without, the PDF is only 1k because the the URI isn't actually
loaded - the status is
<enum WEBKIT_LOAD_PROVISIONAL of type WebKitLoadStatus>
while, when calling the print_() method, afterwards the status is
WEBKIT_LOAD_FINISHED

I guess there's some signal to make the engine actually load the url
as it's not loaded until it's actually needed somewhere, which happens
automatically in the interactive print functionality, but not in
print_full() for some reason.
But I don't really find out what I can do to trigger that. I tried to
call a view.show(), view.show_all() - but no result. Ah, I also tried
to sleep a while in between to wait for the load, but also no effect.
I also tried to create and load a request explicitly, but same effect,
it's only loaded provisionally.


Thanks for any pointers

Henning


here the code:


from gi.repository import Gtk, Gdk, WebKit
from time import sleep

view = WebKit.WebView()

request = Webkit.

view.load_uri('http://en.wikipedia.org/wiki/Portable_Document_Format')

frame = view.get_main_frame()

print frame.get_load_status()

frame.print_()

print frame.get_load_status()

operation = Gtk.PrintOperation()
operation.set_export_filename('PDF.pdf')
frame.print_full(operation, Gtk.PrintOperationAction.EXPORT)




--
Henning Sprang
http://www.sprang.de
_______________________________________________
webkit-gtk mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-gtk

_______________________________________________
webkit-gtk mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-gtk

Reply via email to