Release 1.1
[zeroinstall.git] / zeroinstall / 0launch-gui / gui.py
blobe1f7ba4a5b8c3f4ab01862f23fb1a711d61cbc7a
1 # Copyright (C) 2009, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
4 import gobject
6 from zeroinstall import _
7 from zeroinstall.support import tasks
8 from zeroinstall.injector import handler, download
10 version = '1.1'
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 @tasks.async
48 def _switch_to_main_window(self, reason):
49 if self.mainwindow.systray_icon:
50 self.mainwindow.systray_icon.set_tooltip(reason)
51 self.mainwindow.systray_icon.set_blinking(True)
53 # Wait for the user to click the icon, then continue
54 yield self.mainwindow.systray_icon_blocker
55 yield tasks.TimeoutBlocker(0.5, 'Delay')
57 @tasks.async
58 def confirm_import_feed(self, pending, valid_sigs):
59 yield self._switch_to_main_window(_('Need to confirm a new GPG key'))
61 from zeroinstall.gtkui import trust_box
62 box = trust_box.TrustBox(pending, valid_sigs, parent = self.mainwindow.window)
63 box.show()
64 yield box.closed
66 @tasks.async
67 def confirm_install(self, message):
68 yield self._switch_to_main_window(_('Need to confirm installation of distribution packages'))
70 from zeroinstall.injector.download import DownloadAborted
71 import dialog
72 import gtk
73 box = gtk.MessageDialog(self.mainwindow.window,
74 gtk.DIALOG_DESTROY_WITH_PARENT,
75 gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL,
76 str(message))
77 box.set_position(gtk.WIN_POS_CENTER)
79 install = dialog.MixedButton(_('Install'), gtk.STOCK_OK)
80 install.set_flags(gtk.CAN_DEFAULT)
81 box.add_action_widget(install, gtk.RESPONSE_OK)
82 install.show_all()
83 box.set_default_response(gtk.RESPONSE_OK)
84 box.show()
86 response = dialog.DialogResponse(box)
87 yield response
88 box.destroy()
90 if response.response != gtk.RESPONSE_OK:
91 raise DownloadAborted()
93 def report_error(self, ex, tb = None):
94 if isinstance(ex, download.DownloadAborted):
95 return # No need to tell the user about this, since they caused it
96 self.mainwindow.report_exception(ex, tb = tb)