Updated uris in tests, and removed code that caused a warning.
[zeroinstall.git] / help_box.py
blobec663d5f44bc39321788fb6002b64fad4a4ff103
1 import gtk
3 from dialog import Dialog
5 class HelpBox:
6 box = None
7 title = None
8 sections = None
10 def __init__(self, title, *sections):
11 self.title = title
12 self.sections = sections
14 def display(self):
15 if self.box:
16 self.box.destroy()
17 assert not self.box
19 self.box = box = Dialog()
20 box.set_title(self.title)
21 box.set_has_separator(False)
23 swin = gtk.ScrolledWindow(None, None)
24 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
25 swin.set_shadow_type(gtk.SHADOW_IN)
26 swin.set_border_width(2)
27 box.vbox.pack_start(swin, True, True)
29 text = gtk.TextView()
30 text.set_left_margin(4)
31 text.set_right_margin(4)
32 text.set_wrap_mode(gtk.WRAP_WORD)
33 text.set_editable(False)
34 text.set_cursor_visible(False)
35 body = text.get_buffer()
36 titer = body.get_start_iter()
37 heading_style = body.create_tag(underline = True, scale = 1.2)
39 first = True
40 for title, body in self.sections:
41 if first:
42 first = False
43 else:
44 body.insert(titer, '\n\n')
45 body.insert_with_tags(titer, title, heading_style)
46 body.insert(titer, '\n' + body.strip())
47 swin.add(text)
49 swin.show_all()
51 box.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
52 box.connect('response', lambda box, resp: box.destroy())
54 box.set_default_response(gtk.RESPONSE_CANCEL)
56 def destroyed(box):
57 self.box = None
58 box.connect('destroy', destroyed)
60 box.set_position(gtk.WIN_POS_CENTER)
61 box.set_default_size(gtk.gdk.screen_width() / 4,
62 gtk.gdk.screen_height() / 3)
63 box.show()