]>
Commit | Line | Data |
---|---|---|
c731eb47 RD |
1 | |
2 | from wxPython.wx import * | |
3 | ||
4 | if wxPlatform == '__WXMSW__': | |
5 | from wxPython.iewin import * | |
6 | ||
7 | #---------------------------------------------------------------------- | |
8 | ||
9 | class TestPanel(wxWindow): | |
10 | def __init__(self, parent, log, frame=None): | |
11 | wxWindow.__init__(self, parent, -1, style=wxCLIP_CHILDREN) | |
12 | self.log = log | |
13 | self.current = "http://wxPython.org/" | |
14 | self.frame = frame | |
15 | if frame: | |
16 | self.titleBase = frame.GetTitle() | |
17 | ||
18 | ||
19 | sizer = wxBoxSizer(wxVERTICAL) | |
20 | btnSizer = wxBoxSizer(wxHORIZONTAL) | |
21 | ||
22 | self.ie = wxIEHtmlWin(self, -1) ##, style=wxSUNKEN_BORDER) | |
23 | ||
24 | ||
25 | btn = wxButton(self, wxNewId(), "Open", style=wxBU_EXACTFIT) | |
26 | EVT_BUTTON(self, btn.GetId(), self.OnOpenButton) | |
27 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
28 | ||
29 | btn = wxButton(self, wxNewId(), "Home", style=wxBU_EXACTFIT) | |
30 | EVT_BUTTON(self, btn.GetId(), self.OnHomeButton) | |
31 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
32 | ||
33 | btn = wxButton(self, wxNewId(), "<--", style=wxBU_EXACTFIT) | |
34 | EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton) | |
35 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
36 | ||
37 | btn = wxButton(self, wxNewId(), "-->", style=wxBU_EXACTFIT) | |
38 | EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton) | |
39 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
40 | ||
41 | btn = wxButton(self, wxNewId(), "Stop", style=wxBU_EXACTFIT) | |
42 | EVT_BUTTON(self, btn.GetId(), self.OnStopButton) | |
43 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
44 | ||
45 | btn = wxButton(self, wxNewId(), "Search", style=wxBU_EXACTFIT) | |
46 | EVT_BUTTON(self, btn.GetId(), self.OnSearchPageButton) | |
47 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
48 | ||
49 | btn = wxButton(self, wxNewId(), "Refresh", style=wxBU_EXACTFIT) | |
50 | EVT_BUTTON(self, btn.GetId(), self.OnRefreshPageButton) | |
51 | btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2) | |
52 | ||
53 | txt = wxStaticText(self, -1, "Location:") | |
54 | btnSizer.Add(txt, 0, wxCENTER|wxALL, 2) | |
55 | ||
56 | self.location = wxComboBox(self, wxNewId(), "", style=wxCB_DROPDOWN) | |
57 | EVT_COMBOBOX(self, self.location.GetId(), self.OnLocationSelect) | |
58 | EVT_KEY_UP(self.location, self.OnLocationKey) | |
59 | EVT_CHAR(self.location, self.IgnoreReturn) | |
60 | btnSizer.Add(self.location, 1, wxEXPAND|wxALL, 2) | |
61 | ||
62 | sizer.Add(btnSizer, 0, wxEXPAND) | |
63 | sizer.Add(self.ie, 1, wxEXPAND) | |
64 | ||
65 | self.ie.LoadUrl(self.current) | |
66 | self.location.Append(self.current) | |
67 | ||
68 | self.SetSizer(sizer) | |
69 | self.SetAutoLayout(true) | |
70 | EVT_SIZE(self, self.OnSize) | |
71 | ||
72 | # Hook up the event handlers for the IE window | |
73 | EVT_MSHTML_BEFORENAVIGATE2(self, -1, self.OnBeforeNavigate2) | |
74 | EVT_MSHTML_NEWWINDOW2(self, -1, self.OnNewWindow2) | |
75 | EVT_MSHTML_DOCUMENTCOMPLETE(self, -1, self.OnDocumentComplete) | |
76 | #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange) | |
77 | EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange) | |
78 | EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange) | |
79 | ||
80 | ||
81 | def OnSize(self, evt): | |
82 | self.Layout() | |
83 | ||
84 | def OnLocationSelect(self, evt): | |
85 | url = self.location.GetStringSelection() | |
86 | self.log.write('OnLocationSelect: %s\n' % url) | |
87 | self.ie.LoadUrl(url) | |
88 | ||
89 | def OnLocationKey(self, evt): | |
90 | if evt.KeyCode() == WXK_RETURN: | |
91 | URL = self.location.GetValue() | |
92 | self.location.Append(URL) | |
93 | self.ie.LoadUrl(URL) | |
94 | else: | |
95 | evt.Skip() | |
96 | ||
97 | def IgnoreReturn(self, evt): | |
98 | print 'IgnoreReturn' | |
99 | if evt.KeyCode() != WXK_RETURN: | |
100 | evt.Skip() | |
101 | ||
102 | def OnOpenButton(self, event): | |
103 | dlg = wxTextEntryDialog(self, "Open Location", | |
104 | "Enter a full URL or local path", | |
105 | self.current, wxOK|wxCANCEL) | |
106 | dlg.CentreOnParent() | |
107 | if dlg.ShowModal() == wxID_OK: | |
108 | self.current = dlg.GetValue() | |
109 | self.ie.LoadUrl(self.current) | |
110 | dlg.Destroy() | |
111 | ||
112 | def OnHomeButton(self, event): | |
113 | self.ie.GoHome() ## ET Phone Home! | |
114 | ||
115 | def OnPrevPageButton(self, event): | |
116 | self.ie.GoBack() | |
117 | ||
118 | def OnNextPageButton(self, event): | |
119 | self.ie.GoForward() | |
120 | ||
121 | def OnStopButton(self, evt): | |
122 | self.ie.Stop() | |
123 | ||
124 | def OnSearchPageButton(self, evt): | |
125 | self.ie.GoSearch() | |
126 | ||
127 | def OnRefreshPageButton(self, evt): | |
128 | self.ie.Refresh(wxIEHTML_REFRESH_COMPLETELY) | |
129 | ||
130 | ||
131 | ||
132 | def logEvt(self, name, event): | |
133 | self.log.write('%s: %s\n' % | |
134 | (name, (event.GetLong1(), event.GetLong2(), event.GetText()))) | |
135 | ||
136 | def OnBeforeNavigate2(self, evt): | |
137 | self.logEvt('OnBeforeNavigate2', evt) | |
138 | ||
139 | def OnNewWindow2(self, evt): | |
140 | self.logEvt('OnNewWindow2', evt) | |
141 | evt.Veto() # don't allow it | |
142 | ||
143 | def OnDocumentComplete(self, evt): | |
144 | self.logEvt('OnDocumentComplete', evt) | |
145 | self.current = evt.GetText() | |
146 | self.location.SetValue(self.current) | |
147 | ||
148 | def OnTitleChange(self, evt): | |
149 | self.logEvt('OnTitleChange', evt) | |
150 | if self.frame: | |
151 | self.frame.SetTitle(self.titleBase + ' -- ' + evt.GetText()) | |
152 | ||
153 | def OnStatusTextChange(self, evt): | |
154 | self.logEvt('OnStatusTextChange', evt) | |
155 | if self.frame: | |
156 | self.frame.SetStatusText(evt.GetText()) | |
157 | ||
158 | ||
159 | #---------------------------------------------------------------------- | |
160 | # for the demo framework... | |
161 | ||
162 | def runTest(frame, nb, log): | |
163 | if wxPlatform == '__WXMSW__': | |
164 | win = TestPanel(nb, log, frame) | |
165 | return win | |
166 | else: | |
167 | dlg = wxMessageDialog(frame, 'This demo only works on MSW.', | |
168 | 'Sorry', wxOK | wxICON_INFORMATION) | |
169 | dlg.ShowModal() | |
170 | dlg.Destroy() | |
171 | ||
172 | ||
173 | ||
174 | overview = """\ | |
175 | <html><body> | |
176 | <h2>wxIEHtmlWin</h2> | |
177 | ||
178 | The wxIEHtmlWin class is the first example of using a contributed | |
179 | wxActiveX class in wxWindows C++. It is still experimental, but | |
180 | I think it is useful. | |
181 | ||
182 | <p> Using this class is simpler than ActiveXWrapper, doesn't rely on | |
183 | the win32all extensions, and is more "wx\'ish", meaning that it uses | |
184 | events and etc. as would be expected from any other wx window. | |
185 | ||
186 | </body></html> | |
187 | """ | |
188 | ||
189 | ||
190 | ||
191 | if __name__ == '__main__': | |
192 | import sys,os | |
193 | import run | |
194 | run.main(['', os.path.basename(sys.argv[0])]) | |
195 | ||
196 | ||
197 | #---------------------------------------------------------------------- | |
198 |