[python-win32] COM Events
Phil Hornby
phil.hornby at accutest.co.uk
Fri Jul 9 11:39:36 CEST 2004
Great that seems to work - but I only get my parent object in this way:
agent = win32com.client.DispatchWithEvents ("Agent.Control.2", AgentEvents)
What if I then get other objects as properties of this object -
E.g.
"""
SomethingElse = agent.Another
"""
And this object/interface has events too...
In VB it would be something like:
"""
Dim WithEvents gCanApp As CANalyzer.Application
Dim WithEvents gCanMeasurement As CANalyzer.Measurement
Set gCanApp = New Application
Set gCanMeasurement = gCanApp.Measurement
"""
I have tried to do something similar like:
"""
CANalyzer = win32com.client.DispatchWithEvents('CANalyzer.Application',
CANalyzerEvents)
measurement = win32com.client.DispatchWithEvents('CANalyzer.Measurement',
MeasurementEvents)
measurement = CANalyzer.Measurement
"""
But I get a claim that I have an invalid class string - if I look at the
typelib that I am working with and it contains both interfaces - if I simply
have some code like:
"""
CANalyzer = win32com.client.DispatchWithEvents('CANalyzer.Application',
CANalyzerEvents)
measurement = CANalyzer.Measurement
"""
Then I get 'some' of the events from the CANalyzerEvents object - but the
ones I don't get are ones I can understand NOT getting - and I can use the
measurement interface in the way I would like EXCEPT I don't get any events.
Any ideas?
--
Phil
> -----Original Message-----
> From: Tim Golden [mailto:tim.golden at viacom-outdoor.co.uk]
> Sent: Friday, July 09, 2004 9:15 AM
> To: 'Phil Hornby'; Python Win32
> Subject: RE: [python-win32] COM Events
>
> | In VB one way to write the code would be something like this:
> |
> | """
> | Dim WithEvents gMyApp As XYZ.Application
> |
> | Private Sub gMyApp_OnQuit()
> | 'create application specific OnQuit event handler here..
> | End Sub
> | """
> |
> | Where the event handler HAS to be called '<object>_<event>'
> |
> | I can obviously make sure that I have a function with the
> correct name
> | - but HOW do I do the WithEvents bit!!??
>
> You want to use DispatchWithEvents. You use it like the
> normal Dispatch, but pass in additionally a class
> (*not* an instance) which contains methods corresponding to
> the events you're interested in.
>
> The following code fragment should illustrate what I mean
> (from when I was playing around with Microsoft Agent):
>
> <code>
>
> class AgentEvents:
> def OnActivateInput (self, character_id):
> this_agent = active_agents.get (character_id)
> if this_agent: this_agent.on_activate_input ()
>
> def OnActiveClientChange (self, character_id, active):
> this_agent = active_agents.get (character_id)
> if this_agent: this_agent.on_activate_client_change (active)
>
> def OnAgentPropertyChange (self):
> pass
>
> agent = win32com.client.DispatchWithEvents
> ("Agent.Control.2", AgentEvents)
>
> </code>
>
> TJG
>
>
> ______________________________________________________________
> __________
> This e-mail has been scanned for all viruses by Star
> Internet. The service is powered by MessageLabs. For more
> information on a proactive anti-virus service working around
> the clock, around the globe, visit:
> http://www.star.net.uk
> ______________________________________________________________
> __________
>
More information about the Python-win32
mailing list