Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time
- import cairo
- from gi.repository import Gtk, Gdk, WebKit
- if len(sys.argv) != 3:
- print 'usage: %s url filename'%sys.argv[0]
- sys.exit(-1)
- uri, filename = sys.argv[1:]
- for scheme in ('http://', 'https://', 'ftp://', 'file://'):
- if uri.startswith(scheme):
- break
- else:
- uri = 'http://' + uri
- #w = Gtk.OffscreenWindow()
- w = Gtk.Window()
- #w.set_default_size(800, 640)
- v = WebKit.WebView()
- w.add(v)
- def capture_window(window):
- w, h = window.get_size()
- dst = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
- ctx = cairo.Context(dst)
- surface = Gdk.cairo_create(window.get_window()).get_target()
- ctx.set_source_surface(surface)
- ctx.paint()
- dst.write_to_png(filename)
- Gtk.main_quit()
- def progress_cb(webview, progress, window):
- if webview.get_progress() == 1.0:
- capture_window(window)
- v.connect('notify::progress', progress_cb, w)
- v.load_uri(uri)
- w.show_all()
- Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment