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.
9 """A dialog for showing longish help texts.
10 The GTK widget is not created until L{display} is called.
16 def __init__(self
, title
, *sections
):
18 @param title: window title
19 @param sections: the content, as a list of (section_title, section_body) pairs
20 @type sections: [(str, str)]"""
22 self
.sections
= sections
25 """Display this help text. If it is already displayed, close the old window first."""
30 self
.box
= box
= gtk
.Dialog()
31 if sys
.version_info
[0] < 3:
32 self
.box
.set_has_separator(False)
33 self
.box
.set_position(gtk
.WIN_POS_CENTER
)
34 box
.set_title(self
.title
)
36 swin
= gtk
.ScrolledWindow(None, None)
37 swin
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
38 swin
.set_shadow_type(gtk
.SHADOW_IN
)
39 swin
.set_border_width(2)
40 box
.get_content_area().pack_start(swin
, True, True, 0)
43 text
.set_left_margin(4)
44 text
.set_right_margin(4)
45 text
.set_wrap_mode(gtk
.WRAP_WORD
)
46 text
.set_editable(False)
47 text
.set_cursor_visible(False)
48 model
= text
.get_buffer()
49 titer
= model
.get_start_iter()
50 heading_style
= model
.create_tag(underline
= True, scale
= 1.2)
53 for title
, body
in self
.sections
:
57 model
.insert(titer
, '\n\n')
58 model
.insert_with_tags(titer
, title
, heading_style
)
59 model
.insert(titer
, '\n' + body
.strip())
64 box
.add_button(gtk
.STOCK_CLOSE
, gtk
.RESPONSE_CANCEL
)
65 box
.connect('response', lambda box
, resp
: box
.destroy())
67 box
.set_default_response(gtk
.RESPONSE_CANCEL
)
71 box
.connect('destroy', destroyed
)
73 box
.set_position(gtk
.WIN_POS_CENTER
)
74 box
.set_default_size(gtk
.gdk
.screen_width() / 4,
75 gtk
.gdk
.screen_height() / 3)