Make errors in the download box selectable (requested by Peter Prohaska).
[zeroinstall.git] / dialog.py
blobfcc2379a2216759cdf3b2255750999d27048e35d
1 import gtk
3 n_windows = 0
5 class Dialog(gtk.Dialog):
6 def __init__(self):
7 gtk.Dialog.__init__(self)
8 self.set_has_separator(False)
9 self.set_position(gtk.WIN_POS_CENTER)
11 def destroyed(widget):
12 _one_less_window()
13 self.connect('destroy', destroyed)
15 def show(self):
16 global n_windows
17 n_windows += 1
18 gtk.Dialog.show(self)
20 def add_mixed_button(self, message, stock, response):
21 button = gtk.Button()
23 label = gtk.Label('')
24 label.set_text_with_mnemonic(message)
25 label.set_mnemonic_widget(button)
27 image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_BUTTON)
28 box = gtk.HBox(False, 2)
29 align = gtk.Alignment(0.5, 0.5, 0.0, 0.0)
31 box.pack_start(image, False, False, 0)
32 box.pack_end(label, False, False, 0)
34 button.add(align)
35 align.add(box)
36 button.set_flags(gtk.CAN_DEFAULT)
38 self.add_action_widget(button, response)
39 button.show_all()
41 def alert(parent, message):
42 global n_windows
43 box = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT,
44 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
45 str(message))
46 box.set_position(gtk.WIN_POS_CENTER)
47 def resp(b, r):
48 box.destroy()
49 _one_less_window()
50 box.connect('response', resp)
51 box.show()
52 n_windows += 1
54 def _one_less_window():
55 global n_windows
56 n_windows -= 1
57 if n_windows == 0:
58 gtk.main_quit()
60 def wait_for_no_windows():
61 while n_windows > 0:
62 gtk.main()