]>
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 | ||
57 | self.location = wxComboBox(self, wxNewId(), "", style=wxCB_DROPDOWN) | |
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 | ||
63 | sizer.Add(btnSizer, 0, wxEXPAND) | |
64 | sizer.Add(self.ie, 1, wxEXPAND) | |
65 | ||
66 | self.ie.LoadUrl(self.current) | |
67 | self.location.Append(self.current) | |
68 | ||
69 | self.SetSizer(sizer) | |
70 | self.SetAutoLayout(true) | |
71 | EVT_SIZE(self, self.OnSize) | |
72 | ||
73 | # Hook up the event handlers for the IE window | |
74 | EVT_MSHTML_BEFORENAVIGATE2(self, -1, self.OnBeforeNavigate2) | |
75 | EVT_MSHTML_NEWWINDOW2(self, -1, self.OnNewWindow2) | |
76 | EVT_MSHTML_DOCUMENTCOMPLETE(self, -1, self.OnDocumentComplete) | |
77 | #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange) | |
78 | EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange) | |
79 | EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange) | |
80 | ||
81 | ||
82 | def OnSize(self, evt): | |
83 | self.Layout() | |
84 | ||
85 | def OnLocationSelect(self, evt): | |
86 | url = self.location.GetStringSelection() | |
87 | self.log.write('OnLocationSelect: %s\n' % url) | |
88 | self.ie.LoadUrl(url) | |
89 | ||
90 | def OnLocationKey(self, evt): | |
91 | if evt.KeyCode() == WXK_RETURN: | |
92 | URL = self.location.GetValue() | |
93 | self.location.Append(URL) | |
94 | self.ie.LoadUrl(URL) | |
95 | else: | |
96 | evt.Skip() | |
97 | ||
98 | def IgnoreReturn(self, evt): | |
99 | print 'IgnoreReturn' | |
100 | if evt.KeyCode() != WXK_RETURN: | |
101 | evt.Skip() | |
102 | ||
103 | def OnOpenButton(self, event): | |
104 | dlg = wxTextEntryDialog(self, "Open Location", | |
105 | "Enter a full URL or local path", | |
106 | self.current, wxOK|wxCANCEL) | |
107 | dlg.CentreOnParent() | |
108 | if dlg.ShowModal() == wxID_OK: | |
109 | self.current = dlg.GetValue() | |
110 | self.ie.LoadUrl(self.current) | |
111 | dlg.Destroy() | |
112 | ||
113 | def OnHomeButton(self, event): | |
114 | self.ie.GoHome() ## ET Phone Home! | |
115 | ||
116 | def OnPrevPageButton(self, event): | |
117 | self.ie.GoBack() | |
118 | ||
119 | def OnNextPageButton(self, event): | |
120 | self.ie.GoForward() | |
121 | ||
122 | def OnStopButton(self, evt): | |
123 | self.ie.Stop() | |
124 | ||
125 | def OnSearchPageButton(self, evt): | |
126 | self.ie.GoSearch() | |
127 | ||
128 | def OnRefreshPageButton(self, evt): | |
129 | self.ie.Refresh(wxIEHTML_REFRESH_COMPLETELY) | |
130 | ||
131 | ||
132 | ||
133 | def logEvt(self, name, event): | |
134 | self.log.write('%s: %s\n' % | |
135 | (name, (event.GetLong1(), event.GetLong2(), event.GetText()))) | |
136 | ||
137 | def OnBeforeNavigate2(self, evt): | |
138 | self.logEvt('OnBeforeNavigate2', evt) | |
139 | ||
140 | def OnNewWindow2(self, evt): | |
141 | self.logEvt('OnNewWindow2', evt) | |
142 | evt.Veto() # don't allow it | |
143 | ||
144 | def OnDocumentComplete(self, evt): | |
145 | self.logEvt('OnDocumentComplete', evt) | |
146 | self.current = evt.GetText() | |
147 | self.location.SetValue(self.current) | |
148 | ||
149 | def OnTitleChange(self, evt): | |
150 | self.logEvt('OnTitleChange', evt) | |
151 | if self.frame: | |
152 | self.frame.SetTitle(self.titleBase + ' -- ' + evt.GetText()) | |
153 | ||
154 | def OnStatusTextChange(self, evt): | |
155 | self.logEvt('OnStatusTextChange', evt) | |
156 | if self.frame: | |
157 | self.frame.SetStatusText(evt.GetText()) | |
158 | ||
159 | ||
160 | #---------------------------------------------------------------------- | |
161 | # for the demo framework... | |
162 | ||
163 | def runTest(frame, nb, log): | |
164 | if wxPlatform == '__WXMSW__': | |
165 | win = TestPanel(nb, log, frame) | |
166 | return win | |
167 | else: | |
168 | dlg = wxMessageDialog(frame, 'This demo only works on MSW.', | |
169 | 'Sorry', wxOK | wxICON_INFORMATION) | |
170 | dlg.ShowModal() | |
171 | dlg.Destroy() | |
172 | ||
173 | ||
174 | ||
175 | overview = """\ | |
176 | <html><body> | |
177 | <h2>wxIEHtmlWin</h2> | |
178 | ||
179 | The wxIEHtmlWin class is the first example of using a contributed | |
180 | wxActiveX class in wxWindows C++. It is still experimental, but | |
181 | I think it is useful. | |
182 | ||
183 | <p> Using this class is simpler than ActiveXWrapper, doesn't rely on | |
184 | the win32all extensions, and is more "wx\'ish", meaning that it uses | |
185 | events and etc. as would be expected from any other wx window. | |
186 | ||
187 | </body></html> | |
188 | """ | |
189 | ||
190 | ||
191 | ||
192 | if __name__ == '__main__': | |
193 | import sys,os | |
194 | import run | |
195 | run.main(['', os.path.basename(sys.argv[0])]) | |
196 | ||
197 | ||
198 | #---------------------------------------------------------------------- | |
199 |