Perform GUI downloads in the main window.
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / 0launch-gui / dialog.py
blobcac1dcfd460208001f3bd7816f9aee4dd359d679
1 import gtk
3 n_windows = 0
5 last_error = None
7 class Dialog(gtk.Dialog):
8 __shown = False
10 def __init__(self):
11 gtk.Dialog.__init__(self)
12 self.set_has_separator(False)
13 self.set_position(gtk.WIN_POS_CENTER)
15 def add_mixed_button(self, message, stock, response):
16 button = MixedButton(message, stock)
17 button.set_flags(gtk.CAN_DEFAULT)
19 self.add_action_widget(button, response)
20 button.show_all()
21 return button
23 def alert(parent, message, type = gtk.MESSAGE_ERROR):
24 if type == gtk.MESSAGE_ERROR:
25 global last_error
26 last_error = message
28 box = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT,
29 type, gtk.BUTTONS_OK,
30 str(message))
31 box.set_position(gtk.WIN_POS_CENTER)
32 def resp(b, r):
33 b.destroy()
34 box.connect('response', resp)
35 box.show()
37 def MixedButton(message, stock, x_align = 0.5):
38 button = gtk.Button()
40 label = gtk.Label('')
41 label.set_text_with_mnemonic(message)
42 label.set_mnemonic_widget(button)
44 image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_BUTTON)
45 box = gtk.HBox(False, 2)
46 align = gtk.Alignment(x_align, 0.5, 0.0, 0.0)
48 box.pack_start(image, False, False, 0)
49 box.pack_end(label, False, False, 0)
51 button.add(align)
52 align.add(box)
53 return button
55 def frame(page, title, content, expand = False):
56 frame = gtk.Frame()
57 label = gtk.Label()
58 label.set_markup('<b>%s</b>' % title)
59 frame.set_label_widget(label)
60 frame.set_shadow_type(gtk.SHADOW_NONE)
61 if type(content) in (str, unicode):
62 content = gtk.Label(content)
63 content.set_alignment(0, 0.5)
64 content.set_selectable(True)
65 frame.add(content)
66 if hasattr(content, 'set_padding'):
67 content.set_padding(8, 4)
68 else:
69 content.set_border_width(8)
70 page.pack_start(frame, expand, True, 0)