Ticket #4385: download_twice_same_file_with_webkit.py

File download_twice_same_file_with_webkit.py, 2.0 KB (added by humitos, 11 years ago)

Test Case

Line 
1from gi.repository import Gtk
2from gi.repository import WebKit
3
4
5def __destroy_cb(widget, data=None):
6    global download
7    if download is not None:
8        download.cancel()
9    Gtk.main_quit()
10
11
12def __progress_change_cb(download, something):
13    progress = download.get_progress()
14    print progress
15
16
17def __state_change_cb(download, gparamspec):
18    state = download.get_status()
19    if state == WebKit.DownloadStatus.STARTED:
20        print 'STARTED'
21    elif state == WebKit.DownloadStatus.FINISHED:
22        print 'FINISHED'
23    elif state == WebKit.DownloadStatus.CANCELLED:
24        print 'CANCELLED'
25    else:
26        print 'Other state: %s' % state
27
28
29def __error_cb(download, err_code, err_detail, reason):
30    print 'Error downloading URI code %s, detail %s: %s' % (err_code, err_detail, reason)
31
32
33# We need to keep the download in memory
34download = None
35def __clicked_start_button(widget):
36    print 'Button clicked'
37
38    url = 'http://download.laptop.org/xo-1.5/os/candidate/12.1.0-21/21021o1.zd'
39    nr = WebKit.NetworkRequest()
40    nr.set_uri(url)
41    global download
42    download = WebKit.Download(network_request=nr)
43
44    download.connect('notify::progress', __progress_change_cb)
45    download.connect('notify::status', __state_change_cb)
46    download.connect('error', __error_cb)
47
48    print download.get_uri()
49    download.set_destination_uri('file:///tmp/21021o1.zd')
50    download.start()
51
52
53def __clicked_cancel_button(widget):
54    global download
55    if download is not None:
56        download.cancel()
57        print 'Download CANCELLED!'
58
59window = Gtk.Window()
60window.set_title('Download a file with WebKit example')
61window.set_default_size(300, 60)
62window.connect('destroy', __destroy_cb)
63
64start_button = Gtk.Button('Download file!')
65start_button.connect('clicked', __clicked_start_button)
66
67cancel_button = Gtk.Button('Cancel download!')
68cancel_button.connect('clicked', __clicked_cancel_button)
69
70vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
71vbox.add(start_button)
72vbox.add(cancel_button)
73
74window.add(vbox)
75window.show_all()
76Gtk.main()