2 from wxPython
.wx
import *
4 if wxPlatform
== '__WXMSW__':
5 from wxPython
.iewin
import *
7 #----------------------------------------------------------------------
9 class TestPanel(wxWindow
):
10 def __init__(self
, parent
, log
, frame
=None):
11 wxWindow
.__init
__(self
, parent
, -1, style
=wxCLIP_CHILDREN
)
13 self
.current
= "http://wxPython.org/"
16 self
.titleBase
= frame
.GetTitle()
19 sizer
= wxBoxSizer(wxVERTICAL
)
20 btnSizer
= wxBoxSizer(wxHORIZONTAL
)
22 self
.ie
= wxIEHtmlWin(self
, -1) ##, style=wxSUNKEN_BORDER)
25 btn
= wxButton(self
, wxNewId(), "Open", style
=wxBU_EXACTFIT
)
26 EVT_BUTTON(self
, btn
.GetId(), self
.OnOpenButton
)
27 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
29 btn
= wxButton(self
, wxNewId(), "Home", style
=wxBU_EXACTFIT
)
30 EVT_BUTTON(self
, btn
.GetId(), self
.OnHomeButton
)
31 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
33 btn
= wxButton(self
, wxNewId(), "<--", style
=wxBU_EXACTFIT
)
34 EVT_BUTTON(self
, btn
.GetId(), self
.OnPrevPageButton
)
35 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
37 btn
= wxButton(self
, wxNewId(), "-->", style
=wxBU_EXACTFIT
)
38 EVT_BUTTON(self
, btn
.GetId(), self
.OnNextPageButton
)
39 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
41 btn
= wxButton(self
, wxNewId(), "Stop", style
=wxBU_EXACTFIT
)
42 EVT_BUTTON(self
, btn
.GetId(), self
.OnStopButton
)
43 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
45 btn
= wxButton(self
, wxNewId(), "Search", style
=wxBU_EXACTFIT
)
46 EVT_BUTTON(self
, btn
.GetId(), self
.OnSearchPageButton
)
47 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
49 btn
= wxButton(self
, wxNewId(), "Refresh", style
=wxBU_EXACTFIT
)
50 EVT_BUTTON(self
, btn
.GetId(), self
.OnRefreshPageButton
)
51 btnSizer
.Add(btn
, 0, wxEXPAND|wxALL
, 2)
53 txt
= wxStaticText(self
, -1, "Location:")
54 btnSizer
.Add(txt
, 0, wxCENTER|wxALL
, 2)
56 self
.location
= wxComboBox(self
, wxNewId(), "", style
=wxCB_DROPDOWN
)
57 EVT_COMBOBOX(self
, self
.location
.GetId(), self
.OnLocationSelect
)
58 EVT_KEY_UP(self
.location
, self
.OnLocationKey
)
59 EVT_CHAR(self
.location
, self
.IgnoreReturn
)
60 btnSizer
.Add(self
.location
, 1, wxEXPAND|wxALL
, 2)
62 sizer
.Add(btnSizer
, 0, wxEXPAND
)
63 sizer
.Add(self
.ie
, 1, wxEXPAND
)
65 self
.ie
.LoadUrl(self
.current
)
66 self
.location
.Append(self
.current
)
69 self
.SetAutoLayout(true
)
70 EVT_SIZE(self
, self
.OnSize
)
72 # Hook up the event handlers for the IE window
73 EVT_MSHTML_BEFORENAVIGATE2(self
, -1, self
.OnBeforeNavigate2
)
74 EVT_MSHTML_NEWWINDOW2(self
, -1, self
.OnNewWindow2
)
75 EVT_MSHTML_DOCUMENTCOMPLETE(self
, -1, self
.OnDocumentComplete
)
76 #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange)
77 EVT_MSHTML_STATUSTEXTCHANGE(self
, -1, self
.OnStatusTextChange
)
78 EVT_MSHTML_TITLECHANGE(self
, -1, self
.OnTitleChange
)
81 def OnSize(self
, evt
):
84 def OnLocationSelect(self
, evt
):
85 url
= self
.location
.GetStringSelection()
86 self
.log
.write('OnLocationSelect: %s\n' % url
)
89 def OnLocationKey(self
, evt
):
90 if evt
.KeyCode() == WXK_RETURN
:
91 URL
= self
.location
.GetValue()
92 self
.location
.Append(URL
)
97 def IgnoreReturn(self
, evt
):
99 if evt
.KeyCode() != WXK_RETURN
:
102 def OnOpenButton(self
, event
):
103 dlg
= wxTextEntryDialog(self
, "Open Location",
104 "Enter a full URL or local path",
105 self
.current
, wxOK|wxCANCEL
)
107 if dlg
.ShowModal() == wxID_OK
:
108 self
.current
= dlg
.GetValue()
109 self
.ie
.LoadUrl(self
.current
)
112 def OnHomeButton(self
, event
):
113 self
.ie
.GoHome() ## ET Phone Home!
115 def OnPrevPageButton(self
, event
):
118 def OnNextPageButton(self
, event
):
121 def OnStopButton(self
, evt
):
124 def OnSearchPageButton(self
, evt
):
127 def OnRefreshPageButton(self
, evt
):
128 self
.ie
.Refresh(wxIEHTML_REFRESH_COMPLETELY
)
132 def logEvt(self
, name
, event
):
133 self
.log
.write('%s: %s\n' %
134 (name
, (event
.GetLong1(), event
.GetLong2(), event
.GetText())))
136 def OnBeforeNavigate2(self
, evt
):
137 self
.logEvt('OnBeforeNavigate2', evt
)
139 def OnNewWindow2(self
, evt
):
140 self
.logEvt('OnNewWindow2', evt
)
141 evt
.Veto() # don't allow it
143 def OnDocumentComplete(self
, evt
):
144 self
.logEvt('OnDocumentComplete', evt
)
145 self
.current
= evt
.GetText()
146 self
.location
.SetValue(self
.current
)
148 def OnTitleChange(self
, evt
):
149 self
.logEvt('OnTitleChange', evt
)
151 self
.frame
.SetTitle(self
.titleBase
+ ' -- ' + evt
.GetText())
153 def OnStatusTextChange(self
, evt
):
154 self
.logEvt('OnStatusTextChange', evt
)
156 self
.frame
.SetStatusText(evt
.GetText())
159 #----------------------------------------------------------------------
160 # for the demo framework...
162 def runTest(frame
, nb
, log
):
163 if wxPlatform
== '__WXMSW__':
164 win
= TestPanel(nb
, log
, frame
)
167 dlg
= wxMessageDialog(frame
, 'This demo only works on MSW.',
168 'Sorry', wxOK | wxICON_INFORMATION
)
178 The wxIEHtmlWin class is the first example of using a contributed
179 wxActiveX class in wxWindows C++. It is still experimental, but
180 I think it is useful.
182 <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
183 the win32all extensions, and is more "wx\'ish", meaning that it uses
184 events and etc. as would be expected from any other wx window.
191 if __name__
== '__main__':
194 run
.main(['', os
.path
.basename(sys
.argv
[0])])
197 #----------------------------------------------------------------------