Added @tasks.async decorator to simplify common code.
[zeroinstall.git] / zeroinstall / 0launch-gui / checking.py
blobb0854ea812c8bf6ce92179f7b7081135ee421840
1 import gtk, gobject
3 from dialog import Dialog
4 from zeroinstall.support import tasks
6 class CheckingBox(Dialog):
7 hint_timeout = None
9 def __init__(self, root):
10 Dialog.__init__(self)
11 self.prog_name = root.get_name()
12 self.set_title("Checking for updates")
13 self.label = gtk.Label("Checking for updates to '%s'..." % self.prog_name)
14 self.label.set_padding(10, 10)
15 self.vbox.pack_start(self.label, True, True, 0)
16 self.vbox.show_all()
18 self.progress = gtk.ProgressBar()
19 self.vbox.pack_start(self.progress, False, True, 0)
20 self.progress.show()
22 self.show_details_clicked = tasks.Blocker("click Show Details")
23 self.cancelled = tasks.Blocker("cancel checking box")
25 self.add_mixed_button('Details...', gtk.STOCK_ZOOM_IN, gtk.RESPONSE_OK)
26 def response(w, r):
27 if r == gtk.RESPONSE_OK:
28 self.show_details_clicked.trigger()
29 else:
30 self.cancelled.trigger()
31 self.connect('response', response)
33 def show_hint():
34 hint = gtk.Label("(if you want to skip this, click on\n"
35 "Details, and then on Run)")
36 hint.set_justify(gtk.JUSTIFY_CENTER)
37 self.vbox.pack_start(hint, False, True, 0)
38 self.vbox.show_all()
39 self.hint_timeout = None
40 return False
41 self.hint_timeout = self.hint_timeout = gobject.timeout_add(8000, show_hint)
42 def destroy(box):
43 if self.hint_timeout is not None:
44 gobject.source_remove(self.hint_timeout)
45 self.hint_timeout = None
46 self.connect('destroy', destroy)
48 def updates_done(self, changes):
49 """Close the dialog after a short delay"""
50 if changes:
51 self.label.set_text("Updates found for '%s'" % self.prog_name)
52 else:
53 self.label.set_text("No updates for '%s'" % self.prog_name)
54 self.progress.set_fraction(1)
55 self.set_response_sensitive(gtk.RESPONSE_OK, False)