[python-win32] How to use event class ?
Serge Gauthier
gauthier.sg at wanadoo.fr
Mon Jun 9 14:31:53 CEST 2008
Hi,
To develop a interface to a COM library under Boa Constructor and WxPython, Python 2.5, I had to use the makepy utility to generate the classes file.
I show you a part of this file:
class _IPmacDeviceEvents:
"""_IPmacDeviceEvents Interface"""
CLSID = CLSID_Sink = IID('{D1C5C7C8-5E0C-495E-9AAF-85B146DA5F13}')
coclass_clsid = IID('{B544D2BD-354C-456E-9E88-20F71625E7DF}')
_public_methods_ = [] # For COM Server support
_dispid_to_func_ = {
5 : "OnUnsolicited",
3 : "OnError",
4 : "OnInterrupt",
2 : "OnProgress",
1 : "OnMessage",
6 : "OnDataReady",
}
def __init__(self, oobj = None):
if oobj is None:
self._olecp = None
else:
import win32com.server.util
from win32com.server.policy import EventHandlerPolicy
cpc=oobj._oleobj_.QueryInterface(pythoncom.IID_IConnectionPointContainer)
cp=cpc.FindConnectionPoint(self.CLSID_Sink)
cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy))
self._olecp,self._olecp_cookie = cp,cookie
def __del__(self):
try:
self.close()
except pythoncom.com_error:
pass
def close(self):
if self._olecp is not None:
cp,cookie,self._olecp,self._olecp_cookie = self._olecp,self._olecp_cookie,None,None
cp.Unadvise(cookie)
def _query_interface_(self, iid):
import win32com.server.util
if iid==self.CLSID_Sink: return win32com.server.util.wrap(self)
# Event Handlers
# If you create handlers, they should have the following prototypes:
# def OnUnsolicited(self, Device=defaultNamedNotOptArg, Msg=defaultNamedNotOptArg):
# """method Unsolicited"""
# def OnError(self, Device=defaultNamedNotOptArg, FileName=defaultNamedNotOptArg, ErrorID=defaultNamedNotOptArg, LineNum=defaultNamedNotOptArg
# , Line=defaultNamedNotOptArg):
# """method Error"""
# def OnInterrupt(self, Device=defaultNamedNotOptArg, lLevel=defaultNamedNotOptArg):
# """method Interrupt"""
# def OnProgress(self, Device=defaultNamedNotOptArg, dwPercent=defaultNamedNotOptArg):
# """method Progress"""
# def OnMessage(self, Device=defaultNamedNotOptArg, Msg=defaultNamedNotOptArg, bNewLine=defaultNamedNotOptArg):
# """method Message"""
# def OnDataReady(self, Device=defaultNamedNotOptArg):
# """method DataReady"""
;
;
;
from win32com.client import CoClassBaseClass
# This CoClass is known by the name 'PcommServer.PmacDevice.1'
class PmacDevice(CoClassBaseClass): # A CoClass
# PmacDevice Class
CLSID = IID('{B544D2BD-354C-456E-9E88-20F71625E7DF}')
coclass_sources = [
_IPmacDeviceEvents,
]
default_source = _IPmacDeviceEvents
coclass_interfaces = [
IPmacDevice,
]
default_interface = IPmacDevice
I can call PmacDevice() class without problem and everything works well to communicate with the card.
How to use the events managed in the library ?
Do you have a example or tutorial ?
Thanks a lot.
Serge Gauthier
--
J'utilise la version gratuíte de SPAMfighter pour utilisateurs privés.
Ce programme a supprimé1939 d'e-mails spam à ce jour.
Les utilisateurs qui paient n'ont pas ce message dans leurse-mails.
Obtenez la version gratuite de SPAMfighter ici: http://www.spamfighter.com/lfr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080609/379d3dc1/attachment.htm>
More information about the python-win32
mailing list