Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-11-06 11:29:41 (GMT)
committer Manuel Kaufmann <humitos@gmail.com>2012-11-06 11:29:41 (GMT)
commit9cf83eb95943bcf49e6a3dd467e8e856d45dcbe2 (patch)
treefdf4f343c735f7a08f44410e85618386a26fefe2
parent8914be5dda2a6111ad12c77b4a913d8602d17be5 (diff)
Download a file with WebKit leaves .goutputstream- files
-rw-r--r--tests/download_file_with_webkit.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/download_file_with_webkit.py b/tests/download_file_with_webkit.py
new file mode 100644
index 0000000..499d201
--- /dev/null
+++ b/tests/download_file_with_webkit.py
@@ -0,0 +1,62 @@
+from gi.repository import Gtk
+from gi.repository import WebKit
+
+
+def __destroy_cb(widget, data=None):
+ global download
+ download.cancel()
+ Gtk.main_quit()
+
+
+def __progress_change_cb(download, something):
+ progress = download.get_progress()
+ print progress
+
+
+def __state_change_cb(download, gparamspec):
+ state = download.get_status()
+ if state == WebKit.DownloadStatus.STARTED:
+ print 'STARTED'
+ elif state == WebKit.DownloadStatus.FINISHED:
+ print 'FINISHED'
+ elif state == WebKit.DownloadStatus.CANCELLED:
+ print 'CANCELLED'
+ else:
+ print 'Other state: %s' % state
+
+
+def __error_cb(download, err_code, err_detail, reason):
+ print 'Error downloading URI code %s, detail %s: %s' % (err_code, err_detail, reason)
+
+
+# We need to keep the download in memory
+download = None
+def __clicked_button(widget):
+ print 'Button clicked'
+
+ url = 'http://download.laptop.org/xo-1.5/os/candidate/12.1.0-21/21021o1.zd'
+ nr = WebKit.NetworkRequest()
+ nr.set_uri(url)
+ global download
+ download = WebKit.Download(network_request=nr)
+
+ download.connect('notify::progress', __progress_change_cb)
+ download.connect('notify::status', __state_change_cb)
+ download.connect('error', __error_cb)
+
+ print download.get_uri()
+ download.set_destination_uri('file:///tmp/21021o1.zd')
+ download.start()
+
+
+window = Gtk.Window()
+window.set_title('Download a file with WebKit example')
+window.set_default_size(300, 180)
+window.connect('destroy', __destroy_cb)
+
+button = Gtk.Button('Download file!')
+button.connect('clicked', __clicked_button)
+
+window.add(button)
+window.show_all()
+Gtk.main()