]>
Commit | Line | Data |
---|---|---|
ec3e670f | 1 | |
e166644c RD |
2 | import sys, os |
3 | ||
4 | from wxPython.wx import * | |
5 | from wxPython.html import * | |
e166644c | 6 | import wxPython.lib.wxpTag |
ec3e670f RD |
7 | |
8 | #---------------------------------------------------------------------- | |
9 | ||
10 | # This shows how to catch the OnLinkClicked non-event. (It's a virtual | |
11 | # method in the C++ code...) | |
12 | class MyHtmlWindow(wxHtmlWindow): | |
13 | def __init__(self, parent, id, log): | |
14 | wxHtmlWindow.__init__(self, parent, id) | |
15 | self.log = log | |
16 | ||
17 | def OnLinkClicked(self, link): | |
18 | self.log.WriteText('OnLinkClicked: %s\n' % link) | |
19 | ||
20 | # Virtuals in the base class have been renamed with base_ on the font. | |
21 | self.base_OnLinkClicked(link) | |
22 | ||
23 | ||
24 | ||
25 | class TestHtmlPanel(wxPanel): | |
26 | def __init__(self, parent, frame, log): | |
27 | wxPanel.__init__(self, parent, -1) | |
28 | self.log = log | |
29 | self.frame = frame | |
ae920857 RD |
30 | self.cwd = os.path.split(sys.argv[0])[0] |
31 | if not self.cwd: | |
32 | self.cwd = os.getcwd() | |
ec3e670f RD |
33 | |
34 | ||
35 | self.html = MyHtmlWindow(self, -1, log) | |
36 | self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s") | |
37 | self.html.SetRelatedStatusBar(0) | |
38 | ||
65dd82cb RD |
39 | self.printer = wxHtmlEasyPrinting() |
40 | ||
2f90df85 RD |
41 | self.box = wxBoxSizer(wxVERTICAL) |
42 | self.box.Add(self.html, 1, wxGROW) | |
ec3e670f RD |
43 | |
44 | subbox = wxBoxSizer(wxHORIZONTAL) | |
45 | btn = wxButton(self, 1201, "Show Default") | |
46 | EVT_BUTTON(self, 1201, self.OnShowDefault) | |
2f90df85 | 47 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
48 | |
49 | btn = wxButton(self, 1202, "Load File") | |
50 | EVT_BUTTON(self, 1202, self.OnLoadFile) | |
2f90df85 | 51 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
52 | |
53 | btn = wxButton(self, 1203, "With Widgets") | |
54 | EVT_BUTTON(self, 1203, self.OnWithWidgets) | |
2f90df85 | 55 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
56 | |
57 | btn = wxButton(self, 1204, "Back") | |
58 | EVT_BUTTON(self, 1204, self.OnBack) | |
2f90df85 | 59 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
60 | |
61 | btn = wxButton(self, 1205, "Forward") | |
62 | EVT_BUTTON(self, 1205, self.OnForward) | |
2f90df85 | 63 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f | 64 | |
65dd82cb RD |
65 | btn = wxButton(self, 1207, "Print") |
66 | EVT_BUTTON(self, 1207, self.OnPrint) | |
67 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
68 | ||
e166644c RD |
69 | btn = wxButton(self, 1206, "View Source") |
70 | EVT_BUTTON(self, 1206, self.OnViewSource) | |
2f90df85 | 71 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
e166644c | 72 | |
2f90df85 RD |
73 | self.box.Add(subbox, 0, wxGROW) |
74 | self.SetSizer(self.box) | |
75 | self.SetAutoLayout(true) | |
e166644c RD |
76 | |
77 | # A button with this ID is created on the widget test page. | |
78 | EVT_BUTTON(self, wxID_OK, self.OnOk) | |
79 | ||
ec3e670f RD |
80 | self.OnShowDefault(None) |
81 | ||
82 | ||
e166644c | 83 | |
ec3e670f RD |
84 | |
85 | def OnShowDefault(self, event): | |
ae920857 | 86 | name = os.path.join(self.cwd, 'data/test.htm') |
e166644c | 87 | self.html.LoadPage(name) |
ec3e670f RD |
88 | |
89 | ||
90 | def OnLoadFile(self, event): | |
e166644c RD |
91 | dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN) |
92 | if dlg.ShowModal(): | |
93 | path = dlg.GetPath() | |
94 | self.html.LoadPage(path) | |
95 | dlg.Destroy() | |
ec3e670f RD |
96 | |
97 | ||
98 | def OnWithWidgets(self, event): | |
ae920857 RD |
99 | os.chdir(self.cwd) |
100 | name = os.path.join(self.cwd, 'data/widgetTest.htm') | |
e166644c | 101 | self.html.LoadPage(name) |
ae920857 | 102 | |
e166644c RD |
103 | |
104 | def OnOk(self, event): | |
105 | self.log.WriteText("It works!\n") | |
ec3e670f RD |
106 | |
107 | def OnBack(self, event): | |
108 | if not self.html.HistoryBack(): | |
109 | wxMessageBox("No more items in history!") | |
110 | ||
e166644c | 111 | |
ec3e670f RD |
112 | def OnForward(self, event): |
113 | if not self.html.HistoryForward(): | |
114 | wxMessageBox("No more items in history!") | |
115 | ||
116 | ||
e166644c RD |
117 | def OnViewSource(self, event): |
118 | from wxPython.lib.dialogs import wxScrolledMessageDialog | |
119 | source = self.html.GetParser().GetSource() | |
120 | dlg = wxScrolledMessageDialog(self, source, 'HTML Source') | |
121 | dlg.ShowModal() | |
122 | dlg.Destroy() | |
123 | ||
124 | ||
65dd82cb RD |
125 | def OnPrint(self, event): |
126 | self.printer.PrintFile(self.html.GetOpenedPage()) | |
127 | ||
ec3e670f RD |
128 | #---------------------------------------------------------------------- |
129 | ||
130 | def runTest(frame, nb, log): | |
131 | win = TestHtmlPanel(nb, frame, log) | |
132 | return win | |
133 | ||
134 | ||
135 | #---------------------------------------------------------------------- | |
136 | ||
137 | ||
138 | ||
139 | ||
140 | ||
141 | overview = """\ | |
142 | wxHtmlWindow is capable of parsing and rendering most simple HTML tags. | |
143 | ||
144 | It is not intended to be a high-end HTML browser. If you're looking for something like that try http://www.mozilla.org - there's a chance you'll be able to make their widget wxWindows-compatible. I'm sure everyone will enjoy your work in that case... | |
145 | ||
146 | """ | |
147 | ||
e166644c RD |
148 | |
149 | ||
150 | ||
151 | ||
e166644c RD |
152 | |
153 | ||
154 | ||
155 | ||
156 |