]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ActiveX_IEHtmlWindow.py
Warning fixes and source cleaning.
[wxWidgets.git] / wxPython / demo / ActiveX_IEHtmlWindow.py
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.lib.iewin as iewin
10
11 #----------------------------------------------------------------------
12
13 class TestPanel(wx.Panel):
14 def __init__(self, parent, log, frame=None):
15 wx.Panel.__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.GetKeyCode() == 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 # Veto the new window. Cancel is defined as an "out" param
164 # for this event. See iewin.py
165 evt.Cancel = True
166
167 def OnProgressChange(self, evt):
168 self.logEvt(evt)
169
170 def OnDocumentComplete(self, evt):
171 self.logEvt(evt)
172 self.current = evt.URL
173 self.location.SetValue(self.current)
174
175 def OnTitleChange(self, evt):
176 self.logEvt(evt)
177 if self.frame:
178 self.frame.SetTitle(self.titleBase + ' -- ' + evt.Text)
179
180 def OnStatusTextChange(self, evt):
181 self.logEvt(evt)
182 if self.frame:
183 self.frame.SetStatusText(evt.Text)
184
185
186 #----------------------------------------------------------------------
187 # for the demo framework...
188
189 def runTest(frame, nb, log):
190 if wx.Platform == '__WXMSW__':
191 win = TestPanel(nb, log, frame)
192 return win
193 else:
194 from Main import MessagePanel
195 win = MessagePanel(nb, 'This demo only works on Microsoft Windows.',
196 'Sorry', wx.ICON_WARNING)
197 return win
198
199
200
201 overview = """\
202 <html><body>
203 <h2>wx.lib.iewin.IEHtmlWindow</h2>
204
205 The wx.lib.iewin.IEHtmlWindow class is one example of using ActiveX
206 controls from wxPython using the new wx.activex module. This allows
207 you to use an ActiveX control as if it is a wx.Window, you can call
208 its methods, set/get properties, and receive events from the ActiveX
209 control in a very intuitive way.
210
211 <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
212 the win32all extensions, and is more "wx\'ish", meaning that it uses
213 events and etc. as would be expected from any other wx window.
214
215 </body></html>
216 """
217
218
219
220 if __name__ == '__main__':
221 import sys,os
222 import run
223 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
224
225
226 #----------------------------------------------------------------------
227