wx.lib.iewin and NewWindow3
Suppose your wxPython app is is using an embedded Internet Explorer window to display HTML. You want links clicked in that window to open the user’s default browser rather than following the link within the embedded Internet Explorer.
The obvious solution is to hook OnBeforeNavigate2 like so:
self.Bind(iewin.EVT_BeforeNavigate2, self.OnBeforeNavigate2, self.ie)
...
def OnBeforeNavigate2(self, evt):
wx.LaunchDefaultBrowser(evt.URL)
evt.Cancel = True
but if the link the user clicked is set to open a new window, the emebdded IE will just open a new window. So you hook NewWindow2. Oops, NewWindow2 doesn’t tell you what the URL is!
Here’s what I did, since I don’t care if my reader works on pre-SP2 Windows XP:
Define an Event to permit me to hook NewWindow3, which is a new event that includes the URL being opened, then hook it appropriately:
wxEVT_NewWindow3 = wx.activex.RegisterActiveXEvent('NewWindow3') EVT_NewWindow3 = wx.PyEventBinder(wxEVT_NewWindow3, 1) ... self.Bind(EVT_NewWindow3, self.OnNewWindow3, self.ie) ... def OnNewWindow3(self, evt): self.logEvt(evt) # Veto the new window. Cancel is defined as an "out" param # for this event. See iewin.py evt.Cancel = True wx.LaunchDefaultBrowser(evt.bstrUrl)
March 23rd, 2007 at 7:41 am
Whats the difference between that and pre service pack too (not that I can about pre SP2 system support but I’m curious)
Also, seems like you are ripe for a GUI programming tag.
March 23rd, 2007 at 10:23 am
The NewWindow3 event didn’t exist pre-SP2, according to the documentation I read about the event in.