Release 1.10
[zeroinstall.git] / zeroinstall / 0launch-gui / gui.py
blob0cce3f938d1b5719da0e7714a3f780e0c473046f
1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
4 from zeroinstall import _, gobject
5 from zeroinstall.support import tasks
6 from zeroinstall.injector import handler, download
8 version = '1.10'
10 class GUIHandler(handler.Handler):
11 dl_callbacks = None # Download -> [ callback ]
12 pulse = None
13 mainwindow = None
15 def _reset_counters(self):
16 if not self.monitored_downloads:
17 self.n_completed_downloads = 0
18 self.total_bytes_downloaded = 0
19 return False
21 def abort_all_downloads(self):
22 for dl in self.monitored_downloads:
23 dl.abort()
25 def downloads_changed(self):
26 if self.monitored_downloads and self.pulse is None:
27 def pulse():
28 self.mainwindow.update_download_status(only_update_visible = True)
29 return True
30 pulse()
31 self.pulse = gobject.timeout_add(200, pulse)
32 elif len(self.monitored_downloads) == 0:
33 # Delay before resetting, in case we start a new download quickly
34 gobject.timeout_add(500, self._reset_counters)
36 # Stop animation
37 if self.pulse:
38 gobject.source_remove(self.pulse)
39 self.pulse = None
40 self.mainwindow.update_download_status()
42 def impl_added_to_store(self, impl):
43 self.mainwindow.update_download_status(only_update_visible = True)
45 @tasks.async
46 def _switch_to_main_window(self, reason):
47 if self.mainwindow.systray_icon:
48 self.mainwindow.systray_icon.set_tooltip(reason)
49 self.mainwindow.systray_icon.set_blinking(True)
51 # Wait for the user to click the icon, then continue
52 yield self.mainwindow.systray_icon_blocker
53 yield tasks.TimeoutBlocker(0.5, 'Delay')
55 @tasks.async
56 def confirm_import_feed(self, pending, valid_sigs):
57 yield self._switch_to_main_window(_('Need to confirm a new GPG key'))
59 from zeroinstall.gtkui import trust_box
60 box = trust_box.TrustBox(pending, valid_sigs, parent = self.mainwindow.window)
61 box.show()
62 yield box.closed
64 @tasks.async
65 def confirm_install(self, message):
66 yield self._switch_to_main_window(_('Need to confirm installation of distribution packages'))
68 from zeroinstall.injector.download import DownloadAborted
69 import dialog
70 import gtk
71 box = gtk.MessageDialog(self.mainwindow.window,
72 gtk.DIALOG_DESTROY_WITH_PARENT,
73 gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL,
74 str(message))
75 box.set_position(gtk.WIN_POS_CENTER)
77 install = dialog.MixedButton(_('Install'), gtk.STOCK_OK)
78 install.set_can_default(True)
79 box.add_action_widget(install, gtk.RESPONSE_OK)
80 install.show_all()
81 box.set_default_response(gtk.RESPONSE_OK)
82 box.show()
84 response = dialog.DialogResponse(box)
85 yield response
86 box.destroy()
88 if response.response != gtk.RESPONSE_OK:
89 raise DownloadAborted()
91 def report_error(self, ex, tb = None):
92 if isinstance(ex, download.DownloadAborted):
93 return # No need to tell the user about this, since they caused it
94 self.mainwindow.report_exception(ex, tb = tb)