]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # | |
c731eb47 | 5 | |
8fa876ca | 6 | import wx |
c731eb47 | 7 | |
8fa876ca RD |
8 | if wx.Platform == '__WXMSW__': |
9 | import wx.iewin as iewin | |
c731eb47 RD |
10 | |
11 | #---------------------------------------------------------------------- | |
12 | ||
8fa876ca | 13 | class TestPanel(wx.Window): |
c731eb47 | 14 | def __init__(self, parent, log, frame=None): |
8fa876ca RD |
15 | wx.Window.__init__( |
16 | self, parent, -1, | |
17 | style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE | |
18 | ) | |
19 | ||
c731eb47 | 20 | self.log = log |
8fa876ca | 21 | self.current = "http://wxPython.org/" |
c731eb47 | 22 | self.frame = frame |
8fa876ca | 23 | |
c731eb47 RD |
24 | if frame: |
25 | self.titleBase = frame.GetTitle() | |
26 | ||
8fa876ca RD |
27 | sizer = wx.BoxSizer(wx.VERTICAL) |
28 | btnSizer = wx.BoxSizer(wx.HORIZONTAL) | |
c731eb47 | 29 | |
8fa876ca | 30 | self.ie = iewin.IEHtmlWin(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE) |
c731eb47 | 31 | |
c731eb47 | 32 | |
8fa876ca RD |
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) | |
c731eb47 | 36 | |
8fa876ca RD |
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) | |
c731eb47 | 40 | |
8fa876ca RD |
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) | |
c731eb47 | 44 | |
8fa876ca RD |
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) | |
c731eb47 | 48 | |
8fa876ca RD |
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) | |
c731eb47 | 52 | |
8fa876ca RD |
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) | |
c731eb47 | 56 | |
8fa876ca RD |
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) | |
c731eb47 | 60 | |
8fa876ca RD |
61 | txt = wx.StaticText(self, -1, "Location:") |
62 | btnSizer.Add(txt, 0, wx.CENTER|wx.ALL, 2) | |
c731eb47 | 63 | |
8fa876ca RD |
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) | |
63b6646e | 72 | |
8fa876ca RD |
73 | sizer.Add(btnSizer, 0, wx.EXPAND) |
74 | sizer.Add(self.ie, 1, wx.EXPAND) | |
c731eb47 | 75 | |
63b6646e | 76 | self.ie.Navigate(self.current) |
c731eb47 RD |
77 | self.location.Append(self.current) |
78 | ||
79 | self.SetSizer(sizer) | |
1e4a197e | 80 | self.SetAutoLayout(True) |
8fa876ca | 81 | wx.EVT_SIZE(self, self.OnSize) |
c731eb47 RD |
82 | |
83 | # Hook up the event handlers for the IE window | |
8fa876ca RD |
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) | |
c731eb47 | 87 | #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange) |
8fa876ca RD |
88 | iewin.EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange) |
89 | iewin.EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange) | |
c731eb47 RD |
90 | |
91 | ||
1e4a197e RD |
92 | def ShutdownDemo(self): |
93 | # put the frame title back | |
94 | if self.frame: | |
95 | self.frame.SetTitle(self.titleBase) | |
96 | ||
97 | ||
c731eb47 RD |
98 | def OnSize(self, evt): |
99 | self.Layout() | |
100 | ||
63b6646e | 101 | |
c731eb47 RD |
102 | def OnLocationSelect(self, evt): |
103 | url = self.location.GetStringSelection() | |
104 | self.log.write('OnLocationSelect: %s\n' % url) | |
63b6646e | 105 | self.ie.Navigate(url) |
c731eb47 RD |
106 | |
107 | def OnLocationKey(self, evt): | |
8fa876ca | 108 | if evt.KeyCode() == wx.WXK_RETURN: |
c731eb47 RD |
109 | URL = self.location.GetValue() |
110 | self.location.Append(URL) | |
63b6646e | 111 | self.ie.Navigate(URL) |
c731eb47 RD |
112 | else: |
113 | evt.Skip() | |
114 | ||
63b6646e | 115 | |
c731eb47 | 116 | def IgnoreReturn(self, evt): |
8fa876ca | 117 | if evt.GetKeyCode() != wx.WXK_RETURN: |
c731eb47 RD |
118 | evt.Skip() |
119 | ||
120 | def OnOpenButton(self, event): | |
8fa876ca | 121 | dlg = wx.TextEntryDialog(self, "Open Location", |
c731eb47 | 122 | "Enter a full URL or local path", |
8fa876ca | 123 | self.current, wx.OK|wx.CANCEL) |
c731eb47 | 124 | dlg.CentreOnParent() |
8fa876ca RD |
125 | |
126 | if dlg.ShowModal() == wx.ID_OK: | |
c731eb47 | 127 | self.current = dlg.GetValue() |
63b6646e | 128 | self.ie.Navigate(self.current) |
8fa876ca | 129 | |
c731eb47 RD |
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): | |
8fa876ca | 148 | self.ie.Refresh(iewin.IEHTML_REFRESH_COMPLETELY) |
c731eb47 RD |
149 | |
150 | ||
151 | def logEvt(self, name, event): | |
152 | self.log.write('%s: %s\n' % | |
63b6646e | 153 | (name, (event.GetLong1(), event.GetLong2(), event.GetText1()))) |
c731eb47 RD |
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) | |
63b6646e | 164 | self.current = evt.GetText1() |
c731eb47 RD |
165 | self.location.SetValue(self.current) |
166 | ||
167 | def OnTitleChange(self, evt): | |
168 | self.logEvt('OnTitleChange', evt) | |
169 | if self.frame: | |
63b6646e | 170 | self.frame.SetTitle(self.titleBase + ' -- ' + evt.GetText1()) |
c731eb47 RD |
171 | |
172 | def OnStatusTextChange(self, evt): | |
173 | self.logEvt('OnStatusTextChange', evt) | |
174 | if self.frame: | |
63b6646e | 175 | self.frame.SetStatusText(evt.GetText1()) |
c731eb47 RD |
176 | |
177 | ||
178 | #---------------------------------------------------------------------- | |
179 | # for the demo framework... | |
180 | ||
181 | def runTest(frame, nb, log): | |
8fa876ca | 182 | if wx.Platform == '__WXMSW__': |
c731eb47 RD |
183 | win = TestPanel(nb, log, frame) |
184 | return win | |
185 | else: | |
21b227f2 | 186 | dlg = wx.MessageDialog(frame, 'This demo only works on Windows.', |
8fa876ca | 187 | 'Sorry', wx.OK | wx.ICON_INFORMATION) |
c731eb47 RD |
188 | dlg.ShowModal() |
189 | dlg.Destroy() | |
190 | ||
191 | ||
192 | ||
193 | overview = """\ | |
194 | <html><body> | |
95bfd958 | 195 | <h2>wx.IEHtmlWin</h2> |
c731eb47 | 196 | |
95bfd958 | 197 | The wx.IEHtmlWin class is the first example of using a contributed |
c731eb47 RD |
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 | |
8eca4fef | 213 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) |
c731eb47 RD |
214 | |
215 | ||
216 | #---------------------------------------------------------------------- | |
217 |