Re: How to receive events (eg. user mouse clicks) from IE



<cal_2pac@xxxxxxxxx> wrote in message
news:1116604655.431664.261430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Thanks for the response again. The solution is pretty close but not yet
> complete
> This is what I observed.
> a) I tried to use the delay mechanism as suggested below
> ie.
> ie.Navigate('www.google.com')
> while ie.ReadyState !- 4
> time.sleep(0.5)
>
> d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events)
>
> IE *fails* to load the webpage

Thought this was quite curious so tried it myself (on Python 2.3 Win2k
machine). Put in some timing conditions and the problem is not that it
fails to load, but that it takes really long (min time during tests = 60
secs
, maximum time 580 secs).

Tried using just WithEvents, same problem. The problem seems to
lie with the call to ie.ReadyState while trapping events. 2 things lead me
to believe this...
1) Interrupting the Python code after the browser window opens, results in
the window
finishing and loading the URL immediately with no problems.
2) Running the code with just Dispatch (no events) and it works fine (< 1
sec).

All I can think is that each call to ie.ReadyState triggers some internal
event which hogs resources to process.

It seems like the problem is with IE Events only... so a possible workaround
(if all you need is the Doc events) is the following:
-------------------------
import win32com.client

class Doc_Events:
def Ononactivate(self):
print 'onactivate:', doc.location.href
def Ononclick(self):
print 'onclick fired.'
def Ononreadystatechange(self):
print 'onreadystatechange:', doc.readyState

ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 1
ie.Navigate('http://www.google.com')

while ie.ReadyState != 4:
time.sleep(1)

doc = ie.Document
doc_events = win32com.client.WithEvents(doc, Doc_Events)
# OR can use following:
# doc = win32com.client.DispatchWithEvents(ie.Document, Doc_Events)

while ie.ReadyState != 4 and doc.readyState != "complete":
# readystate is case sensitive and differs for ie (R) and doc (r)
# ie.ReadyState: 0=uninitialised; 1=loading; 2=loaded;
# 3=interactive; 4=complete
time.sleep(1)
-------------------------

HTH,


.



Relevant Pages

  • Re: is there a problem on this simple code
    ... if i put my timer control inside the thread, ... def someThreadHere() ... >>> while theres no error in the output, there is also no response from ... does not wait for response data to catch up ...
    (comp.lang.python)
  • Re: [RCR] abstract method in Ruby
    ... def initialize ... it expects a response to messages:foo and:bar with any or no params ...
    (comp.lang.ruby)
  • Re: XMLRPC Problem
    ... class ConversationSavingClient < Client ... def initialize ... response = super ...
    (comp.lang.ruby)
  • Re: [RCR] abstract method in Ruby
    ... it expects a response to messages:foo and:bar with any or no params ... should_respond_to just logs warning if msg not responded to properly ... def abstract_method m ...
    (comp.lang.ruby)
  • Re: [wxPython-users] Problem in threading
    ... My response is at the end. ... My applications has a GUI that has some button. ... def OnDelete: ... self.sender.send#Send the XML string ...
    (comp.lang.python)