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