Added a delay before resetting the download counters in the GUI.
[zeroinstall.git] / zeroinstall / 0launch-gui / gui.py
blob6d3c3d5048ae92f43baee2baf64d0783a3527c32
1 import gobject
3 from zeroinstall.injector import handler
4 import dialog
6 version = '0.31'
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 confirm_trust_keys(self, interface, sigs, iface_xml):
41 import trust_box
42 return trust_box.confirm_trust(interface, sigs, iface_xml, parent = self.mainwindow.window)
44 def report_error(self, ex):
45 dialog.alert(None, str(ex))