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