]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/IEHtmlWin.py
Script updates
[wxWidgets.git] / wxPython / demo / IEHtmlWin.py
CommitLineData
8fa876ca
RD
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#
c731eb47 9
8fa876ca 10import wx
c731eb47 11
8fa876ca
RD
12if wx.Platform == '__WXMSW__':
13 import wx.iewin as iewin
c731eb47
RD
14
15#----------------------------------------------------------------------
16
8fa876ca 17class TestPanel(wx.Window):
c731eb47 18 def __init__(self, parent, log, frame=None):
8fa876ca
RD
19 wx.Window.__init__(
20 self, parent, -1,
21 style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE
22 )
23
c731eb47 24 self.log = log
8fa876ca 25 self.current = "http://wxPython.org/"
c731eb47 26 self.frame = frame
8fa876ca 27
c731eb47
RD
28 if frame:
29 self.titleBase = frame.GetTitle()
30
8fa876ca
RD
31 sizer = wx.BoxSizer(wx.VERTICAL)
32 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
c731eb47 33
8fa876ca 34 self.ie = iewin.IEHtmlWin(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
c731eb47 35
c731eb47 36
8fa876ca
RD
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)
c731eb47 40
8fa876ca
RD
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)
c731eb47 44
8fa876ca
RD
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)
c731eb47 48
8fa876ca
RD
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)
c731eb47 52
8fa876ca
RD
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)
c731eb47 56
8fa876ca
RD
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)
c731eb47 60
8fa876ca
RD
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)
c731eb47 64
8fa876ca
RD
65 txt = wx.StaticText(self, -1, "Location:")
66 btnSizer.Add(txt, 0, wx.CENTER|wx.ALL, 2)
c731eb47 67
8fa876ca
RD
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)
63b6646e 76
8fa876ca
RD
77 sizer.Add(btnSizer, 0, wx.EXPAND)
78 sizer.Add(self.ie, 1, wx.EXPAND)
c731eb47 79
63b6646e 80 self.ie.Navigate(self.current)
c731eb47
RD
81 self.location.Append(self.current)
82
83 self.SetSizer(sizer)
1e4a197e 84 self.SetAutoLayout(True)
8fa876ca 85 wx.EVT_SIZE(self, self.OnSize)
c731eb47
RD
86
87 # Hook up the event handlers for the IE window
8fa876ca
RD
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)
c731eb47 91 #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange)
8fa876ca
RD
92 iewin.EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange)
93 iewin.EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange)
c731eb47
RD
94
95
1e4a197e
RD
96 def ShutdownDemo(self):
97 # put the frame title back
98 if self.frame:
99 self.frame.SetTitle(self.titleBase)
100
101
c731eb47
RD
102 def OnSize(self, evt):
103 self.Layout()
104
63b6646e 105
c731eb47
RD
106 def OnLocationSelect(self, evt):
107 url = self.location.GetStringSelection()
108 self.log.write('OnLocationSelect: %s\n' % url)
63b6646e 109 self.ie.Navigate(url)
c731eb47
RD
110
111 def OnLocationKey(self, evt):
8fa876ca 112 if evt.KeyCode() == wx.WXK_RETURN:
c731eb47
RD
113 URL = self.location.GetValue()
114 self.location.Append(URL)
63b6646e 115 self.ie.Navigate(URL)
c731eb47
RD
116 else:
117 evt.Skip()
118
63b6646e 119
c731eb47 120 def IgnoreReturn(self, evt):
8fa876ca 121 if evt.GetKeyCode() != wx.WXK_RETURN:
c731eb47
RD
122 evt.Skip()
123
124 def OnOpenButton(self, event):
8fa876ca 125 dlg = wx.TextEntryDialog(self, "Open Location",
c731eb47 126 "Enter a full URL or local path",
8fa876ca 127 self.current, wx.OK|wx.CANCEL)
c731eb47 128 dlg.CentreOnParent()
8fa876ca
RD
129
130 if dlg.ShowModal() == wx.ID_OK:
c731eb47 131 self.current = dlg.GetValue()
63b6646e 132 self.ie.Navigate(self.current)
8fa876ca 133
c731eb47
RD
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):
8fa876ca 152 self.ie.Refresh(iewin.IEHTML_REFRESH_COMPLETELY)
c731eb47
RD
153
154
155 def logEvt(self, name, event):
156 self.log.write('%s: %s\n' %
63b6646e 157 (name, (event.GetLong1(), event.GetLong2(), event.GetText1())))
c731eb47
RD
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)
63b6646e 168 self.current = evt.GetText1()
c731eb47
RD
169 self.location.SetValue(self.current)
170
171 def OnTitleChange(self, evt):
172 self.logEvt('OnTitleChange', evt)
173 if self.frame:
63b6646e 174 self.frame.SetTitle(self.titleBase + ' -- ' + evt.GetText1())
c731eb47
RD
175
176 def OnStatusTextChange(self, evt):
177 self.logEvt('OnStatusTextChange', evt)
178 if self.frame:
63b6646e 179 self.frame.SetStatusText(evt.GetText1())
c731eb47
RD
180
181
182#----------------------------------------------------------------------
183# for the demo framework...
184
185def runTest(frame, nb, log):
8fa876ca 186 if wx.Platform == '__WXMSW__':
c731eb47
RD
187 win = TestPanel(nb, log, frame)
188 return win
189 else:
8fa876ca
RD
190 dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
191 'Sorry', wx.OK | wx.ICON_INFORMATION)
c731eb47
RD
192 dlg.ShowModal()
193 dlg.Destroy()
194
195
196
197overview = """\
198<html><body>
95bfd958 199<h2>wx.IEHtmlWin</h2>
c731eb47 200
95bfd958 201The wx.IEHtmlWin class is the first example of using a contributed
c731eb47
RD
202wxActiveX class in wxWindows C++. It is still experimental, but
203I think it is useful.
204
205<p> Using this class is simpler than ActiveXWrapper, doesn't rely on
206the win32all extensions, and is more "wx\'ish", meaning that it uses
207events and etc. as would be expected from any other wx window.
208
209</body></html>
210"""
211
212
213
214if __name__ == '__main__':
215 import sys,os
216 import run
217 run.main(['', os.path.basename(sys.argv[0])])
218
219
220#----------------------------------------------------------------------
221