Moved some useful GUI code into zeroinstall.gtkui.gtkutils.
[zeroinstall.git] / zeroinstall / 0launch-gui / gui.py
blob0c9b844f4731b6522e1ae2b1a244eee6f474ed44
1 # Copyright (C) 2008, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
4 import gobject
6 from zeroinstall.injector import handler, download
7 import dialog
9 version = '0.34'
11 class GUIHandler(handler.Handler):
12 dl_callbacks = None # Download -> [ callback ]
13 pulse = None
14 mainwindow = None
16 def _reset_counters(self):
17 if not self.monitored_downloads:
18 self.n_completed_downloads = 0
19 self.total_bytes_downloaded = 0
20 return False
22 def abort_all_downloads(self):
23 for dl in self.monitored_downloads.values():
24 dl.abort()
26 def downloads_changed(self):
27 if self.monitored_downloads and self.pulse is None:
28 def pulse():
29 self.mainwindow.update_download_status()
30 return True
31 pulse()
32 self.pulse = gobject.timeout_add(50, pulse)
33 elif len(self.monitored_downloads) == 0:
34 # Delay before resetting, in case we start a new download quickly
35 gobject.timeout_add(500, self._reset_counters)
37 # Stop animation
38 if self.pulse:
39 gobject.source_remove(self.pulse)
40 self.pulse = None
41 self.mainwindow.update_download_status()
43 def impl_added_to_store(self, impl):
44 self.mainwindow.update_download_status()
46 def confirm_trust_keys(self, interface, sigs, iface_xml):
47 import trust_box
48 return trust_box.confirm_trust(interface, sigs, iface_xml, parent = self.mainwindow.window)
50 def report_error(self, ex, tb = None):
51 if isinstance(ex, download.DownloadAborted):
52 return # No need to tell the user about this, since they caused it
53 dialog.alert(self.mainwindow.window, str(ex))