[python-win32] IE control via DWebBrowserEvents2
Vaclav Opekar
opekar at eccam.com
Sun Jun 8 13:47:14 CEST 2008
Hello all,
I'm trying to embed IE to a GTK app and control IE behavior via the
DWebBrowserEvents2 interface.
Embedding works, events like OnBeforeNavigate2 or OnNewWindow2 are
comming fine but when I try to return (from the callback) a Cancel
value which suppose stop IE from next page loading or new explorer
window creation, the program either crashes or doesn't prevent IE from
moving to next page or opening a new window.
Any idea how I could approach this problem?
Bellow are details and code snippets.
Thanks a lot,
Vasek
->I've used this example as a base
http://pywin32.cvs.sourceforge.net/pywin32/pywin32/com/win32comext/axcontrol/demos/container_ie.py?revision=1.2&view=markup
->generated the stubs using
python makepy.py C:\WINDOWS\system32\shdocvw.dll
->defined callback class using the generated classes (DWebBrowserEvents2)
class BrowserCB(DWebBrowserEvents2):
def __init__(self, oobj):
DWebBrowserEvents2.__init__(self, oobj)
#Cancel is in/out param in COM
def OnBeforeNavigate2(self, pDisp, URL, Flags, TargetFrameName,
PostData, Headers, Cancel):
if URL != "about:blank" :
# return 1 # <- this crashes IE
return True # this doesnt work - doesn stop IE to move to
non blank page
# Cancel is in/out param in COM
def OnNewWindow2(self, ppDisp=defaultNamedNotOptArg,
Cancel=defaultNamedNotOptArg):
print "OnNewWindow2"
return True # returns pythoncom error: Python error invoking COM
method.
-> callback class registration snippet
browser.DoVerb(axcontrol.OLEIVERB_SHOW, None, site, -1,
self.hwnd, rect)
b2 = Dispatch(browser.QueryInterface(pythoncom.IID_IDispatch))
self.browser2 = b2
self.eventSink = BrowserCB(self.browser2) #only this line was
added to the above example from CVS
More information about the python-win32
mailing list