[python-win32] Python COM problem with IE

Jorgensen, Jens jens.jorgensen@tallan.com
Thu, 12 Apr 2001 12:12:25 -0500


This is curious indeed. I tried doing a makepy.py on the type library and using that but going that route I couldn't even get it to call events period. I'm sure there must be a way and I thought this might be the better route but I just couldn't get any events to be called. I'm not sure if I'm doing this right, I just guessed after poring over the COM python modules. Here's what I tried (IE is the module I generated with makepy):

from win32com.client import DispatchWithEvents
import IE
import pythoncom

class IEEvents(IE.DWebBrowserEvents2): #
    def OnBeforeNavigate2(self, pDisp=pythoncom.Missing, URL=pythoncom.Missing, Flags=pythoncom.Missing, TargetFrameName=pythoncom.Missing, PostData=pythoncom.Missing, Headers=pythoncom.Missing, Cancel=pythoncom.Missing) :
#    def OnBeforeNavigate2(self, disp, url, *args):
        print repr(URL)
        if URL != "about:blank" :
            return 1
        else :
            return 0

class MyIE(IE.InternetExplorer) :
    def __init__(self) :
        IE.InternetExplorer.__init__(self)
        print 'coclass_interfaces', repr(self.coclass_sources)

    coclass_sources = [IE.DWebBrowserEvents, IEEvents ]
    default_source = IEEvents

ie = MyIE()
#ie = DispatchWithEvents("InternetExplorer.Application", IEEvents)
ie.Visible =  1
ie.Navigate2("about:blank")

pythoncom.PumpMessages()



Scott Yang wrote:

> Hi,
>
> I am trying to implement a GUI application using IE as an
> ActiveX control. I need to manipulate the content of the browser
> depending on the URL. I implemented a class that handles the events
> as DWebBrowserEvents2, and Python crashes everytime when I return
> "Cancel" to be true in BeforeNavigate2 (it is a ByRef value). I can
> re-produce that when I use IE as an ActiveX control or as an automation
> object.
>
> For example, the following code will crash python when you try to go
> to any link. We tried similar code on both Perl and Delphi, and both
> of them work fine.
>
> Any ideas?
>
> -----------------------------------------------------------
>
> from win32com.client import DispatchWithEventsNimport pythoncom
>
> class IEEvents:
>     def OnBeforeNavigate2(self, disp, url, *args):
>         return url != u"about:blank"
>
> ie = DispatchWithEvents("InternetExplorer.Application", IEEvents)
> ie.Visible =  1
> ie.Navigate2("about:blank")
>
> pythoncom.PumpMessages()
>
> --
> Scott Yang <syang@xplantechnology.com>                Xplan Technology Pty Ltd
>     Exchange Square, 10 Bridge Street, Sydney NSW 2000
>     P +61 2 8220 8116  F +61 2 8220 8117
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32

--
Jens B. Jorgensen
jens.jorgensen@tallan.com