Hi,

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.
>

In short, Antidote binary is launched, then its IApiOle interface takes the
Dispatch object of the custom server I made and uses it to communicate back
and forth.

> self.server = win32com.client.Dispatch("Correcteur.Antidote")
> self.antidote = 
> win32com.client.Dispatch("Antidote.ApiOle")self.antidote.LanceOutilDispatch2(self.server,
>  "C", "", str(version))  # Server, tool, lang, API version
>
>
Using the Dispatch() method, the interface I made is working as expected,
which means that the methods exposed in AdapteurAntidote are then being
queried (updated example below). I did not try delivering back the resuts
but I assume it should work.


What I could not achieve is to get the server adapter class
(AdapteurAntidote) to work with objects which are created at runtime,
namely instances of other classes. I cannot set another runtime object as
an attribute of the adapter class, nor pass it on instantiation. Thus, the
adapter is quite useless in this case. Is it even possible using pywin32?
If so, how?


Looking back at Antiote's C++ example, there is an idl file available from
them. Is it necessary though? I would rather do everything dynamically,
such as setting the GUID, just like I did for the DBus interface.


DBus interface: https://gitlab.com/-/snippets/2151173

COM interface: https://gitlab.com/-/snippets/2154411


Thanks,

Will

Le mer. 28 juil. 2021 à 22:21, Mark Hammond <skippy.hamm...@gmail.com> a
écrit :

>
> 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
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to