Release 0.33
[zeroinstall.git] / zeroinstall / 0launch-gui / gui.py
blob5c789b45df793c7abd431c7d568c85534a69de78
1 import gobject
3 from zeroinstall.injector import handler, download
4 import dialog
6 version = '0.33'
8 class GUIHandler(handler.Handler):
9 dl_callbacks = None # Download -> [ callback ]
10 pulse = None
11 mainwindow = None
13 def _reset_counters(self):
14 if not self.monitored_downloads:
15 self.n_completed_downloads = 0
16 self.total_bytes_downloaded = 0
17 return False
19 def abort_all_downloads(self):
20 for dl in self.monitored_downloads.values():
21 dl.abort()
23 def downloads_changed(self):
24 if self.monitored_downloads and self.pulse is None:
25 def pulse():
26 self.mainwindow.update_download_status()
27 return True
28 pulse()
29 self.pulse = gobject.timeout_add(50, pulse)
30 elif len(self.monitored_downloads) == 0:
31 # Delay before resetting, in case we start a new download quickly
32 gobject.timeout_add(500, self._reset_counters)
34 # Stop animation
35 if self.pulse:
36 gobject.source_remove(self.pulse)
37 self.pulse = None
38 self.mainwindow.update_download_status()
40 def impl_added_to_store(self, impl):
41 self.mainwindow.update_download_status()
43 def confirm_trust_keys(self, interface, sigs, iface_xml):
44 import trust_box
45 return trust_box.confirm_trust(interface, sigs, iface_xml, parent = self.mainwindow.window)
47 def report_error(self, ex, tb = None):
48 if isinstance(ex, download.DownloadAborted):
49 return # No need to tell the user about this, since they caused it
50 dialog.alert(self.mainwindow.window, str(ex))