Updated GUI to handle background downloads.
[zeroinstall.git] / gui.py
blob8e8e5dd9f55724807c10e629d2d5b501b06725dc
1 from gpg import BadSignature
2 from policy import Policy
3 import download
4 import gtk, os
5 import sys
7 # Singleton Policy
8 policy = None
10 class GUIPolicy(Policy):
11 window = None
12 n_downloads = 0
13 pulse = None
15 def __init__(self, interface, prog, prog_args):
16 Policy.__init__(self, interface)
17 global policy
18 assert policy is None
19 policy = self
21 import mainwindow
22 self.window = mainwindow.MainWindow(prog, prog_args)
23 self.window.browser.set_root(policy.get_interface(policy.root))
25 def monitor_download(self, dl):
26 error_stream = dl.start()
27 def error_ready(src, cond):
28 print src, "ready"
29 got = os.read(src.fileno(), 100)
30 if not got:
31 error_stream.close()
32 self.n_downloads -= 1
33 if self.n_downloads == 0:
34 self.window.progress.hide()
35 gtk.timeout_remove(self.pulse)
36 self.pulse = None
37 data = dl.error_stream_closed()
38 try:
39 self.check_signed_data(dl, data)
40 except BadSignature, ex:
41 print >>sys.stderr, ex
42 return False
43 print "Errors: '%s'" % got
44 print "(from %s)" % dl.url
45 return True
47 gtk.input_add(error_stream, gtk.gdk.INPUT_READ, error_ready)
49 self.n_downloads += 1
50 if self.pulse is None:
51 progress = self.window.progress
52 self.pulse = gtk.timeout_add(50, lambda: progress.pulse() or True)
53 progress.show()
55 def main(self):
56 self.window.show()
57 gtk.main()