With --systray, just blink the icon if key confirmation is needed
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / 0launch-gui / gui.py
blob09889fa7a7b6b01397dfc7bba68105117c3279b7
1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
4 import gobject, sys
6 from zeroinstall.support import tasks
7 from zeroinstall.injector import handler, download
8 import dialog
10 version = '0.38'
12 class GUIHandler(handler.Handler):
13 dl_callbacks = None # Download -> [ callback ]
14 pulse = None
15 mainwindow = None
17 def _reset_counters(self):
18 if not self.monitored_downloads:
19 self.n_completed_downloads = 0
20 self.total_bytes_downloaded = 0
21 return False
23 def abort_all_downloads(self):
24 for dl in self.monitored_downloads.values():
25 dl.abort()
27 def downloads_changed(self):
28 if self.monitored_downloads and self.pulse is None:
29 def pulse():
30 self.mainwindow.update_download_status()
31 return True
32 pulse()
33 self.pulse = gobject.timeout_add(200, pulse)
34 elif len(self.monitored_downloads) == 0:
35 # Delay before resetting, in case we start a new download quickly
36 gobject.timeout_add(500, self._reset_counters)
38 # Stop animation
39 if self.pulse:
40 gobject.source_remove(self.pulse)
41 self.pulse = None
42 self.mainwindow.update_download_status()
44 def impl_added_to_store(self, impl):
45 self.mainwindow.update_download_status()
47 def confirm_trust_keys(self, interface, sigs, iface_xml):
48 def do_confirm():
49 import trust_box
50 return trust_box.confirm_trust(interface, sigs, iface_xml, parent = self.mainwindow.window)
51 if self.mainwindow.systray_icon:
52 self.mainwindow.systray_icon.set_tooltip('Need to confirm a new GPG key')
53 self.mainwindow.systray_icon.set_blinking(True)
54 @tasks.async
55 def wait_and_confirm():
56 # Wait for the user to click the icon, then continue
57 yield self.mainwindow.systray_icon_blocker
58 yield tasks.TimeoutBlocker(0.5, 'Delay')
59 conf = do_confirm()
60 if conf:
61 yield conf
62 return wait_and_confirm()
63 else:
64 return do_confirm()
66 def report_error(self, ex, tb = None):
67 if isinstance(ex, download.DownloadAborted):
68 return # No need to tell the user about this, since they caused it
69 self.mainwindow.report_exception(ex)