Radu Adrian Ciora schrieb: > Hi, > > I have modified the test_showevents.py with the following code: > def test(self): > o = comtypes.client.GetActiveObject("Word.Application") > o.Visible = 1 > toolbar = o.CommandBars("Standard") > print toolbar > > comtypes.client.GetModule(os.path.join(os.environ["CommonProgramFiles"], > r"Microsoft Shared\OFFICE11\MSO.dll")) > from comtypes.gen import Office > print Office.CommandBars, Office.CommandBarControl > while 1: > conn = comtypes.client.ShowEvents(toolbar)
> > but I get the following error : > > Traceback (most recent call last): [...] > TypeError: cannot determine source interface > > Is it possible to get events generated by the toolbar? On the internet I found code that shows how to do it, in VB. Apparently the CommandBar controls have their own way in which they expose events, you have to pass them to the 'word.VBE.Events.CommandBarEvents()' function, and that will deliver the events then: word = comtypes.client.CreateObject("Word.Application") word.Visible = 1 tb = word.CommandBars("Standard") btn = tb.Controls[1] evt = word.VBE.Events.CommandBarEvents(btn) from comtypes.gen import VBIDE comtypes.client.ShowEvents(evt, interface=VBIDE._dispCommandBarControlEvents) Unfortunately you have to supply the event interface in the ShowEvents call, because comtypes currently is not able to find out this interface itself. I have already fixed this bug in SVN, so in the next version (or if you grab the svn version) you should be able to use: comtypes.client.ShowEvents(evt) Please note that the comtypes.gen.VBIDE module is automatically generated; there is no need to call GetModule() in your code (at least that was the case for me, but I only have Word97 installed). Thomas ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users