Hi Mark,

- "you would define a function called "ObjectName_EventName"

Thank you again! This is valuable info.  In the following pseudo-code,  the 
Host COM Object implements TWO Events interfaces.  How should I defined 
relevant event sink functions?  For example, if the object instance is named 
"MyHostObject",  should I just directly define the following event sink 
functions?

MyHostObject.Do_A_Event()
MyHostObject.Do_B_Event()
MyHostObject.Do_C_Event()
MyHostObject.Do_D_Event()


interface _IMondayEvents
{
        Do_A_Event;
        Do_B_event;
}

interface _ITuesdayEvents
{
        Do_C_Event;
        Do_D_event;
}

    coclass HostApplication
    {
        [default] interface IHostApplication;
        [source] interface _IMondayEvents;
        [source] interface _ITuesdayEvents;
    };


------ Original Message ------
From "Mark Hammond" 
<mhamm...@skippinet.com.au<mailto:mhamm...@skippinet.com.au>>
To "Wuping Xin" <wup...@caliper.com<mailto:wup...@caliper.com>>
Cc "Python-win32@python.org<mailto:Python-win32@python.org>" 
<Python-win32@python.org<mailto:Python-win32@python.org>>
Date 3/13/2023 8:45:37 PM
Subject Re: [python-win32] How to enable events for Python Active Scripting?

WARNING EXTERNAL EMAIL


[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"
<mhamm...@skippinet.com.au><mailto:mhamm...@skippinet.com.au>
To "Wuping Xin" <oudou...@gmail.com><mailto:oudou...@gmail.com>; 
python-win32@python.org<mailto:python-win32@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@python.org<mailto:python-win32@python.org>
https://mail.python.org/mailman/listinfo/python-win32<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-win32&data=05%7C01%7Cwuping%40caliper.com%7C8a2f2cde07f1444e64bd08db2425717d%7Cf6e1fbdcbea34b468ff6deddc0d9eabd%7C1%7C0%7C638143515469156931%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Mt8TOaPoNrTYtQgb7j7Y0yfGWVEJaBlCi2nrEHaRHWo%3D&reserved=0>


>

_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to