Hello All;

While I play with pyrc's Events with win32com object, i can't get it work 
as I intended.
Here's the scenario.

On the window machine, I built a server that has win32com services.
and on the Mac machine, I want to access that service and get events from 
server.
I pretty much follow the tutorial in 
http://rpyc.sourceforge.net/tutorial/tut5.html#tut5
I can call COM obj functions, but can't get any event from the "COM modules"
For example in the source, COM event is "DocumentComplete"

In addition ,the execution actually happened after the client connection is 
closed (conn.close()), don't know why.


any idea?

Thanks in advance.


Best,
BS


[On the server side (Windows), "ThreadComS.py"]

*import* rpyc
> *from* threading *import* Thread
>
> *import* win32com 
> *import* win32com.client
> *import* pythoncom 
> *import* time
>
>
> *class* *IEService*(rpyc.Service):
>     
>     *class* *exposed_IESession*(object):
>         *def* __init__(*self*,callback, interval = 1):
>             *self*.callback = rpyc.async(callback)   # create an async
>  callback
>             *self*.interval=interval
>             *self*.active = *True
> *            *self*.pythoncom=pythoncom
>             *class* *IESessionEvents*(object): 
>                 *def* OnDocumentComplete(*self*, pDisp, URL):   
>                     *print* "OnDocumentComplete event processed", URL   
>             *self*.IESessionEvents=IESessionEvents
>             
>             
>             *self*.pythoncom.CoInitialize()
> #            pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
>             *self*.ie = win32com.client.DispatchWithEvents
> ("InternetExplorer.Application", 
>                                                                 *self*
> .IESessionEvents)
> #            pythoncom.CoUninitialize()
>             *self*.thread = Thread(target = *self*.PumpMsg)
>             *self*.thread.start()
>             
>         *def* exposed_Stop(*self*):
>             *self*.active = *False
> *            
>         *def* exposed_Go(*self*,URL):
>             *print* "GO: ", URL 
>             
>             *self*.ie.Visible = 1
>             *self*.ie.Navigate(URL)
>                 
>         *def* PumpMsg(*self*):
>             
>             *while* *self*.active:
>                 retval=*self*.pythoncom.PumpWaitingMessages()
>                 *print* 1,retval
>                 time.sleep(*self*.interval)
>                 
>     
> *if* __name__ == "__main__":
>     *from* rpyc.utils.server *import* ThreadedServer
>     ThreadedServer(IEService, port = 18871).start()
>     
>         
>     

    

[On the client side (Mac), "ThreadComC.py"]        

> *import* rpyc
> *import* time
> conn = rpyc.connect("ge.kaist.ac.kr", 18871)
> bgsrv = rpyc.BgServingThread(conn)  # creates a bg thread to process 
> incoming events
> *def* on_Session(args):
>     *print* "YES!"
>     *print* args[1]
>     
>     
> ieCOM = conn.root.IESession(on_Session,0.5)
> ieCOM.Go('www.google.com')
> *print* "waiting"
> time.sleep(3)
> *print* "done"
> ieCOM.Stop()
> bgsrv.stop()
> conn.close()
>

    

Reply via email to