473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

pythoncom and IDispatch

Hello. I got a little problem while using pythoncom to automate IE; for
some reason, changing the 'selectedIndex' on an instance of
IHTMLSelectElement doesn't fire the 'onchange' event (I guess this is a
bug in mshtml).

So, I tried to get the 'onchange' event handler and call it myself.
According to the docs, this is a simple IDispatch implementation and
calling Invoke() should do the trick; I actually have a working example
of this in Delphi.

But I can't manage to get it work in Python; the following code
idisp = pythoncom.WrapObject(elt.onchange)
idisp.Invoke(pythoncom.DISPID_VALUE,
0x400, # LOCALE_USER_DEFAULT
pythoncom.DISPATCH_METHOD,
False)

fails with an AttributeError:

Traceback (most recent call last):

File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line
283, in _
Invoke_

return self._invoke_(dispid, lcid, wFlags, args)

File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line
288, in _
invoke_

return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None,
None)
File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line
581, in _
invokeex_

return func(*args)

File "ietest.py", line 44, in OnDocumentComplete

self.deleg.onDocumentComplete(Dispatch(disp), url)

File "ietest.py", line 122, in onDocumentComplete

self.current.onDocumentComplete(self, browser, url)

File "ietest.py", line 141, in onDocumentComplete

sink.nextStep()

File "ietest.py", line 96, in nextStep

self.current.onStart(self)

File "ietest.py", line 191, in onStart

False)

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Python
COM Serve
r Internal Error', 'Unexpected Python Error: exceptions.AttributeError:
_Invoke_
', None, 0, -2147467259), None)
Did I miss something ?

TIA
May 15 '06 #1
1 3706

"fraca7" <fr****@free.fr> wrote in message news:44**********************@news.free.fr...
Hello. I got a little problem while using pythoncom to automate IE; for some reason, changing the 'selectedIndex' on an
instance of IHTMLSelectElement doesn't fire the 'onchange' event (I guess this is a bug in mshtml).
As I understand it, this was done as a security measure to foil script
exploits.
So, I tried to get the 'onchange' event handler and call it myself. According to the docs, this is a simple IDispatch
implementation and calling Invoke() should do the trick; I actually have a working example of this in Delphi.

But I can't manage to get it work in Python; the following code
idisp = pythoncom.WrapObject(elt.onchange)
idisp.Invoke(pythoncom.DISPID_VALUE,
0x400, # LOCALE_USER_DEFAULT
pythoncom.DISPATCH_METHOD,
False)

fails with an AttributeError:


You can access the underlying IDispatch using the
_oleobj_ property, ie elt.onchange._oleobj_.Invoke(......)

Alternately, you can also use FireEvent, which would look
something like this (untested):
elt.FireEvent('onchange',elt.onchange)
Roger

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
May 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul | last post by:
Hi I'm trying to build a standalone COM exe server using Python 2.2 + Mark Hammond's windows extensions + Py2Exe. I've built the example linked on the Py2Exe homepage and get this error when...
2
by: John J. Lee | last post by:
Dear, I have problems when I get the IDispatch with pythoncom.connect(). When I called the 'Excel.Application' with it, it worked. (At least I can see the pythoncom.connect() is working for the...
5
by: Brian Hlubocky | last post by:
I'm have a fairly simple (in terms of COM) python program that pulls info from an Access database and creates Outlook contacts from that information. It uses wxPython for gui and works without...
0
by: Olaf Meding | last post by:
How does Python (version 23 on Windows) know what to import? I could not find a file or directory named "pythoncom". import pythoncom help(pythoncom) FILE c:\windows\system32\pythoncom23.dll...
0
by: UlleAcki | last post by:
Hi, in my Python program I have to use a COM-Server. One method of the COM class needs a SAFEARRAY of a special type as parameter. Trying to create such an array and calling the method results in...
0
by: Paul Keating | last post by:
I want my Python COM object to do early binding. I have this working for methods that return floats and dates and variants, but not for methods that return COM objects. They are returning IDispatch...
1
by: Manu | last post by:
Hi, I have a COM component server that just exposes the IDispatch interface but when you use it in a VB app you can access other method. I think the way to access the other methods( as does it...
6
by: gcmartijn | last post by:
H! I using a script that opens a internet page in a small window (what I can control) In XP everything was working fine, but now I'm using Vista with IE7 and this is what happends now: First...
0
by: Gabriel Genellina | last post by:
En Wed, 27 Aug 2008 21:17:22 -0300, Vistro <vistro@vistro.netescribi�: Reinstalling the pywin32 package should fix that, I presume. In fact that __import_whatever function does a rather...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.