]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxIEHtmlWin.py
Removed AlignIn after further thought
[wxWidgets.git] / wxPython / demo / wxIEHtmlWin.py
1
2 from wxPython.wx import *
3
4 if wxPlatform == '__WXMSW__':
5 from wxPython.iewin import *
6
7 #----------------------------------------------------------------------
8
9 class TestPanel(wxWindow):
10 def __init__(self, parent, log, frame=None):
11 wxWindow.__init__(self, parent, -1,
12 style=wxTAB_TRAVERSAL|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE)
13 self.log = log
14 self.current = "http://wxWindows.org/"
15 self.frame = frame
16 if frame:
17 self.titleBase = frame.GetTitle()
18
19
20 sizer = wxBoxSizer(wxVERTICAL)
21 btnSizer = wxBoxSizer(wxHORIZONTAL)
22
23 self.ie = wxIEHtmlWin(self, -1, style = wxNO_FULL_REPAINT_ON_RESIZE)
24
25
26 btn = wxButton(self, wxNewId(), "Open", style=wxBU_EXACTFIT)
27 EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
28 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
29
30 btn = wxButton(self, wxNewId(), "Home", style=wxBU_EXACTFIT)
31 EVT_BUTTON(self, btn.GetId(), self.OnHomeButton)
32 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
33
34 btn = wxButton(self, wxNewId(), "<--", style=wxBU_EXACTFIT)
35 EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
36 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
37
38 btn = wxButton(self, wxNewId(), "-->", style=wxBU_EXACTFIT)
39 EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
40 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
41
42 btn = wxButton(self, wxNewId(), "Stop", style=wxBU_EXACTFIT)
43 EVT_BUTTON(self, btn.GetId(), self.OnStopButton)
44 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
45
46 btn = wxButton(self, wxNewId(), "Search", style=wxBU_EXACTFIT)
47 EVT_BUTTON(self, btn.GetId(), self.OnSearchPageButton)
48 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
49
50 btn = wxButton(self, wxNewId(), "Refresh", style=wxBU_EXACTFIT)
51 EVT_BUTTON(self, btn.GetId(), self.OnRefreshPageButton)
52 btnSizer.Add(btn, 0, wxEXPAND|wxALL, 2)
53
54 txt = wxStaticText(self, -1, "Location:")
55 btnSizer.Add(txt, 0, wxCENTER|wxALL, 2)
56
57 self.location = wxComboBox(self, wxNewId(), "", style=wxCB_DROPDOWN|wxPROCESS_ENTER)
58 EVT_COMBOBOX(self, self.location.GetId(), self.OnLocationSelect)
59 EVT_KEY_UP(self.location, self.OnLocationKey)
60 EVT_CHAR(self.location, self.IgnoreReturn)
61 btnSizer.Add(self.location, 1, wxEXPAND|wxALL, 2)
62
63
64 sizer.Add(btnSizer, 0, wxEXPAND)
65 sizer.Add(self.ie, 1, wxEXPAND)
66
67 self.ie.Navigate(self.current)
68 self.location.Append(self.current)
69
70 self.SetSizer(sizer)
71 self.SetAutoLayout(True)
72 EVT_SIZE(self, self.OnSize)
73
74 # Hook up the event handlers for the IE window
75 EVT_MSHTML_BEFORENAVIGATE2(self, -1, self.OnBeforeNavigate2)
76 EVT_MSHTML_NEWWINDOW2(self, -1, self.OnNewWindow2)
77 EVT_MSHTML_DOCUMENTCOMPLETE(self, -1, self.OnDocumentComplete)
78 #EVT_MSHTML_PROGRESSCHANGE(self, -1, self.OnProgressChange)
79 EVT_MSHTML_STATUSTEXTCHANGE(self, -1, self.OnStatusTextChange)
80 EVT_MSHTML_TITLECHANGE(self, -1, self.OnTitleChange)
81
82
83 def ShutdownDemo(self):
84 # put the frame title back
85 if self.frame:
86 self.frame.SetTitle(self.titleBase)
87
88
89 def OnSize(self, evt):
90 self.Layout()
91
92
93 def OnLocationSelect(self, evt):
94 url = self.location.GetStringSelection()
95 self.log.write('OnLocationSelect: %s\n' % url)
96 self.ie.Navigate(url)
97
98 def OnLocationKey(self, evt):
99 if evt.KeyCode() == WXK_RETURN:
100 URL = self.location.GetValue()
101 self.location.Append(URL)
102 self.ie.Navigate(URL)
103 else:
104 evt.Skip()
105
106
107 def IgnoreReturn(self, evt):
108 if evt.GetKeyCode() != WXK_RETURN:
109 evt.Skip()
110
111 def OnOpenButton(self, event):
112 dlg = wxTextEntryDialog(self, "Open Location",
113 "Enter a full URL or local path",
114 self.current, wxOK|wxCANCEL)
115 dlg.CentreOnParent()
116 if dlg.ShowModal() == wxID_OK:
117 self.current = dlg.GetValue()
118 self.ie.Navigate(self.current)
119 dlg.Destroy()
120
121 def OnHomeButton(self, event):
122 self.ie.GoHome() ## ET Phone Home!
123
124 def OnPrevPageButton(self, event):
125 self.ie.GoBack()
126
127 def OnNextPageButton(self, event):
128 self.ie.GoForward()
129
130 def OnStopButton(self, evt):
131 self.ie.Stop()
132
133 def OnSearchPageButton(self, evt):
134 self.ie.GoSearch()
135
136 def OnRefreshPageButton(self, evt):
137 self.ie.Refresh(wxIEHTML_REFRESH_COMPLETELY)
138
139
140
141 def logEvt(self, name, event):
142 self.log.write('%s: %s\n' %
143 (name, (event.GetLong1(), event.GetLong2(), event.GetText1())))
144
145 def OnBeforeNavigate2(self, evt):
146 self.logEvt('OnBeforeNavigate2', evt)
147
148 def OnNewWindow2(self, evt):
149 self.logEvt('OnNewWindow2', evt)
150 evt.Veto() # don't allow it
151
152 def OnDocumentComplete(self, evt):
153 self.logEvt('OnDocumentComplete', evt)
154 self.current = evt.GetText1()
155 self.location.SetValue(self.current)
156
157 def OnTitleChange(self, evt):
158 self.logEvt('OnTitleChange', evt)
159 if self.frame:
160 self.frame.SetTitle(self.titleBase + ' -- ' + evt.GetText1())
161
162 def OnStatusTextChange(self, evt):
163 self.logEvt('OnStatusTextChange', evt)
164 if self.frame:
165 self.frame.SetStatusText(evt.GetText1())
166
167
168 #----------------------------------------------------------------------
169 # for the demo framework...
170
171 def runTest(frame, nb, log):
172 if wxPlatform == '__WXMSW__':
173 win = TestPanel(nb, log, frame)
174 return win
175 else:
176 dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
177 'Sorry', wxOK | wxICON_INFORMATION)
178 dlg.ShowModal()
179 dlg.Destroy()
180
181
182
183 overview = """\
184 <html><body>
185 <h2>wxIEHtmlWin</h2>
186
187 The wxIEHtmlWin class is the first example of using a contributed
188 wxActiveX class in wxWindows C++. It is still experimental, but
189 I think it is useful.
190
191 <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
192 the win32all extensions, and is more "wx\'ish", meaning that it uses
193 events and etc. as would be expected from any other wx window.
194
195 </body></html>
196 """
197
198
199
200 if __name__ == '__main__':
201 import sys,os
202 import run
203 run.main(['', os.path.basename(sys.argv[0])])
204
205
206 #----------------------------------------------------------------------
207