]>
Commit | Line | Data |
---|---|---|
d14a1e28 | 1 | #---------------------------------------------------------------------- |
cbfc9df6 | 2 | # Name: wx.tools.helpviewer |
d14a1e28 RD |
3 | # Purpose: HTML Help viewer |
4 | # | |
5 | # Author: Robin Dunn | |
6 | # | |
7 | # Created: 11-Dec-2002 | |
8 | # RCS-ID: $Id$ | |
9 | # Copyright: (c) 2002 by Total Control Software | |
10 | # Licence: wxWindows license | |
11 | #---------------------------------------------------------------------- | |
1fded56b | 12 | |
d14a1e28 RD |
13 | """ |
14 | helpviewer.py -- Displays HTML Help in a wxHtmlHelpController window. | |
1fded56b | 15 | |
d14a1e28 RD |
16 | Usage: |
17 | helpviewer [--cache=path] helpfile [helpfile(s)...] | |
18 | ||
19 | Where helpfile is the path to either a .hhp file or a .zip file | |
20 | which contians a .hhp file. The .hhp files are the same as those | |
21 | used by Microsoft's HTML Help Workshop for creating CHM files. | |
22 | """ | |
23 | ||
24 | ||
25 | import sys, os | |
26 | ||
27 | #--------------------------------------------------------------------------- | |
28 | ||
cbfc9df6 RD |
29 | def makeOtherFrame(helpctrl): |
30 | import wx | |
31 | parent = helpctrl.GetFrame() | |
32 | otherFrame = wx.Frame(parent) | |
33 | ||
34 | ||
d14a1e28 RD |
35 | def main(args=sys.argv): |
36 | if len(args) < 2: | |
37 | print __doc__ | |
38 | return | |
39 | ||
40 | args = args[1:] | |
41 | cachedir = None | |
42 | if args[0][:7] == '--cache': | |
43 | cachedir = os.path.expanduser(args[0].split('=')[1]) | |
44 | args = args[1:] | |
45 | ||
46 | if len(args) == 0: | |
47 | print __doc__ | |
48 | return | |
49 | ||
e6c3f9eb RD |
50 | import wx |
51 | import wx.html | |
d14a1e28 | 52 | |
e6c3f9eb RD |
53 | app = wx.PySimpleApp() |
54 | #wx.Log.SetActiveTarget(wx.LogStderr()) | |
55 | wx.Log.SetLogLevel(wx.LOG_Error) | |
d14a1e28 RD |
56 | |
57 | # Set up the default config so the htmlhelp frame can save its preferences | |
58 | app.SetVendorName('wxWindows') | |
59 | app.SetAppName('helpviewer') | |
e6c3f9eb | 60 | cfg = wx.ConfigBase.Get() |
d14a1e28 RD |
61 | |
62 | # Add the Zip filesystem | |
e6c3f9eb | 63 | wx.FileSystem.AddHandler(wx.ZipFSHandler()) |
d14a1e28 RD |
64 | |
65 | # Create the viewer | |
e6c3f9eb | 66 | helpctrl = wx.html.HtmlHelpController() |
d14a1e28 RD |
67 | if cachedir: |
68 | helpctrl.SetTempDir(cachedir) | |
69 | ||
70 | # and add the books | |
71 | for helpfile in args: | |
72 | print "Adding %s..." % helpfile | |
73 | helpctrl.AddBook(helpfile, 1) | |
74 | ||
cbfc9df6 RD |
75 | # The frame used by the HtmlHelpController is set to not prevent |
76 | # app exit, so in the case of a standalone helpviewer like this | |
77 | # when the about box or search box is closed the help frame will | |
78 | # be the only one left and the app will close unexpectedly. To | |
79 | # work around this we'll create another frame that is never shown, | |
80 | # but which will be closed when the helpviewer frame is closed. | |
81 | wx.CallAfter(makeOtherFrame, helpctrl) | |
82 | ||
d14a1e28 RD |
83 | # start it up! |
84 | helpctrl.DisplayContents() | |
85 | app.MainLoop() | |
86 | ||
87 | ||
88 | if __name__ == '__main__': | |
89 | main() | |
e6c3f9eb RD |
90 | |
91 |