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