[python-win32] Dispatches With Events on COM Object
Neil Benn
benn at cenix-bioscience.com
Wed Aug 2 14:22:01 CEST 2006
Hello,
I am trying to use PythonCOM to interact with a provided
proprietary COM object. The Object consists of three dispatch interfaces:
IApplication
IApplicationEvents
IDocumentEvents
This can be accessed using the CoBaseClass by ProgID
'OpalControl.Applcation' - so far so good. The first thing I do is to
run the following code:
import win32com.client
import time
objCybio = win32com.client.Dispatch('OpalControl.Application', CybioEvents)
objCybio.ConfigFile = r"C:\CyBio Software\Config\opalctrl.ini"
objCybio.Config = "CyBi-Well"
objCybio.visible = True
objCybio.OpenDocument(r'C:\testscript.igl', True)
time.sleep(2)
objCybio.CloseDocument(r'C:\testscript.igl', True)
objCybio = None
This works fine and it does what I expect, so the next thing to do
is to try and write something to get the events:
import win32com.client
import time
import win32com.client.gencache
class CybioEvents(object):
def __init__(self):
super(CybioEvents, self).__init__()
def onCommand(pstrTitle, pstrParam):
print 'OnCommand\n', pstrTitle,'\n', pstrParam
objCybio = win32com.client.DispatchWithEvents('OpalControl.Application',
CybioEvents)
objCybio.ConfigFile = r"C:\CyBio Software\Config\opalctrl.ini"
objCybio.Config = "CyBi-Well"
objCybio.visible = True
objCybio.OpenDocument(r'C:\testscript.igl', True)
time.sleep(2)
objCybio.CloseDocument(r'C:\testscript.igl', True)
objCybio = None
When I run this, I get the following error:
Traceback (most recent call last):
File "C:\Program
Files\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\benn\Desktop\cybio test.py", line 9, in ?
objCybio =
win32com.client.DispatchWithEvents("OpalControl.Application", CybioEvents)
File "C:\Program
Files\Python24\Lib\site-packages\win32com\client\__init__.py", line 254,
in DispatchWithEvents
raise TypeError, "This COM object can not automate the makepy
process - please run makepy manually for this object"
TypeError: This COM object can not automate the makepy process - please
run makepy manually for this object
So no probs, using the makepy utility in PythonWin (I'll automate
this later ;-) ) I generate the required stubs and a file does appear
which seems to be OK (contains the correct GUIDs and interfaces and so
on). Running this again, I get :
Traceback (most recent call last):
File "C:\Program
Files\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\benn\Desktop\cybio test.py", line 9, in ?
objCybio =
win32com.client.DispatchWithEvents("OpalControl.Application", CybioEvents)
File "C:\Program
Files\Python24\Lib\site-packages\win32com\client\__init__.py", line 254,
in DispatchWithEvents
raise TypeError, "This COM object can not automate the makepy
process - please run makepy manually for this object"
TypeError: This COM object can not automate the makepy process - please
run makepy manually for this object
Basically the same as above, I've checked this COM object out with
VB and it works fine - no probs. In addition looking at the stub file
in the cache in gen_py, the class has not been compiled to a pyc file
(I'm assuming that it should be here) so it seems like it is not even
finding this - although that is a guess.
I've also tried using the GUID to get hold of the CoBaseClass using
the GUID but I get the same error, unfortunately I cannot give you the
COM object as it is dongle protected and therefore will not run. I can
attach the generated file from makepy but I won't do that as yet because
it is relatively big.
Can anyone shed any light as to how I can track down this problem?
Thanks in advance for your help.
Cheers,
Neil
--
Neil Benn MSc
Head of Automation
Cenix BioScience GmbH
Tatzberg 47
01307 Dresden
Germany
http://wwww.cenix-bioscience.com
More information about the Python-win32
mailing list