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