]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import sys, os | |
3 | ||
4 | from wxPython.wx import * | |
5 | from wxPython.html import * | |
6 | import wxPython.lib.wxpTag | |
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 | 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() | |
22 | ||
23 | ||
24 | def OnLinkClicked(self, linkinfo): | |
25 | self.log.WriteText('OnLinkClicked: %s\n' % linkinfo.GetHref()) | |
26 | ||
27 | # Virtuals in the base class have been renamed with base_ on the front. | |
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) | |
34 | ||
35 | ## def __del__(self): | |
36 | ## print 'MyHtmlWindow.__del__' | |
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 | |
44 | self.cwd = os.path.split(sys.argv[0])[0] | |
45 | if not self.cwd: | |
46 | self.cwd = os.getcwd() | |
47 | ||
48 | self.html = MyHtmlWindow(self, -1, log) | |
49 | self.html.SetRelatedFrame(frame, "wxPython: (A Demonstration) -- %s") | |
50 | self.html.SetRelatedStatusBar(0) | |
51 | ||
52 | self.printer = wxHtmlEasyPrinting() | |
53 | ||
54 | self.box = wxBoxSizer(wxVERTICAL) | |
55 | self.box.Add(self.html, 1, wxGROW) | |
56 | ||
57 | subbox = wxBoxSizer(wxHORIZONTAL) | |
58 | ## btn = wxButton(self, 1201, "Show Default") | |
59 | ## EVT_BUTTON(self, 1201, self.OnShowDefault) | |
60 | ## subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
61 | ||
62 | btn = wxButton(self, 1202, "Load File") | |
63 | EVT_BUTTON(self, 1202, self.OnLoadFile) | |
64 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
65 | ||
66 | btn = wxButton(self, 1203, "With Widgets") | |
67 | EVT_BUTTON(self, 1203, self.OnWithWidgets) | |
68 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
69 | ||
70 | btn = wxButton(self, 1204, "Back") | |
71 | EVT_BUTTON(self, 1204, self.OnBack) | |
72 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
73 | ||
74 | btn = wxButton(self, 1205, "Forward") | |
75 | EVT_BUTTON(self, 1205, self.OnForward) | |
76 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
77 | ||
78 | btn = wxButton(self, 1207, "Print") | |
79 | EVT_BUTTON(self, 1207, self.OnPrint) | |
80 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
81 | ||
82 | btn = wxButton(self, 1206, "View Source") | |
83 | EVT_BUTTON(self, 1206, self.OnViewSource) | |
84 | subbox.Add(btn, 1, wxGROW | wxALL, 2) | |
85 | ||
86 | self.box.Add(subbox, 0, wxGROW) | |
87 | self.SetSizer(self.box) | |
88 | self.SetAutoLayout(true) | |
89 | ||
90 | # A button with this ID is created on the widget test page. | |
91 | EVT_BUTTON(self, wxID_OK, self.OnOk) | |
92 | ||
93 | self.OnShowDefault(None) | |
94 | ||
95 | ||
96 | ## def __del__(self): | |
97 | ## print 'TestHtmlPanel.__del__' | |
98 | ||
99 | ||
100 | ||
101 | def OnShowDefault(self, event): | |
102 | name = os.path.join(self.cwd, 'data/test.htm') | |
103 | self.html.LoadPage(name) | |
104 | ||
105 | ||
106 | def OnLoadFile(self, event): | |
107 | dlg = wxFileDialog(self, wildcard = '*.htm*', style=wxOPEN) | |
108 | if dlg.ShowModal(): | |
109 | path = dlg.GetPath() | |
110 | self.html.LoadPage(path) | |
111 | dlg.Destroy() | |
112 | ||
113 | ||
114 | def OnWithWidgets(self, event): | |
115 | os.chdir(self.cwd) | |
116 | name = os.path.join(self.cwd, 'data/widgetTest.htm') | |
117 | self.html.LoadPage(name) | |
118 | ||
119 | ||
120 | def OnOk(self, event): | |
121 | self.log.WriteText("It works!\n") | |
122 | ||
123 | def OnBack(self, event): | |
124 | if not self.html.HistoryBack(): | |
125 | wxMessageBox("No more items in history!") | |
126 | ||
127 | ||
128 | def OnForward(self, event): | |
129 | if not self.html.HistoryForward(): | |
130 | wxMessageBox("No more items in history!") | |
131 | ||
132 | ||
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 | ||
141 | def OnPrint(self, event): | |
142 | self.printer.PrintFile(self.html.GetOpenedPage()) | |
143 | ||
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 | ||
164 | ||
165 | ||
166 | ||
167 | ||
168 | ||
169 | ||
170 | ||
171 | ||
172 |