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

2023-03-13 Thread Wuping Xin via python-win32
Thank you again Mark.

In framework.py, Line 223 - Line 235, I see that it only searches for [source, 
default] interface on the coclass.  That means,  multiple event interface is 
NOT supported for now.

I think I'll have to use "win32com.client.connect.SimpleConnection()" to 
manually create the Source/EventSink connection.

Wuping


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

WARNING EXTERNAL EMAIL


IIRC, each of these objects is a "named item" - so whatever name you use when 
you call AddNamedItem() is the prefix and the suffix is the name of the 
function on the event interface. I'm really not sure how multiple event 
interfaces are supported, if at all.

Cheers,

Mark



On 14/03/2023 1:12 pm, Wuping Xin wrote:
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" 
mailto:mhamm...@skippinet.com.au>>
To "Wuping Xin" mailto:wup...@caliper.com>>
Cc "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"

To "Wuping Xin" ; 
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. 

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

2023-03-13 Thread Mark Hammond

Feel free to put a PR up!

Cheers,

Mark

On 14/03/2023 3:10 pm, Wuping Xin wrote:

Thank you again Mark.

In framework.py, Line 223 - Line 235, I see that it only searches for 
[source, default] interface on the coclass.  That means,  multiple 
event interface is NOT supported for now.


I think I'll have to use "win32com.client.connect.SimpleConnection()" 
to manually create the Source/EventSink connection.


Wuping


-- Original Message --
From "Mark Hammond" 
To "Wuping Xin" 
Cc "Python-win32@python.org" 
Date 3/13/2023 10:55:03 PM
Subject Re: [python-win32] How to enable events for Python Active 
Scripting?



*WARNING EXTERNAL EMAIL *



IIRC, each of these objects is a "named item" - so whatever name you 
use when you call AddNamedItem() is the prefix and the suffix is the 
name of the function on the event interface. I'm really not sure how 
multiple event interfaces are supported, if at all.


Cheers,

Mark



On 14/03/2023 1:12 pm, Wuping Xin wrote:

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" 
To "Wuping Xin" 
Cc "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"

To "Wuping Xin";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 

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

2023-03-13 Thread Mark Hammond
IIRC, each of these objects is a "named item" - so whatever name you use 
when you call AddNamedItem() is the prefix and the suffix is the name of 
the function on the event interface. I'm really not sure how multiple 
event interfaces are supported, if at all.


Cheers,

Mark



On 14/03/2023 1:12 pm, Wuping Xin wrote:

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" 
To "Wuping Xin" 
Cc "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"

To "Wuping Xin";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
https://mail.python.org/mailman/listinfo/python-win32

>




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

2023-03-13 Thread Wuping Xin via python-win32
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" 
mailto:mhamm...@skippinet.com.au>>
To "Wuping Xin" mailto:wup...@caliper.com>>
Cc "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"

To "Wuping Xin" ; 
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

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

2023-03-13 Thread Mark Hammond

[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"
To "Wuping Xin";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
https://mail.python.org/mailman/listinfo/python-win32

>


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


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

2023-03-13 Thread Wuping Xin

HI Mark,

Thank you very much for the helpful information.

I was trying to connect Event-handlers implemented inside Python Active 
Script to EventSink at the Host App side.


But I cannot figure out how

I'll take a look at the files you advised.

Thank you again.

Wu




-- Original Message --

From "Mark Hammond" 

To "Wuping Xin" ; 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
https://mail.python.org/mailman/listinfo/python-win32



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