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