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 "<input>", line 1, in <module>
>    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: '{00000000-0000-0000-0000-000000000000}'
> 

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
<POINTER(DispHTMLDocument) ptr=0x277764 at 180e7b0>
# 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, <POINTER(DispCEventObj) 
ptr=0x272fa4 at 39e4ee0>)
Event HTMLDocumentEvents2_onmouseout(None, <POINTER(DispCEventObj) ptr=0x27568c 
at 39e4da0>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272f6c at 39e4f30>)
Event HTMLDocumentEvents2_onmouseover(None, <POINTER(DispCEventObj) 
ptr=0x2755dc at 39e4d50>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4d00>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x27328c at 39e4c60>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x273a84 at 39e4c10>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x2755dc at 39e4ee0>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4da0>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x273a84 at 39e4f30>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272f6c at 39e4d50>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4d00>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4c60>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x2755dc at 39e4c10>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272efc at 39e4ee0>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4da0>)
Event HTMLDocumentEvents2_onmouseout(None, <POINTER(DispCEventObj) ptr=0x273a84 
at 39e4f30>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4d50>)
Event HTMLDocumentEvents2_onmouseover(None, <POINTER(DispCEventObj) 
ptr=0x2755dc at 39e4d00>)
Event HTMLDocumentEvents2_onmousedown(None, <POINTER(DispCEventObj) 
ptr=0x272efc at 39e4f30>)
Event HTMLDocumentEvents2_onbeforedeactivate(None, <POINTER(DispCEventObj) 
ptr=0x272e6c at 39e4d50>)
Event HTMLDocumentEvents2_onbeforeactivate(None, <POINTER(DispCEventObj) 
ptr=0x27328c at 39e4d00>)
Event HTMLDocumentEvents2_ondeactivate(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4c60>)
Event HTMLDocumentEvents2_onfocusout(None, <POINTER(DispCEventObj) ptr=0x2729e4 
at 39e4c10>)
Event HTMLDocumentEvents2_onactivate(None, <POINTER(DispCEventObj) ptr=0x273a84 
at 39e4ee0>)
Event HTMLDocumentEvents2_onfocusin(None, <POINTER(DispCEventObj) ptr=0x2755dc 
at 39e4da0>)
Event HTMLDocumentEvents2_onpropertychange(None, <POINTER(DispCEventObj) 
ptr=0x272efc at 39e4f30>)
Event HTMLDocumentEvents2_onmouseup(None, <POINTER(DispCEventObj) ptr=0x272e6c 
at 39e4d50>)
Event HTMLDocumentEvents2_oncontextmenu(None, <POINTER(DispCEventObj) 
ptr=0x27328c at 39e4d00>)
Event HTMLDocumentEvents2_onmousedown(None, <POINTER(DispCEventObj) 
ptr=0x272eb4 at 39e4c60>)
Event HTMLDocumentEvents2_onmousemove(None, <POINTER(DispCEventObj) 
ptr=0x2729e4 at 39e4c10>)
Event HTMLDocumentEvents2_onmouseup(None, <POINTER(DispCEventObj) ptr=0x273a84 
at 39e4ee0>)
Event HTMLDocumentEvents2_onclick(None, <POINTER(DispCEventObj) ptr=0x2755dc at 
39e4da0>)

-- 

Thomas

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to