]>
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 | 7 | |
6c5ae2d2 RD |
8 | from Main import opj |
9 | ||
fd3f2efe RD |
10 | ##wxTrap() |
11 | ||
ec3e670f RD |
12 | #---------------------------------------------------------------------- |
13 | ||
14 | # This shows how to catch the OnLinkClicked non-event. (It's a virtual | |
15 | # method in the C++ code...) | |
16 | class MyHtmlWindow(wxHtmlWindow): | |
17 | def __init__(self, parent, id, log): | |
fe953afb | 18 | wxHtmlWindow.__init__(self, parent, id, style=wxNO_FULL_REPAINT_ON_RESIZE) |
ec3e670f | 19 | self.log = log |
c368d904 RD |
20 | EVT_SCROLLWIN( self, self.OnScroll ) |
21 | ||
22 | def OnScroll( self, event ): | |
a1bfae9d RD |
23 | #print 'event.GetOrientation()',event.GetOrientation() |
24 | #print 'event.GetPosition()',event.GetPosition() | |
c368d904 | 25 | event.Skip() |
ec3e670f | 26 | |
9c00cfa3 RD |
27 | |
28 | def OnLinkClicked(self, linkinfo): | |
29 | self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref()) | |
ec3e670f | 30 | |
eec92d76 | 31 | # Virtuals in the base class have been renamed with base_ on the front. |
9c00cfa3 RD |
32 | self.base_OnLinkClicked(linkinfo) |
33 | ||
34 | ||
35 | def OnSetTitle(self, title): | |
36 | self.log.WriteText('OnSetTitle: %s\n' % title) | |
37 | self.base_OnSetTitle(title) | |
ec3e670f | 38 | |
0122b7e3 RD |
39 | def OnCellMouseHover(self, cell, x, y): |
40 | self.log.WriteText('OnCellMouseHover: %s, (%d %d)\n' % (cell, x, y)) | |
41 | self.base_OnCellMouseHover(cell, x, y) | |
42 | ||
43 | def OnCellClicked(self, cell, x, y, evt): | |
44 | self.log.WriteText('OnCellClicked: %s, (%d %d)\n' % (cell, x, y)) | |
45 | self.base_OnCellClicked(cell, x, y, evt) | |
ec3e670f RD |
46 | |
47 | ||
1e4a197e RD |
48 | # This filter doesn't really do anything but show how to use filters |
49 | class MyHtmlFilter(wxHtmlFilter): | |
50 | def __init__(self, log): | |
51 | wxHtmlFilter.__init__(self) | |
52 | self.log = log | |
53 | ||
54 | # This method decides if this filter is able to read the file | |
55 | def CanRead(self, fsfile): | |
56 | self.log.write("CanRead: %s\n" % fsfile.GetMimeType()) | |
57 | return False | |
58 | ||
59 | # If CanRead returns True then this method is called to actually | |
60 | # read the file and return the contents. | |
61 | def ReadFile(self, fsfile): | |
62 | return "" | |
63 | ||
64 | ||
ec3e670f RD |
65 | class TestHtmlPanel(wxPanel): |
66 | def __init__(self, parent, frame, log): | |
fe953afb | 67 | wxPanel.__init__(self, parent, -1, style=wxNO_FULL_REPAINT_ON_RESIZE) |
ec3e670f RD |
68 | self.log = log |
69 | self.frame = frame | |
ae920857 RD |
70 | self.cwd = os.path.split(sys.argv[0])[0] |
71 | if not self.cwd: | |
72 | self.cwd = os.getcwd() | |
1e4a197e RD |
73 | if frame: |
74 | self.titleBase = frame.GetTitle() | |
75 | ||
76 | wxHtmlWindow_AddFilter(MyHtmlFilter(log)) | |
ec3e670f | 77 | |
ec3e670f | 78 | self.html = MyHtmlWindow(self, -1, log) |
1e4a197e | 79 | self.html.SetRelatedFrame(frame, self.titleBase + " -- %s") |
ec3e670f RD |
80 | self.html.SetRelatedStatusBar(0) |
81 | ||
65dd82cb RD |
82 | self.printer = wxHtmlEasyPrinting() |
83 | ||
2f90df85 RD |
84 | self.box = wxBoxSizer(wxVERTICAL) |
85 | self.box.Add(self.html, 1, wxGROW) | |
ec3e670f RD |
86 | |
87 | subbox = wxBoxSizer(wxHORIZONTAL) | |
ec3e670f | 88 | |
a1bfae9d RD |
89 | btn = wxButton(self, -1, "Load File") |
90 | EVT_BUTTON(self, btn.GetId(), self.OnLoadFile) | |
2f90df85 | 91 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f | 92 | |
a1bfae9d RD |
93 | btn = wxButton(self, -1, "Load URL") |
94 | EVT_BUTTON(self, btn.GetId(), self.OnLoadURL) | |
2f90df85 | 95 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f | 96 | |
a1bfae9d RD |
97 | btn = wxButton(self, -1, "With Widgets") |
98 | EVT_BUTTON(self, btn.GetId(), self.OnWithWidgets) | |
2f90df85 | 99 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f | 100 | |
a1bfae9d RD |
101 | btn = wxButton(self, -1, "Back") |
102 | EVT_BUTTON(self, btn.GetId(), self.OnBack) | |
2f90df85 | 103 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f | 104 | |
a1bfae9d RD |
105 | btn = wxButton(self, -1, "Forward") |
106 | EVT_BUTTON(self, btn.GetId(), self.OnForward) | |
65dd82cb RD |
107 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
108 | ||
a1bfae9d RD |
109 | btn = wxButton(self, -1, "Print") |
110 | EVT_BUTTON(self, btn.GetId(), self.OnPrint) | |
111 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
112 | ||
113 | btn = wxButton(self, -1, "View Source") | |
114 | EVT_BUTTON(self, btn.GetId(), self.OnViewSource) | |
2f90df85 | 115 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
e166644c | 116 | |
2f90df85 RD |
117 | self.box.Add(subbox, 0, wxGROW) |
118 | self.SetSizer(self.box) | |
1e4a197e | 119 | self.SetAutoLayout(True) |
e166644c RD |
120 | |
121 | # A button with this ID is created on the widget test page. | |
122 | EVT_BUTTON(self, wxID_OK, self.OnOk) | |
123 | ||
ec3e670f RD |
124 | self.OnShowDefault(None) |
125 | ||
126 | ||
1e4a197e RD |
127 | def ShutdownDemo(self): |
128 | # put the frame title back | |
129 | if self.frame: | |
130 | self.frame.SetTitle(self.titleBase) | |
131 | ||
ec3e670f RD |
132 | |
133 | def OnShowDefault(self, event): | |
6c5ae2d2 | 134 | name = os.path.join(self.cwd, opj('data/test.htm')) |
e166644c | 135 | self.html.LoadPage(name) |
ec3e670f RD |
136 | |
137 | ||
138 | def OnLoadFile(self, event): | |
e166644c RD |
139 | dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN) |
140 | if dlg.ShowModal(): | |
141 | path = dlg.GetPath() | |
142 | self.html.LoadPage(path) | |
143 | dlg.Destroy() | |
ec3e670f RD |
144 | |
145 | ||
a1bfae9d RD |
146 | def OnLoadURL(self, event): |
147 | dlg = wxTextEntryDialog(self, "Enter a URL") | |
148 | if dlg.ShowModal(): | |
149 | url = dlg.GetValue() | |
150 | self.html.LoadPage(url) | |
151 | dlg.Destroy() | |
152 | ||
153 | ||
ec3e670f | 154 | def OnWithWidgets(self, event): |
ae920857 | 155 | os.chdir(self.cwd) |
6c5ae2d2 | 156 | name = os.path.join(self.cwd, opj('data/widgetTest.htm')) |
e166644c | 157 | self.html.LoadPage(name) |
ae920857 | 158 | |
e166644c RD |
159 | |
160 | def OnOk(self, event): | |
161 | self.log.WriteText("It works!\n") | |
ec3e670f RD |
162 | |
163 | def OnBack(self, event): | |
164 | if not self.html.HistoryBack(): | |
165 | wxMessageBox("No more items in history!") | |
166 | ||
e166644c | 167 | |
ec3e670f RD |
168 | def OnForward(self, event): |
169 | if not self.html.HistoryForward(): | |
170 | wxMessageBox("No more items in history!") | |
171 | ||
172 | ||
e166644c RD |
173 | def OnViewSource(self, event): |
174 | from wxPython.lib.dialogs import wxScrolledMessageDialog | |
175 | source = self.html.GetParser().GetSource() | |
176 | dlg = wxScrolledMessageDialog(self, source, 'HTML Source') | |
177 | dlg.ShowModal() | |
178 | dlg.Destroy() | |
179 | ||
180 | ||
65dd82cb | 181 | def OnPrint(self, event): |
2f9be787 | 182 | ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100)) |
65dd82cb RD |
183 | self.printer.PrintFile(self.html.GetOpenedPage()) |
184 | ||
ec3e670f RD |
185 | #---------------------------------------------------------------------- |
186 | ||
187 | def runTest(frame, nb, log): | |
188 | win = TestHtmlPanel(nb, frame, log) | |
f9b24f07 | 189 | print wxWindow_FindFocus() |
ec3e670f RD |
190 | return win |
191 | ||
192 | ||
193 | #---------------------------------------------------------------------- | |
194 | ||
195 | ||
196 | ||
197 | ||
198 | ||
1e4a197e RD |
199 | overview = """<html><body> |
200 | <h2>wxHtmlWindow</h2> | |
ec3e670f | 201 | |
1e4a197e RD |
202 | <p>wxHtmlWindow is capable of parsing and rendering most |
203 | simple HTML tags. | |
ec3e670f | 204 | |
1e4a197e RD |
205 | <p>It is not intended to be a high-end HTML browser. If you're |
206 | looking for something like that try http://www.mozilla.org - there's a | |
207 | chance you'll be able to make their widget wxWindows-compatible. I'm | |
208 | sure everyone will enjoy your work in that case... | |
209 | ||
210 | </body></html> | |
ec3e670f RD |
211 | """ |
212 | ||
e166644c RD |
213 | |
214 | ||
1e4a197e RD |
215 | if __name__ == '__main__': |
216 | import sys,os | |
217 | import run | |
218 | run.main(['', os.path.basename(sys.argv[0])]) | |
219 | ||
e166644c RD |
220 | |
221 | ||
e166644c RD |
222 | |
223 | ||
224 | ||
225 | ||
226 |