~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/samples/wxPIA_book/Chapter-16/html_help.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
wxPython can use html files for online help or other forms of
 
3
documentation for your application.  The help can be organized as a
 
4
collection of books, and there is a help viewer available that enables
 
5
the user to browse by book, via an index or full text search.  The
 
6
format of the contents and index files are similar to Microsoft
 
7
HtmlHelp.
 
8
"""
 
9
 
 
10
import wx
 
11
import wx.html
 
12
 
 
13
class MyHtmlFrame(wx.Frame):
 
14
    def __init__(self, parent, title):
 
15
        wx.Frame.__init__(self, parent, -1, title)
 
16
        p = wx.Panel(self)
 
17
        b1 = wx.Button(p, -1, "Show Help Contents")
 
18
        b2 = wx.Button(p, -1, "Show Help Index")
 
19
        b3 = wx.Button(p, -1, "Show Specific Help")
 
20
        self.Bind(wx.EVT_BUTTON, self.OnShowHelpContents, b1)
 
21
        self.Bind(wx.EVT_BUTTON, self.OnShowHelpIndex, b2)
 
22
        self.Bind(wx.EVT_BUTTON, self.OnShowSpecificHelp, b3)
 
23
 
 
24
        sizer = wx.BoxSizer(wx.VERTICAL)
 
25
        sizer.Add((10,10))
 
26
        sizer.Add(b1, 0, wx.ALL, 10)
 
27
        sizer.Add(b2, 0, wx.ALL, 10)
 
28
        sizer.Add(b3, 0, wx.ALL, 10)
 
29
        p.SetSizer(sizer)
 
30
        
 
31
        self.InitHelp()
 
32
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
 
33
 
 
34
        
 
35
    def InitHelp(self):
 
36
        def _addBook(filename):
 
37
            if not self.help.AddBook(filename):
 
38
                wx.MessageBox("Unable to open: " + filename,
 
39
                              "Error", wx.OK|wx.ICON_EXCLAMATION)
 
40
 
 
41
        self.help = wx.html.HtmlHelpController()
 
42
        _addBook("helpfiles/testing.hhp")
 
43
        _addBook("helpfiles/another.hhp")
 
44
 
 
45
 
 
46
    def OnCloseWindow(self, evt):
 
47
        del self.help
 
48
        evt.Skip()
 
49
        
 
50
    def OnShowHelpContents(self, evt):
 
51
        self.help.DisplayContents()
 
52
 
 
53
    def OnShowHelpIndex(self, evt):
 
54
        self.help.DisplayIndex()
 
55
 
 
56
    def OnShowSpecificHelp(self, evt):
 
57
        self.help.Display("sub book")
 
58
 
 
59
 
 
60
app = wx.PySimpleApp()
 
61
frm = MyHtmlFrame(None, "HTML Help")
 
62
frm.Show()
 
63
app.MainLoop()