help_box.py :  » Installer » Zero-Install » zeroinstall-injector-0.47 » zeroinstall » gtkui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Installer » Zero Install 
Zero Install » zeroinstall injector 0.47 » zeroinstall » gtkui » help_box.py
"""A dialog box for displaying help text."""
# Copyright (C) 2009, Thomas Leonard
# See the README file for details, or visit http://0install.net.

from zeroinstall import _
import gtk

class HelpBox:
  """A dialog for showing longish help texts.
  The GTK widget is not created until L{display} is called.
  """
  box = None
  title = None
  sections = None

  def __init__(self, title, *sections):
    """Constructor.
    @param title: window title
    @param sections: the content, as a list of (section_title, section_body) pairs
    @type sections: [(str, str)]"""
    self.title = title
    self.sections = sections
  
  def display(self):
    """Display this help text. If it is already displayed, close the old window first."""
    if self.box:
      self.box.destroy()
      assert not self.box

    self.box = box = gtk.Dialog()
    self.box.set_has_separator(False)
    self.box.set_position(gtk.WIN_POS_CENTER)
    box.set_title(self.title)
    box.set_has_separator(False)

    swin = gtk.ScrolledWindow(None, None)
    swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
    swin.set_shadow_type(gtk.SHADOW_IN)
    swin.set_border_width(2)
    box.vbox.pack_start(swin, True, True)

    text = gtk.TextView()
    text.set_left_margin(4)
    text.set_right_margin(4)
    text.set_wrap_mode(gtk.WRAP_WORD)
    text.set_editable(False)
    text.set_cursor_visible(False)
    model = text.get_buffer()
    titer = model.get_start_iter()
    heading_style = model.create_tag(underline = True, scale = 1.2)

    first = True
    for title, body in self.sections:
      if first:
        first = False
      else:
        model.insert(titer, '\n\n')
      model.insert_with_tags(titer, title, heading_style)
      model.insert(titer, '\n' + body.strip())
    swin.add(text)

    swin.show_all()

    box.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CANCEL)
    box.connect('response', lambda box, resp: box.destroy())

    box.set_default_response(gtk.RESPONSE_CANCEL)

    def destroyed(box):
      self.box = None
    box.connect('destroy', destroyed)

    box.set_position(gtk.WIN_POS_CENTER)
    box.set_default_size(gtk.gdk.screen_width() / 4,
              gtk.gdk.screen_height() / 3)
    box.show()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.