1 """A dialog box for displaying help text."""
2 # Copyright (C) 2009, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
8 """A dialog for showing longish help texts.
9 The GTK widget is not created until L{display} is called.
15 def __init__(self
, title
, *sections
):
17 @param title: window title
18 @param sections: the content, as a list of (section_title, section_body) pairs
19 @type sections: [(str, str)]"""
21 self
.sections
= sections
24 """Display this help text. If it is already displayed, close the old window first."""
29 self
.box
= box
= gtk
.Dialog()
30 self
.box
.set_has_separator(False)
31 self
.box
.set_position(gtk
.WIN_POS_CENTER
)
32 box
.set_title(self
.title
)
33 box
.set_has_separator(False)
35 swin
= gtk
.ScrolledWindow(None, None)
36 swin
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
37 swin
.set_shadow_type(gtk
.SHADOW_IN
)
38 swin
.set_border_width(2)
39 box
.vbox
.pack_start(swin
, True, True)
42 text
.set_left_margin(4)
43 text
.set_right_margin(4)
44 text
.set_wrap_mode(gtk
.WRAP_WORD
)
45 text
.set_editable(False)
46 text
.set_cursor_visible(False)
47 model
= text
.get_buffer()
48 titer
= model
.get_start_iter()
49 heading_style
= model
.create_tag(underline
= True, scale
= 1.2)
52 for title
, body
in self
.sections
:
56 model
.insert(titer
, '\n\n')
57 model
.insert_with_tags(titer
, title
, heading_style
)
58 model
.insert(titer
, '\n' + body
.strip())
63 box
.add_button(gtk
.STOCK_CLOSE
, gtk
.RESPONSE_CANCEL
)
64 box
.connect('response', lambda box
, resp
: box
.destroy())
66 box
.set_default_response(gtk
.RESPONSE_CANCEL
)
70 box
.connect('destroy', destroyed
)
72 box
.set_position(gtk
.WIN_POS_CENTER
)
73 box
.set_default_size(gtk
.gdk
.screen_width() / 4,
74 gtk
.gdk
.screen_height() / 3)