[python-win32] com events while running wx main loop

Thomas Heller theller at ctypes.org
Wed Apr 18 20:50:48 CEST 2007


Christian K. schrieb:
> sorry. I forgot the attachment.
> 
> Christian
> 
> 
> 
> ------------------------------------------------------------------------
> 
> import unittest
> import comtypes.client
> 
> import wx
> 
> class EventHandler(object):
>     """Instances are called when the COM object fires events."""
>     def __init__(self, view, name):
>         self.view = view
>         self.name = name
> 
>     def __call__(self, this, *args, **kw):
>         self.view.write(unicode("Event %s fired" % self.name, args, kw))

Here is the problem:                                          ^^^^^^^^^^^^
You are calling the unicode function with three arguments ;-).
Unfortunately, by default you do not get a traceback that points out the problem.

You can enable the tracebacks with these lines at  the top of your script:

import logging
logging.basicConfig(level=logging.WARNING)

BTW:  I see that you are using an old version of comtypes (in recent versions the CreateObject function
does not accept a 'sink' argument any longer; you have to setup the events by calling
comtypes.client.GetEvents function, and keep the returned object as long as you want
to receive the events).  Unfortunately I have never released a newer comtypes, but
you can get it with 'easy_install comtypes==dev', if you have svn installed.

Thomas

PS: I'll attach a working script that I have made, it connects to internet explorer which
is my favorite com client for testing (although I don't use it for browsing).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: x.py
Type: application/x-python
Size: 1956 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20070418/ccd50daa/attachment.bin 


More information about the Python-win32 mailing list