[python-win32] attaching an event handler to already created object

2011-01-30 Thread Patricio Stegmann

Hello,

I am trying to attach an event handler to a running pythoncom object.
The problem is I am not instantiating it via Dispatch. Basically I generated 
the python wrapper code (via makepy), and renamed it to a specific name, say, 
SignpadActivex.

The code is the following:
"""
import os, sys
import win32com
import SignpadActivex

class MyEvents():
def OnPenDown(self):
print 'evt pendown'
self.m__signpad.SetEventEnableMask(7)

def OnPenUp(self):
print 'evt penup'
self.m__signpad.SetEventEnableMask(7)

def OnPenPoint(self):
print 'pen point'
self.m__signpad.SetEventEnableMask(7)

class SignPad():
def __init__(self):
self.m__signpad = None

def createControl(self):
self.m__signpad = TopazSigPlus.SigPlus()
print dir(self.m__signpad)
win32com.client.WithEvents(self.m__signpad, MyEvents)
self.m__signpad.SetEventEnableMask(7)

if __name__ == '__main__':
l__obj = None
l__resp = raw_input('enter option ...:')
while l__resp != 'x':
if l__resp == 'c':
l__obj = SignPad()
l__obj.createControl()
l__resp = raw_input('enter option ...:')
"""

Because I do instantiate this way, I dont have the DispatchWithEvents method. 
So I dont know how to add MyEvents event handler class managing the control's 
events.

>From the generated python code I got this:
"""
# This CoClass is known by the name 'SIGPLUS.SigPlusCtrl.1'
class SigPlus(CoClassBaseClass): # A CoClass
# SigPlus Control
CLSID = IID('{69A40DA3-4D42-11D0-86B0-C025864A}')
coclass_sources = [
_DSigPlusEvents,
]
default_source = _DSigPlusEvents
coclass_interfaces = [
_DSigPlus,
]
default_interface = _DSigPlus
"""

So basically how do I attach an event handler to that running object ?

Thank you !

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


Re: [python-win32] attaching an event handler to already created object

2011-01-30 Thread Roger Upole
You can pass an existing IDispatch object to DispatchWithEvents
as the first arg in place of a clsid.

 Roger



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


Re: [python-win32] attaching an event handler to already created object

2011-01-30 Thread Patricio Eduardo Stegmann
Hi Roger,

could you please be a bit more specific ?


- Original message -
> You can pass an existing IDispatch object to DispatchWithEvents
> as the first arg in place of a clsid.
> 
>                   Roger
> 
> 
> 
> ___
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 

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


Re: [python-win32] attaching an event handler to already created object

2011-01-30 Thread Patricio Eduardo Stegmann
Hi Roger,

could you please be a bit more specific ?


- Original message -
> You can pass an existing IDispatch object to DispatchWithEvents
> as the first arg in place of a clsid.
> 
>                   Roger
> 
> 
> 
> ___
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 

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


Re: [python-win32] attaching an event handler to alreadycreated object

2011-01-30 Thread Roger Upole
Try replacing

self.m__signpad = TopazSigPlus.SigPlus()

with

self.m__signpad = win32com.client.DispatchWithEvents(TopazSigPlus.SigPlus(), 
MyEvents)

  Roger

Patricio Eduardo Stegmann wrote:
> Hi Roger,
>
> could you please be a bit more specific ?
>
>
> - Original message -
>> You can pass an existing IDispatch object to DispatchWithEvents
>> as the first arg in place of a clsid.
>>
>>   Roger
>>
>>
>>
>> ___
>> python-win32 mailing list
>> python-win32@python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>
> ___
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 



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