Remove checking box from GUI.
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / 0launch-gui / dialog.py
blobda5927ccca6414fa0cc45bafbf2bea680d135c18
1 import gtk
2 from zeroinstall.support import tasks
4 n_windows = 0
6 last_error = None
8 class Dialog(gtk.Dialog):
9 __shown = False
11 def __init__(self):
12 gtk.Dialog.__init__(self)
13 self.set_has_separator(False)
14 self.set_position(gtk.WIN_POS_CENTER)
16 def add_mixed_button(self, message, stock, response):
17 button = MixedButton(message, stock)
18 button.set_flags(gtk.CAN_DEFAULT)
20 self.add_action_widget(button, response)
21 button.show_all()
22 return button
24 class DialogResponse(tasks.Blocker):
25 response = None
26 def __init__(self, dialog):
27 tasks.Blocker.__init__(self, dialog.get_title())
28 a = None
29 def response(d, resp):
30 self.response = resp
31 d.disconnect(a)
32 self.trigger()
33 a = dialog.connect('response', response)
35 def alert(parent, message, type = gtk.MESSAGE_ERROR):
36 if type == gtk.MESSAGE_ERROR:
37 global last_error
38 last_error = message
40 box = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT,
41 type, gtk.BUTTONS_OK,
42 str(message))
43 box.set_position(gtk.WIN_POS_CENTER)
44 def resp(b, r):
45 b.destroy()
46 box.connect('response', resp)
47 box.show()
49 def MixedButton(message, stock, x_align = 0.5, button = None):
50 if button is None:
51 button = gtk.Button()
53 label = gtk.Label('')
54 label.set_text_with_mnemonic(message)
55 label.set_mnemonic_widget(button)
57 image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_BUTTON)
58 box = gtk.HBox(False, 2)
59 align = gtk.Alignment(x_align, 0.5, 0.0, 0.0)
61 box.pack_start(image, False, False, 0)
62 box.pack_end(label, False, False, 0)
64 button.add(align)
65 align.add(box)
66 return button
68 def frame(page, title, content, expand = False):
69 frame = gtk.Frame()
70 label = gtk.Label()
71 label.set_markup('<b>%s</b>' % title)
72 frame.set_label_widget(label)
73 frame.set_shadow_type(gtk.SHADOW_NONE)
74 if type(content) in (str, unicode):
75 content = gtk.Label(content)
76 content.set_alignment(0, 0.5)
77 content.set_selectable(True)
78 frame.add(content)
79 if hasattr(content, 'set_padding'):
80 content.set_padding(8, 4)
81 else:
82 content.set_border_width(8)
83 page.pack_start(frame, expand, True, 0)