pywin32
pywin32 copied to clipboard
Allow detaching events from a COM client
Type: Feature
Expected behavior
Detach a specific event after attaching it to a COM object.
Actual behavior
Not supported
Steps to reproduce the problem
from win32com.client import WithEvents
# ...
class ClassOfHandlers():
def OnStart(self):
print("Start observed")
class AnotherClassOfHandlers():
def OnStart(self):
print("Start observed from another")
handler = WithEvents(client, ClassOfHandlers)
# ...
WithEvents(client, AnotherClassOfHandlers)
# ...
# Deregister `ClassOfHandlers`
Notes:
- There's a workaround of having a list in the ClassOfHandlers that we manipulate, which I described in this StackOverflow answer, but it is of course not ideal.
- It would be great to cover the scenario when
WithEvents()is needed to be executed from inside the thread runnable, to satisfy the constraint for thePumpWaitingMessages()of havingWithEvents()called from the same thread, while supporting this event detaching feature. - Further details are [found here(https://stackoverflow.com/q/73864764/2730737).
- IConnectionPoint::Unadvise() may be required to be used in the background based on DS_London's suggestion.
Version of Python and pywin32
Python: 3.10.0 pywin32: 304
How to have events for Python Active Scripting? I searched everywhere but ended up here. Any hints?
@wxinix-2022 I'd suggest opening a support request in Discussions or on the python-win32 mailing list, describing your complete use case and what you already tried.