[python-win32] Python COM server: can it generate events?

Mark Hammond mhammond at skippinet.com.au
Wed Sep 22 02:32:34 CEST 2004


> Is it possible to make a Python COM server which can generate
> COM events?  I
> know how to make attributes and methods, but either I've
> missed the event
> section in the doc, or maybe it's not possible?
>
> I'd like to make an asynchronous COM server which can send
> events back to
> its container (the VB container implements the event handlers, e.g.
> OnMyEvent, and that code should run when the Python code calls
> "RaiseMyEvent" or whatever).
>
> Is this possible?

It is possible, but no friendly "wrappers" exist.  You will probably need to
understand how these events actually work (ie, "connection points") and roll
your sleeves up.  I think you would need to:
* Create a typelib describing your event interface, and using
win32com\test\pippo*, construct a python server with support for the
typelib. (this has no event support)
* Look at win32com\demos\connect.py, and add the necessary interfaces to
your server to support the connection point dance.  connect.py does events,
but not from a typelib.
* Have your VB code reference this typelib and handle events as normal.

If the events you want to raise already are defined in some other typelib,
it should be a little easier.

Mark.



More information about the Python-win32 mailing list