]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/ActiveX_IEHtmlWindow.py
Need to navigate to "about:blank" in order for the internal docuemnt
[wxWidgets.git] / wxPython / demo / ActiveX_IEHtmlWindow.py
... / ...
CommitLineData
1# 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o Updated for wx namespace
4#
5
6import wx
7
8if wx.Platform == '__WXMSW__':
9 import wx.lib.iewin as iewin
10
11#----------------------------------------------------------------------
12
13class 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.IEHtmlWindow(self, -1, style = wx.NO_FULL_REPAINT_ON_RESIZE)
31
32
33 btn = wx.Button(self, -1, "Open", style=wx.BU_EXACTFIT)
34 self.Bind(wx.EVT_BUTTON, self.OnOpenButton, btn)
35 btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
36
37 btn = wx.Button(self, -1, "Home", style=wx.BU_EXACTFIT)
38 self.Bind(wx.EVT_BUTTON, self.OnHomeButton, btn)
39 btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
40
41 btn = wx.Button(self, -1, "<--", style=wx.BU_EXACTFIT)
42 self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, btn)
43 btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
44
45 btn = wx.Button(self, -1, "-->", style=wx.BU_EXACTFIT)
46 self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, btn)
47 btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
48
49 btn = wx.Button(self, -1, "Stop", style=wx.BU_EXACTFIT)
50 self.Bind(wx.EVT_BUTTON, self.OnStopButton, btn)
51 btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
52
53 btn = wx.Button(self, -1, "Search", style=wx.BU_EXACTFIT)
54 self.Bind(wx.EVT_BUTTON, self.OnSearchPageButton, btn)
55 btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
56
57 btn = wx.Button(self, -1, "Refresh", style=wx.BU_EXACTFIT)
58 self.Bind(wx.EVT_BUTTON, self.OnRefreshPageButton, btn)
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, -1, "", style=wx.CB_DROPDOWN|wx.PROCESS_ENTER
66 )
67
68 self.Bind(wx.EVT_COMBOBOX, self.OnLocationSelect, self.location)
69 self.location.Bind(wx.EVT_KEY_UP, self.OnLocationKey)
70 self.location.Bind(wx.EVT_CHAR, 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.LoadUrl(self.current)
77 self.location.Append(self.current)
78
79 self.SetSizer(sizer)
80 # Since this is a wxWindow we have to call Layout ourselves
81 self.Bind(wx.EVT_SIZE, self.OnSize)
82
83 # Hook up the event handlers for the IE window
84 self.Bind(iewin.EVT_BeforeNavigate2, self.OnBeforeNavigate2, self.ie)
85 self.Bind(iewin.EVT_NewWindow2, self.OnNewWindow2, self.ie)
86 self.Bind(iewin.EVT_DocumentComplete, self.OnDocumentComplete, self.ie)
87 ##self.Bind(iewin.EVT_ProgressChange, self.OnProgressChange, self.ie)
88 self.Bind(iewin.EVT_StatusTextChange, self.OnStatusTextChange, self.ie)
89 self.Bind(iewin.EVT_TitleChange, self.OnTitleChange, self.ie)
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.REFRESH_COMPLETELY)
149
150
151 def logEvt(self, evt):
152 pst = ""
153 for name in evt.paramList:
154 pst += " %s:%s " % (name, repr(getattr(evt, name)))
155 self.log.write('%s: %s\n' % (evt.eventName, pst))
156
157
158 def OnBeforeNavigate2(self, evt):
159 self.logEvt(evt)
160
161 def OnNewWindow2(self, evt):
162 self.logEvt(evt)
163## evt.Veto() # TODO
164
165 def OnProgressChange(self, evt):
166 self.logEvt(evt)
167
168 def OnDocumentComplete(self, evt):
169 self.logEvt(evt)
170 self.current = evt.URL
171 self.location.SetValue(self.current)
172
173 def OnTitleChange(self, evt):
174 self.logEvt(evt)
175 if self.frame:
176 self.frame.SetTitle(self.titleBase + ' -- ' + evt.Text)
177
178 def OnStatusTextChange(self, evt):
179 self.logEvt(evt)
180 if self.frame:
181 self.frame.SetStatusText(evt.Text)
182
183
184#----------------------------------------------------------------------
185# for the demo framework...
186
187def runTest(frame, nb, log):
188 if wx.Platform == '__WXMSW__':
189 win = TestPanel(nb, log, frame)
190 return win
191 else:
192 dlg = wx.MessageDialog(frame, 'This demo only works on Windows.',
193 'Sorry', wx.OK | wx.ICON_INFORMATION)
194 dlg.ShowModal()
195 dlg.Destroy()
196
197
198
199overview = """\
200<html><body>
201<h2>wx.lib.iewin.IEHtmlWindow</h2>
202
203The wx.lib.iewin.IEHtmlWindow class is one example of using ActiveX
204controls from wxPython using the new wx.activex module. This allows
205you to use an ActiveX control as if it is a wx.Window, you can call
206its methods, set/get properties, and receive events from the ActiveX
207control in a very intuitive way.
208
209<p> Using this class is simpler than ActiveXWrapper, doesn't rely on
210the win32all extensions, and is more "wx\'ish", meaning that it uses
211events and etc. as would be expected from any other wx window.
212
213</body></html>
214"""
215
216
217
218if __name__ == '__main__':
219 import sys,os
220 import run
221 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
222
223
224#----------------------------------------------------------------------
225