Robin Dunn schrieb:
> I've got a comtypes based activex container for wxPython[1], and I'm
> trying to find a way to prevent the default context menu in an
> IWebBrowser2 control.
Cool.
> After some googling it seems from some VB
> sites[2] that there should be a OnContextMenu event coming from the
> document object, but I can't seem to be able to catch it using comtypes.
> When I try using GetEvents on the document property it just gives me
> an exception.
>
> >>> cc.GetEvents(ie.ctrl.Document, t)
> Traceback (most recent call last):
>File "", line 1, in
>File
> "c:\tools\python25\lib\site-packages\comtypes-0.5.0a-py2.5.egg\comtypes\client\_events.py",
>
> line 132, in GetEvents
> interface = FindOutgoingInterface(source)
>File
> "c:\tools\python25\lib\site-packages\comtypes-0.5.0a-py2.5.egg\comtypes\client\_events.py",
>
> line 52, in FindOutgoingInterface
> interface = comtypes.com_interface_registry[str(guid)]
> KeyError: '{----}'
>
This looks like the Document object implements IProvideClassInfo2 interface, but
IProvideClassInfo2::GetGUID() returns a NULL guid. comtypes should probably
catch this,
but the net effect is that one cannot determine the outgoing interface.
Fortunately, with a little bit browsing through the comtypes.gen.MSHTML module
(really the comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0 module)
and guessing I found that both the HTMLDocumentEvents or HTMLDocumentEvents2
interface seems to work, you just have to pass that interface to
GetEvents/ShowEvents.
This script works for me:
"""
from comtypes.client import CreateObject, GetEvents, ShowEvents, PumpEvents
ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate2("http://www.python.org";)
PumpEvents(1) # give the page a chance to load
doc = ie.Document
from comtypes.gen import MSHTML
print doc
evt = ShowEvents(doc, interface=MSHTML.HTMLDocumentEvents2)
PumpEvents(10)
"""
and here is some sample output:
c:\svn\theller\comtypes-0.4>py25 docevents.py
# event found: HTMLDocumentEvents2_onstop
# event found: HTMLDocumentEvents2_onbeforeeditfocus
# event found: HTMLDocumentEvents2_onbeforeupdate
# event found: HTMLDocumentEvents2_onafterupdate
# event found: HTMLDocumentEvents2_onrowexit
# event found: HTMLDocumentEvents2_onrowenter
# event found: HTMLDocumentEvents2_onmouseover
# event found: HTMLDocumentEvents2_onmouseout
# event found: HTMLDocumentEvents2_onhelp
# event found: HTMLDocumentEvents2_ondragstart
# event found: HTMLDocumentEvents2_onselectstart
# event found: HTMLDocumentEvents2_onerrorupdate
# event found: HTMLDocumentEvents2_ondatasetchanged
# event found: HTMLDocumentEvents2_ondataavailable
# event found: HTMLDocumentEvents2_ondatasetcomplete
# event found: HTMLDocumentEvents2_onpropertychange
# event found: HTMLDocumentEvents2_onactivate
# event found: HTMLDocumentEvents2_ondeactivate
# event found: HTMLDocumentEvents2_onbeforeactivate
# event found: HTMLDocumentEvents2_onfocusin
# event found: HTMLDocumentEvents2_onfocusout
# event found: HTMLDocumentEvents2_onreadystatechange
# event found: HTMLDocumentEvents2_onrowsdelete
# event found: HTMLDocumentEvents2_onmouseup
# event found: HTMLDocumentEvents2_onmousemove
# event found: HTMLDocumentEvents2_onmousedown
# event found: HTMLDocumentEvents2_onkeyup
# event found: HTMLDocumentEvents2_onkeypress
# event found: HTMLDocumentEvents2_onkeydown
# event found: HTMLDocumentEvents2_ondblclick
# event found: HTMLDocumentEvents2_onclick
# event found: HTMLDocumentEvents2_onmousewheel
# event found: HTMLDocumentEvents2_onbeforedeactivate
# event found: HTMLDocumentEvents2_onrowsinserted
# event found: HTMLDocumentEvents2_oncontrolselect
# event found: HTMLDocumentEvents2_oncellchange
# event found: HTMLDocumentEvents2_onselectionchange
# event found: HTMLDocumentEvents2_oncontextmenu
Event HTMLDocumentEvents2_onreadystatechange(None, )
Event HTMLDocumentEvents2_onmouseout(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmouseover(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmouseout(None, )
Event HTMLDocumentEvents2_onmousemove(None, )
Event HTMLDocumentEvents2_onmouseover(None, )
Event HTMLDocumentEvents2_onmousedown(None, )
Event HTMLDocumentEvents2_onbeforedeactivate(None, )
Event HTMLDocumentEvents2_onbeforeactivate(None, )
Event HTMLDocumentEvents2_ondeactivate(None, )
Event HTMLDocume