1 # 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 if wx
.Platform
== '__WXMSW__':
9 import wx
.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
.IEHtmlWin(self
, -1, style
= wx
.NO_FULL_REPAINT_ON_RESIZE
)
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)
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)
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)
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)
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)
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)
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)
61 txt
= wx
.StaticText(self
, -1, "Location:")
62 btnSizer
.Add(txt
, 0, wx
.CENTER|wx
.ALL
, 2)
64 self
.location
= wx
.ComboBox(
65 self
, wx
.NewId(), "", style
=wx
.CB_DROPDOWN|wx
.PROCESS_ENTER
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)
73 sizer
.Add(btnSizer
, 0, wx
.EXPAND
)
74 sizer
.Add(self
.ie
, 1, wx
.EXPAND
)
76 self
.ie
.Navigate(self
.current
)
77 self
.location
.Append(self
.current
)
80 self
.SetAutoLayout(True)
81 wx
.EVT_SIZE(self
, self
.OnSize
)
83 # Hook up the event handlers for the IE window
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
)
87 #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange)
88 iewin
.EVT_MSHTML_STATUSTEXTCHANGE(self
, -1, self
.OnStatusTextChange
)
89 iewin
.EVT_MSHTML_TITLECHANGE(self
, -1, self
.OnTitleChange
)
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
.IEHTML_REFRESH_COMPLETELY
)
151 def logEvt(self
, name
, event
):
152 self
.log
.write('%s: %s\n' %
153 (name
, (event
.GetLong1(), event
.GetLong2(), event
.GetText1())))
155 def OnBeforeNavigate2(self
, evt
):
156 self
.logEvt('OnBeforeNavigate2', evt
)
158 def OnNewWindow2(self
, evt
):
159 self
.logEvt('OnNewWindow2', evt
)
160 evt
.Veto() # don't allow it
162 def OnDocumentComplete(self
, evt
):
163 self
.logEvt('OnDocumentComplete', evt
)
164 self
.current
= evt
.GetText1()
165 self
.location
.SetValue(self
.current
)
167 def OnTitleChange(self
, evt
):
168 self
.logEvt('OnTitleChange', evt
)
170 self
.frame
.SetTitle(self
.titleBase
+ ' -- ' + evt
.GetText1())
172 def OnStatusTextChange(self
, evt
):
173 self
.logEvt('OnStatusTextChange', evt
)
175 self
.frame
.SetStatusText(evt
.GetText1())
178 #----------------------------------------------------------------------
179 # for the demo framework...
181 def runTest(frame
, nb
, log
):
182 if wx
.Platform
== '__WXMSW__':
183 win
= TestPanel(nb
, log
, frame
)
186 dlg
= wx
.MessageDialog(frame
, 'This demo only works on Windows.',
187 'Sorry', wx
.OK | wx
.ICON_INFORMATION
)
195 <h2>wx.IEHtmlWin</h2>
197 The wx.IEHtmlWin class is the first example of using a contributed
198 wxActiveX class in wxWindows C++. It is still experimental, but
199 I think it is useful.
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.
210 if __name__
== '__main__':
213 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])
216 #----------------------------------------------------------------------