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