[python-win32] DispatchWithEvents call

Neil Benn Neil.Benn at cenix-bioscience.com
Mon Dec 13 10:32:58 CET 2004


Hello,
  
I'm trying to use win32com to access a COM object with Events. After
      some searching I discovered the call to
      win32com.client.DispatchWithEvent can be used - passing a class
      with the method signatures for each event for thrown by the
      ActiveX component.

However I'm getting a strange exception from somewhere inside the
  win32com code and can't find a great deal of documentation on this
  method on the web. Could anyone help me out as to what's going on. The
  code is beneath, followed by the exception that occurrs, if I make a
  call to dispatch the code is working.

<code>

import win32com.client

class ScannerEvents(object):
    
    bLoaded = False
    
    def DuplicateFound(self, nCount, strDuplicates):
        print "Duplicate Found"
        
    def ReadComplete(self):
        print "ReadComplete"
            
    def UIClosing(self):
        print "UIClosing"

    def UILoaded(self):
        print "UILoaded"
        bLoaded = True
            
class Scanner(object):
    
    objVM = None
    objEvents = None
    
    def init(self):
        print "init"
        objEvents = ScannerEvents()
        print 'calling LoadUI'
        #objVM = win32com.client.Dispatch("VisionMate96.cVisionMate96")
objVM = win32com.client.DispatchWithEvents("VisionMate96.cVisionMate96",
        objEvents)
        objVM.LoadUI()
        print 'Called LoadUI'
        
if __name__ == '__main__':
    objScanner = Scanner()
    objScanner.init()

</code>
 
<stacktrace>
>>> ## working on region in file c:\Documents and Settings\Neil\My
>>> Documents\Python stuff\python-4ZAXnv.py...
init
caling LoadUI
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
File "c:\Documents and Settings\Neil\My Documents\Python
  stuff\python-4ZAXnv.py", line 33, in ?
    objScanner.init()
File "c:\Documents and Settings\Neil\My Documents\Python
  stuff\python-4ZAXnv.py", line 28, in init
objVM = win32com.client.DispatchWithEvents("VisionMate96.cVisionMate96",
    objEvents)
File "C:\Python23\Lib\site-packages\win32com\client\__init__.py", line
  264, in DispatchWithEvents
result_class = new.classobj("COMEventClass", (disp_class, events_class,
    user_event_class), {"__setattr__" : _event_setattr_})
TypeError: default __new__ takes no parameters
</stacktrace>

FYI - the component is an ActiveX control to control a flat bed scanner
    which then scans a load of plastic tubes containing 2D barcodes,
    decodes them and returns the barcodes of the tubes.

    Thanks, for any and all help.

Cheers,

Neil

Cenix Bioscience GmbH



More information about the Python-win32 mailing list