[python-win32] How to enable events for Python Active Scripting?

Mark Hammond mhammond at skippinet.com.au
Mon Mar 13 20:45:37 EDT 2023


[adding the list back in]

I'm still not quite sure what you are trying to do. If you are trying to 
use Active Scripting, then things should "just work" in the same way 
they work for other Active Scripting languages. The IE demos show us 
handling events from IE. This all ties together with interfaces 
described in typelibs and using IConnectionPoint etc. In this world you 
don't implement Python classes which derive from EventSink or 
ScriptItem, you would define a function called "ObjectName_EventName"  - 
eg the "Image_OnClick()" you will find in mousetrack.htm.

If you are just trying to use the IConnectionPoint etc without the 
Active Scripting framework, then your best bet is to check out 
win32com\demos\connect.py, and specifically how it uses 
"win32com.client.connect.SimpleConnection()" with the CLSID of an object 
implementing the interface which fires the events.

I'm afraid it has been many years since I've worked on anything related 
to COM or events, so I really don't have great insights into the finer 
details. I've also no additional demos - everything relevant I have is 
in the repo.

Cheers,

Mark

On 14/03/2023 10:41 am, Wuping Xin wrote:
> Hi Mark,
>
> Thank you again for your suggestion.
>
> Here is my use case:
> 1.  C++ Host Application, which exposes a COM object model (with COM
> events).
> 2.  Users are expected to write Python script to interact with the COM
> object model.
>
> Following your advice, I read the following source files
> - win32comext\axscript\client\framework.py
> - win32comext\axscript\test\testHost.py
>
> But I am still somewhat unsure how to create event sinks at the Python
> script side.
> - Should I add a user-define Python class that inherits from EventSink
> or ScriptItem?
>
> Do you think you might be able to provide more hints or it would be
> great if there is an example to illustrate this?
>
> Much appreciated!
>
> Wuping Xin, PE, PhD
> Chief Technology Officer | Caliper Corporation
> |||||||||||||||||||||||||||||||||||||||||||||||||||||
> 1172 Beacon St, Ste 300 • Newton MA 02461 USA
> Mobile: 617-564-1676 • Main: 617-527-4700
>
> ------ Original Message ------
>  From "Mark Hammond"<mhammond at skippinet.com.au>
> To "Wuping Xin"<oudouxin at gmail.com>;python-win32 at python.org
> Date 3/12/2023 10:54:23 PM
> Subject Re: [python-win32] How to enable events for Python Active
> Scripting?
>
>> It's difficult to know what exactly you mean, but if it is how to use IConnectionPoint etc from Python in general, then you should check out the following files in the distribution:
>>
>> com\win32com\demos\connect.py
>> com\win32com\server\connect.py
>> com\win32com\client\connect.py
>>
>> If it is about the use of these interfaces specifically with ActiveScripting, then you should find win32comext\axscript\test\testHost.py useful. win32comext\axscript\client\framework.py is where the implementation of Active Scripting's event handling is implemented - eg, see the functions Connect, CreateConnections, ConnectEventHandlers etc in that file.
>>
>> HTH,
>>
>> Mark
>>
>> On 13/03/2023 1:05 am, Wuping Xin wrote:
>>> I have a host application that uses Python Active Scripting.   That host application implements IConnectionPoint / IConnectionPointContainers etc, and I am able to set COM event callbacks in C++.
>>>
>>> But I am having a hard time to figure out how to set COM event callback with Python Active Scripting - I bought the book "/Python Programming On Win32, but /it doesn't provide much information about//Python Active Scripting COM events.
>>>
>>> Need help and much appreciate any advice.
>>>
>>> Wu
>>>
>>> _______________________________________________
>>> python-win32 mailing list
>>> python-win32 at python.org
>>> https://mail.python.org/mailman/listinfo/python-win32
> >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20230314/7b22d596/attachment.html>


More information about the python-win32 mailing list