[python-win32] Greetings and win32 com events question
Robert Kaplan
belovedbob at greennet.net
Wed Jan 26 17:42:59 CET 2005
Hi,
I'm new to the mailing, so greetings all!
I'm working on an application try to respond to events in Microsoft
Access using Python and win32com. However, I'm having trouble in
setting up the event handlers. I can think of 2 approaches both of
which yield win32com errors.
First is the approach used the MSOfficeEvents.py test program. The
problem is that the events to be picked up are not on the Application
object but on a Form object created from it.
class AccessEvents
def OnActivate(self):
print "Hello from Access"
return 1
<snip>
self. ac = Dispatch ("Access.Application")
self. db = self. ac. NewCurrentDatabase ("d:\\pyhack\\foo")
self. fm = self. ac. CreateForm ()
self. ac. Visible = true
self. fm = DispatchWithEvents (self. fm, AcEvents)
blows out with
self. fm = DispatchWithEvents (self. fm, AcEvents)
File "D:\PYTHON22\Lib\site-packages\win32com\client\__init__.py", line
258, in
DispatchWithEvents
clsid = disp_class.CLSID
AttributeError: 'NoneType' object has no attribute 'CLSID'.
I also tried a variety of string arguments, but all of those also
yielded an invalid class id error.
The other approach is more Visual Basic like:
self. ac = Dispatch ("Access.Application")
self. db = self. ac. NewCurrentDatabase ("d:\\pyhack\\foo")
self. fm = self. ac. CreateForm ()
self. ac. Visible = true
self. ev = AcEvents ()
self. fm. OnActivate = self. ev. OnActivate
this couldn't set the OnActivate attribute with the following error.
File "D:\pyhack\1\Bob.py", line 132, in DoAccess
self. fm. OnActivate = self. ev. OnActivate
File "D:\PYTHON22\Lib\site-packages\win32com\client\__init__.py", line
503, in
__setattr__
d.__setattr__(attr, value)
File "D:\PYTHON22\Lib\site-packages\win32com\client\__init__.py", line
463, in
__setattr__
self._oleobj_.Invoke(*(args + (value,) + defArgs))
TypeError: Objects of type 'instance method' can not be converted to a
COM VARIA
NT
Anyone know how to do this, either strategy is fine.
Thanks
Robert Kaplan
More information about the Python-win32
mailing list