1 # 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 if wx
.Platform
== '__WXMSW__':
9 import wx
.lib
.iewin
as iewin
11 #----------------------------------------------------------------------
13 class TestPanel(wx
.Window
):
14 def __init__(self
, parent
, log
, frame
=None):
17 style
=wx
.TAB_TRAVERSAL|wx
.CLIP_CHILDREN|wx
.NO_FULL_REPAINT_ON_RESIZE
21 self
.current
= "http://wxPython.org/"
25 self
.titleBase
= frame
.GetTitle()
27 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
28 btnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
30 self
.ie
= iewin
.IEHtmlWindow(self
, -1, style
= wx
.NO_FULL_REPAINT_ON_RESIZE
)
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)
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)
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)
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)
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)
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)
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)
61 txt
= wx
.StaticText(self
, -1, "Location:")
62 btnSizer
.Add(txt
, 0, wx
.CENTER|wx
.ALL
, 2)
64 self
.location
= wx
.ComboBox(
65 self
, -1, "", style
=wx
.CB_DROPDOWN|wx
.PROCESS_ENTER
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)
73 sizer
.Add(btnSizer
, 0, wx
.EXPAND
)
74 sizer
.Add(self
.ie
, 1, wx
.EXPAND
)
76 self
.ie
.LoadUrl(self
.current
)
77 self
.location
.Append(self
.current
)
80 # Since this is a wxWindow we have to call Layout ourselves
81 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
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
)
92 def ShutdownDemo(self
):
93 # put the frame title back
95 self
.frame
.SetTitle(self
.titleBase
)
98 def OnSize(self
, evt
):
102 def OnLocationSelect(self
, evt
):
103 url
= self
.location
.GetStringSelection()
104 self
.log
.write('OnLocationSelect: %s\n' % url
)
105 self
.ie
.Navigate(url
)
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
)
116 def IgnoreReturn(self
, evt
):
117 if evt
.GetKeyCode() != wx
.WXK_RETURN
:
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
)
126 if dlg
.ShowModal() == wx
.ID_OK
:
127 self
.current
= dlg
.GetValue()
128 self
.ie
.Navigate(self
.current
)
132 def OnHomeButton(self
, event
):
133 self
.ie
.GoHome() ## ET Phone Home!
135 def OnPrevPageButton(self
, event
):
138 def OnNextPageButton(self
, event
):
141 def OnStopButton(self
, evt
):
144 def OnSearchPageButton(self
, evt
):
147 def OnRefreshPageButton(self
, evt
):
148 self
.ie
.Refresh(iewin
.REFRESH_COMPLETELY
)
151 def logEvt(self
, evt
):
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
))
158 def OnBeforeNavigate2(self
, evt
):
161 def OnNewWindow2(self
, evt
):
165 def OnProgressChange(self
, evt
):
168 def OnDocumentComplete(self
, evt
):
170 self
.current
= evt
.URL
171 self
.location
.SetValue(self
.current
)
173 def OnTitleChange(self
, evt
):
176 self
.frame
.SetTitle(self
.titleBase
+ ' -- ' + evt
.Text
)
178 def OnStatusTextChange(self
, evt
):
181 self
.frame
.SetStatusText(evt
.Text
)
184 #----------------------------------------------------------------------
185 # for the demo framework...
187 def runTest(frame
, nb
, log
):
188 if wx
.Platform
== '__WXMSW__':
189 win
= TestPanel(nb
, log
, frame
)
192 dlg
= wx
.MessageDialog(frame
, 'This demo only works on Windows.',
193 'Sorry', wx
.OK | wx
.ICON_INFORMATION
)
201 <h2>wx.lib.iewin.IEHtmlWindow</h2>
203 The wx.lib.iewin.IEHtmlWindow class is one example of using ActiveX
204 controls from wxPython using the new wx.activex module. This allows
205 you to use an ActiveX control as if it is a wx.Window, you can call
206 its methods, set/get properties, and receive events from the ActiveX
207 control in a very intuitive way.
209 <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
210 the win32all extensions, and is more "wx\'ish", meaning that it uses
211 events and etc. as would be expected from any other wx window.
218 if __name__
== '__main__':
221 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])
224 #----------------------------------------------------------------------