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. 4 5importgtk 6importsys 7
17"""Constructor.18 @param title: window title19 @param sections: the content, as a list of (section_title, section_body) pairs20 @type sections: [(str, str)]"""21self.title=title22self.sections=sections
25"""Display this help text. If it is already displayed, close the old window first."""26ifself.box:27self.box.destroy()28assertnotself.box2930self.box=box=gtk.Dialog()31ifsys.version_info[0]<3:32self.box.set_has_separator(False)33self.box.set_position(gtk.WIN_POS_CENTER)34box.set_title(self.title)3536swin=gtk.ScrolledWindow(None,None)37swin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_ALWAYS)38swin.set_shadow_type(gtk.SHADOW_IN)39swin.set_border_width(2)40box.get_content_area().pack_start(swin,True,True,0)4142text=gtk.TextView()43text.set_left_margin(4)44text.set_right_margin(4)45text.set_wrap_mode(gtk.WRAP_WORD)46text.set_editable(False)47text.set_cursor_visible(False)48model=text.get_buffer()49titer=model.get_start_iter()50heading_style=model.create_tag(underline=True,scale=1.2)5152first=True53fortitle,bodyinself.sections:54iffirst:55first=False56else:57model.insert(titer,'\n\n')58model.insert_with_tags(titer,title,heading_style)59model.insert(titer,'\n'+body.strip())60swin.add(text)6162swin.show_all()6364box.add_button(gtk.STOCK_CLOSE,gtk.RESPONSE_CANCEL)65box.connect('response',lambdabox,resp:box.destroy())6667box.set_default_response(gtk.RESPONSE_CANCEL)6869defdestroyed(box):70self.box=None