1 # 11/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
5 # 11/28/2003 - Jeff Grimmett (grimmtooth@softhome.net)
7 # o iewin.py is missing
12 if wx
.Platform
== '__WXMSW__':
13 import wx
.iewin
as iewin
15 #----------------------------------------------------------------------
17 class TestPanel(wx
.Window
):
18 def __init__(self
, parent
, log
, frame
=None):
21 style
=wx
.TAB_TRAVERSAL|wx
.CLIP_CHILDREN|wx
.NO_FULL_REPAINT_ON_RESIZE
25 self
.current
= "http://wxPython.org/"
29 self
.titleBase
= frame
.GetTitle()
31 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
32 btnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
34 self
.ie
= iewin
.IEHtmlWin(self
, -1, style
= wx
.NO_FULL_REPAINT_ON_RESIZE
)
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)
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)
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)
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)
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)
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)
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)
65 txt
= wx
.StaticText(self
, -1, "Location:")
66 btnSizer
.Add(txt
, 0, wx
.CENTER|wx
.ALL
, 2)
68 self
.location
= wx
.ComboBox(
69 self
, wx
.NewId(), "", style
=wx
.CB_DROPDOWN|wx
.PROCESS_ENTER
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)
77 sizer
.Add(btnSizer
, 0, wx
.EXPAND
)
78 sizer
.Add(self
.ie
, 1, wx
.EXPAND
)
80 self
.ie
.Navigate(self
.current
)
81 self
.location
.Append(self
.current
)
84 self
.SetAutoLayout(True)
85 wx
.EVT_SIZE(self
, self
.OnSize
)
87 # Hook up the event handlers for the IE window
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
)
91 #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange)
92 iewin
.EVT_MSHTML_STATUSTEXTCHANGE(self
, -1, self
.OnStatusTextChange
)
93 iewin
.EVT_MSHTML_TITLECHANGE(self
, -1, self
.OnTitleChange
)
96 def ShutdownDemo(self
):
97 # put the frame title back
99 self
.frame
.SetTitle(self
.titleBase
)
102 def OnSize(self
, evt
):
106 def OnLocationSelect(self
, evt
):
107 url
= self
.location
.GetStringSelection()
108 self
.log
.write('OnLocationSelect: %s\n' % url
)
109 self
.ie
.Navigate(url
)
111 def OnLocationKey(self
, evt
):
112 if evt
.KeyCode() == wx
.WXK_RETURN
:
113 URL
= self
.location
.GetValue()
114 self
.location
.Append(URL
)
115 self
.ie
.Navigate(URL
)
120 def IgnoreReturn(self
, evt
):
121 if evt
.GetKeyCode() != wx
.WXK_RETURN
:
124 def OnOpenButton(self
, event
):
125 dlg
= wx
.TextEntryDialog(self
, "Open Location",
126 "Enter a full URL or local path",
127 self
.current
, wx
.OK|wx
.CANCEL
)
130 if dlg
.ShowModal() == wx
.ID_OK
:
131 self
.current
= dlg
.GetValue()
132 self
.ie
.Navigate(self
.current
)
136 def OnHomeButton(self
, event
):
137 self
.ie
.GoHome() ## ET Phone Home!
139 def OnPrevPageButton(self
, event
):
142 def OnNextPageButton(self
, event
):
145 def OnStopButton(self
, evt
):
148 def OnSearchPageButton(self
, evt
):
151 def OnRefreshPageButton(self
, evt
):
152 self
.ie
.Refresh(iewin
.IEHTML_REFRESH_COMPLETELY
)
155 def logEvt(self
, name
, event
):
156 self
.log
.write('%s: %s\n' %
157 (name
, (event
.GetLong1(), event
.GetLong2(), event
.GetText1())))
159 def OnBeforeNavigate2(self
, evt
):
160 self
.logEvt('OnBeforeNavigate2', evt
)
162 def OnNewWindow2(self
, evt
):
163 self
.logEvt('OnNewWindow2', evt
)
164 evt
.Veto() # don't allow it
166 def OnDocumentComplete(self
, evt
):
167 self
.logEvt('OnDocumentComplete', evt
)
168 self
.current
= evt
.GetText1()
169 self
.location
.SetValue(self
.current
)
171 def OnTitleChange(self
, evt
):
172 self
.logEvt('OnTitleChange', evt
)
174 self
.frame
.SetTitle(self
.titleBase
+ ' -- ' + evt
.GetText1())
176 def OnStatusTextChange(self
, evt
):
177 self
.logEvt('OnStatusTextChange', evt
)
179 self
.frame
.SetStatusText(evt
.GetText1())
182 #----------------------------------------------------------------------
183 # for the demo framework...
185 def runTest(frame
, nb
, log
):
186 if wx
.Platform
== '__WXMSW__':
187 win
= TestPanel(nb
, log
, frame
)
190 dlg
= wx
.MessageDialog(frame
, 'This demo only works on MSW.',
191 'Sorry', wx
.OK | wx
.ICON_INFORMATION
)
199 <h2>wx.IEHtmlWin</h2>
201 The wx.IEHtmlWin class is the first example of using a contributed
202 wxActiveX class in wxWindows C++. It is still experimental, but
203 I think it is useful.
205 <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
206 the win32all extensions, and is more "wx\'ish", meaning that it uses
207 events and etc. as would be expected from any other wx window.
214 if __name__
== '__main__':
217 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])
220 #----------------------------------------------------------------------