On June 17, I wrote: >> >> I'd like to go a step beyond getting/setting properties and invoking >>methods and assign a new event handler to the instance >>that's represented by the return value of GetActiveObject().
On June 17, Michael B. Wright wrote: > > If it is simply another layer of abstraction that you require, it might > be easier to just roll your own proxy class. I'm still unsure how I would associate my own event handling methods with an Internet Explorer instance that someone else has created. If my code is present at the creation, this is no problem, as I can create a class of my own (as in __init__.py): class IEEvents: def OnVisible(self, visible): print "Visibility's changed to ", visible Now, I can have DispatchWithEvents() bind up the automation object along with my event handler: ie = DispatchWithEvents("InternetExplorer.Application", IEEvents) Or, I can do it in two steps by creating a subclass of Internet Explorer's existing event handling class (which I can get with getevents()) and overriding the events of interest (also show in __init__.py) and then associating the event handler with an instance of IE. So far, so good. In the __init__.py example, the association between the IE instance and the specialized event handling class is made by passing the IE instance to the event handling class. This works because the IE instance was generated by a call to win32com.client.Dispatch, but it doesn't work with the result of GetActiveObject(): ie = GetActiveObject("InternetExplorer.Application") events = InternetExplorerEvents(ie) # Won't work or even the result of a QI with the IID set to IDispatch on the result of GetActiveObject(): ieDispatch = ie.QueryInterface(pythoncom.IID_IDispatch) events = InternetExplorerEvents(ieDispatch) # Won't work either The result of invoking Dispatch is an IWebBrowser2 object (which means it's also a DispatchBaseClass object). A DispatchBaseClass object has an _oleobj_ attribute, which is of type PyIDispatch. I have a PyIDispatch object, so my question is, how do I create an IWebBrowser2 object from it? Thanks, Kurt _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython