]>
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 | |
c368d904 RD |
16 | EVT_SCROLLWIN( self, self.OnScroll ) |
17 | ||
18 | def OnScroll( self, event ): | |
19 | print 'event.GetOrientation()',event.GetOrientation() | |
20 | print 'event.GetPosition()',event.GetPosition() | |
21 | event.Skip() | |
ec3e670f | 22 | |
9c00cfa3 RD |
23 | |
24 | def OnLinkClicked(self, linkinfo): | |
25 | self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref()) | |
ec3e670f | 26 | |
eec92d76 | 27 | # Virtuals in the base class have been renamed with base_ on the front. |
9c00cfa3 RD |
28 | self.base_OnLinkClicked(linkinfo) |
29 | ||
30 | ||
31 | def OnSetTitle(self, title): | |
32 | self.log.WriteText('OnSetTitle: %s\n' % title) | |
33 | self.base_OnSetTitle(title) | |
ec3e670f | 34 | |
0122b7e3 RD |
35 | def OnCellMouseHover(self, cell, x, y): |
36 | self.log.WriteText('OnCellMouseHover: %s, (%d %d)\n' % (cell, x, y)) | |
37 | self.base_OnCellMouseHover(cell, x, y) | |
38 | ||
39 | def OnCellClicked(self, cell, x, y, evt): | |
40 | self.log.WriteText('OnCellClicked: %s, (%d %d)\n' % (cell, x, y)) | |
41 | self.base_OnCellClicked(cell, x, y, evt) | |
ec3e670f RD |
42 | |
43 | ||
44 | class TestHtmlPanel(wxPanel): | |
45 | def __init__(self, parent, frame, log): | |
46 | wxPanel.__init__(self, parent, -1) | |
47 | self.log = log | |
48 | self.frame = frame | |
ae920857 RD |
49 | self.cwd = os.path.split(sys.argv[0])[0] |
50 | if not self.cwd: | |
51 | self.cwd = os.getcwd() | |
ec3e670f | 52 | |
ec3e670f RD |
53 | self.html = MyHtmlWindow(self, -1, log) |
54 | self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s") | |
55 | self.html.SetRelatedStatusBar(0) | |
56 | ||
65dd82cb RD |
57 | self.printer = wxHtmlEasyPrinting() |
58 | ||
2f90df85 RD |
59 | self.box = wxBoxSizer(wxVERTICAL) |
60 | self.box.Add(self.html, 1, wxGROW) | |
ec3e670f RD |
61 | |
62 | subbox = wxBoxSizer(wxHORIZONTAL) | |
854862f5 RD |
63 | ## btn = wxButton(self, 1201, "Show Default") |
64 | ## EVT_BUTTON(self, 1201, self.OnShowDefault) | |
65 | ## subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
ec3e670f RD |
66 | |
67 | btn = wxButton(self, 1202, "Load File") | |
68 | EVT_BUTTON(self, 1202, self.OnLoadFile) | |
2f90df85 | 69 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
70 | |
71 | btn = wxButton(self, 1203, "With Widgets") | |
72 | EVT_BUTTON(self, 1203, self.OnWithWidgets) | |
2f90df85 | 73 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
74 | |
75 | btn = wxButton(self, 1204, "Back") | |
76 | EVT_BUTTON(self, 1204, self.OnBack) | |
2f90df85 | 77 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f RD |
78 | |
79 | btn = wxButton(self, 1205, "Forward") | |
80 | EVT_BUTTON(self, 1205, self.OnForward) | |
2f90df85 | 81 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
ec3e670f | 82 | |
65dd82cb RD |
83 | btn = wxButton(self, 1207, "Print") |
84 | EVT_BUTTON(self, 1207, self.OnPrint) | |
85 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
86 | ||
e166644c RD |
87 | btn = wxButton(self, 1206, "View Source") |
88 | EVT_BUTTON(self, 1206, self.OnViewSource) | |
2f90df85 | 89 | subbox.Add(btn, 1, wxGROW | wxALL, 2) |
e166644c | 90 | |
2f90df85 RD |
91 | self.box.Add(subbox, 0, wxGROW) |
92 | self.SetSizer(self.box) | |
93 | self.SetAutoLayout(true) | |
e166644c RD |
94 | |
95 | # A button with this ID is created on the widget test page. | |
96 | EVT_BUTTON(self, wxID_OK, self.OnOk) | |
97 | ||
ec3e670f RD |
98 | self.OnShowDefault(None) |
99 | ||
100 | ||
854862f5 RD |
101 | ## def __del__(self): |
102 | ## print 'TestHtmlPanel.__del__' | |
eec92d76 | 103 | |
e166644c | 104 | |
ec3e670f RD |
105 | |
106 | def OnShowDefault(self, event): | |
ae920857 | 107 | name = os.path.join(self.cwd, 'data/test.htm') |
e166644c | 108 | self.html.LoadPage(name) |
ec3e670f RD |
109 | |
110 | ||
111 | def OnLoadFile(self, event): | |
e166644c RD |
112 | dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN) |
113 | if dlg.ShowModal(): | |
114 | path = dlg.GetPath() | |
115 | self.html.LoadPage(path) | |
116 | dlg.Destroy() | |
ec3e670f RD |
117 | |
118 | ||
119 | def OnWithWidgets(self, event): | |
ae920857 RD |
120 | os.chdir(self.cwd) |
121 | name = os.path.join(self.cwd, 'data/widgetTest.htm') | |
e166644c | 122 | self.html.LoadPage(name) |
ae920857 | 123 | |
e166644c RD |
124 | |
125 | def OnOk(self, event): | |
126 | self.log.WriteText("It works!\n") | |
ec3e670f RD |
127 | |
128 | def OnBack(self, event): | |
129 | if not self.html.HistoryBack(): | |
130 | wxMessageBox("No more items in history!") | |
131 | ||
e166644c | 132 | |
ec3e670f RD |
133 | def OnForward(self, event): |
134 | if not self.html.HistoryForward(): | |
135 | wxMessageBox("No more items in history!") | |
136 | ||
137 | ||
e166644c RD |
138 | def OnViewSource(self, event): |
139 | from wxPython.lib.dialogs import wxScrolledMessageDialog | |
140 | source = self.html.GetParser().GetSource() | |
141 | dlg = wxScrolledMessageDialog(self, source, 'HTML Source') | |
142 | dlg.ShowModal() | |
143 | dlg.Destroy() | |
144 | ||
145 | ||
65dd82cb | 146 | def OnPrint(self, event): |
2f9be787 | 147 | ##self.printer.GetPageSetupData().SetMarginTopLeft((100,100)) |
65dd82cb RD |
148 | self.printer.PrintFile(self.html.GetOpenedPage()) |
149 | ||
ec3e670f RD |
150 | #---------------------------------------------------------------------- |
151 | ||
152 | def runTest(frame, nb, log): | |
153 | win = TestHtmlPanel(nb, frame, log) | |
154 | return win | |
155 | ||
156 | ||
157 | #---------------------------------------------------------------------- | |
158 | ||
159 | ||
160 | ||
161 | ||
162 | ||
163 | overview = """\ | |
164 | wxHtmlWindow is capable of parsing and rendering most simple HTML tags. | |
165 | ||
166 | 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... | |
167 | ||
168 | """ | |
169 | ||
e166644c RD |
170 | |
171 | ||
172 | ||
173 | ||
e166644c RD |
174 | |
175 | ||
176 | ||
177 | ||
178 |