Removed GUI object.
[zeroinstall.git] / zeroinstall / 0launch-gui / gui.py
blob6fbb245da4c224c5cd3ea6e2be33180b794e51f0
1 import gtk, os, gobject, sys
3 from zeroinstall.injector.iface_cache import iface_cache
4 from zeroinstall.injector.policy import Policy
5 from zeroinstall.injector import download, handler
6 from zeroinstall.injector.model import SafeException
7 from zeroinstall.injector.reader import InvalidInterface
8 from zeroinstall.support import tasks, pretty_size
9 import dialog
11 version = '0.31'
13 class GUIHandler(handler.Handler):
14 dl_callbacks = None # Download -> [ callback ]
15 pulse = None
16 mainwindow = None
18 def downloads_changed(self):
19 if self.monitored_downloads and self.pulse is None:
20 def pulse():
21 progress = self.mainwindow.progress
23 any_known = False
24 done = total = self.total_bytes_downloaded # Completed downloads
25 n_downloads = self.n_completed_downloads
26 # Now add downloads in progress...
27 for x in self.monitored_downloads.values():
28 if x.status != download.download_fetching: continue
29 n_downloads += 1
30 if x.expected_size:
31 any_known = True
32 so_far = x.get_bytes_downloaded_so_far()
33 total += x.expected_size or max(4096, so_far) # Guess about 4K for feeds/icons
34 done += so_far
36 progress_text = '%s / %s' % (pretty_size(done), pretty_size(total))
37 if n_downloads == 1:
38 progress.set_text('Downloading one file (%s)' % progress_text)
39 else:
40 progress.set_text('Downloading %d files (%s)' % (n_downloads, progress_text))
42 if total == 0 or (n_downloads < 2 and not any_known):
43 progress.pulse()
44 else:
45 progress.set_fraction(float(done) / total)
47 return True
48 pulse()
49 self.pulse = gobject.timeout_add(50, pulse)
50 self.mainwindow.progress.show()
51 elif len(self.monitored_downloads) == 0:
52 # Reset counters
53 self.n_completed_downloads = 0
54 self.total_bytes_downloaded = 0
56 # Stop animation
57 if self.pulse:
58 gobject.source_remove(self.pulse)
59 self.mainwindow.progress.hide()
60 self.pulse = None
62 def confirm_trust_keys(self, interface, sigs, iface_xml):
63 import trust_box
64 return trust_box.confirm_trust(interface, sigs, iface_xml, parent = self.mainwindow.window)
66 def report_error(self, ex):
67 dialog.alert(None, str(ex))