[python-win32] COM: Minimal example of a custom server working with DispatchWithEvents()
Mark Hammond
skippy.hammond at gmail.com
Wed Jul 28 22:21:30 EDT 2021
On 29/07/2021 9:56 am, William Belanger wrote:
> Hi,
>
>
> There is no typelib file unfortunately. The interface needs to
> communicate with Antidote's API by creating a COM server which exposes
> the methods defined in the AdapteurAntidote class.
>
>
> The problem is that the widget queried (a QTextEdit) is instantiated in
> another class (MainWindow), and I cannot attribute a "parent" to the
> dispatched COM object (self.server), as it raises either an
> AttributeError or a TypeError, depending on its declaration in
> __public_attrs__.
>
>
> From the documentation, I thought I needed to use DispatchWithEvents to
> handle the events in a separate "sink" class (ImplementationAntidote)
> that would behave more like a generic python object. Is there any other
> way to achieve this? It is quite a trivial feature so I assume it is
> possible to do so?
DispatchWithEvents helps with the most common pattern used for COM
events, particularly with MS products - in this model, the interfaces
are described in a typelib. However, products are free to define events
in whatever makes sense for them - eg, the object could take a plain
IDispatch and try and dynamically query and deliver events to the
methods here. If that's what the app in question does, then yeah, you
don't need DispatchWithEvents and can do something simpler. However,
I've no idea how that product works nor what it does, so can't really
answer the question.
I suspect you aren't the first person to run into this though and I
assume the object is usable in a number of languages which support COM,
so you might be better off asking in a forum specific to the product.
Cheers,
Mark
More information about the python-win32
mailing list