Moved some useful GUI code into zeroinstall.gtkui.gtkutils.
[zeroinstall/zeroinstall-rsl.git] / zeroinstall / 0launch-gui / help_box.py
blob03ee534f28585254849fdbc04db61ba552d119ec
1 # Copyright (C) 2008, Thomas Leonard
2 # See the README file for details, or visit http://0install.net.
4 import gtk
6 from dialog import Dialog
8 class HelpBox:
9 box = None
10 title = None
11 sections = None
13 def __init__(self, title, *sections):
14 self.title = title
15 self.sections = sections
17 def display(self):
18 if self.box:
19 self.box.destroy()
20 assert not self.box
22 self.box = box = Dialog()
23 box.set_title(self.title)
24 box.set_has_separator(False)
26 swin = gtk.ScrolledWindow(None, None)
27 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
28 swin.set_shadow_type(gtk.SHADOW_IN)
29 swin.set_border_width(2)
30 box.vbox.pack_start(swin, True, True)
32 text = gtk.TextView()
33 text.set_left_margin(4)
34 text.set_right_margin(4)
35 text.set_wrap_mode(gtk.WRAP_WORD)
36 text.set_editable(False)
37 text.set_cursor_visible(False)
38 model = text.get_buffer()
39 titer = model.get_start_iter()
40 heading_style = model.create_tag(underline = True, scale = 1.2)
42 first = True
43 for title, body in self.sections:
44 if first:
45 first = False
46 else:
47 model.insert(titer, '\n\n')
48 model.insert_with_tags(titer, title, heading_style)
49 model.insert(titer, '\n' + body.strip())
50 swin.add(text)
52 swin.show_all()
54 box.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
55 box.connect('response', lambda box, resp: box.destroy())
57 box.set_default_response(gtk.RESPONSE_CANCEL)
59 def destroyed(box):
60 self.box = None
61 box.connect('destroy', destroyed)
63 box.set_position(gtk.WIN_POS_CENTER)
64 box.set_default_size(gtk.gdk.screen_width() / 4,
65 gtk.gdk.screen_height() / 3)
66 box.show()