import unittest import comtypes.client class EventHandler(object): """Instances are called when the COM object fires events.""" def __init__(self, name): self.name = name def __call__(self, this, *args, **kw): print "Event %s fired" % self.name, args, kw class Events(object): """Provide handlers for COM events.""" def __init__(self): self._event_names = set() def __getattr__(self, name): if name.startswith("__") and name.endswith("__"): raise AttributeError(name) print "# event found:", name self._event_names.add(name) return EventHandler(name) class EventsTest(unittest.TestCase): def test(self): sink = Events() o = comtypes.client.CreateObject("InternetExplorer.Application", sink = sink) from comtypes.gen.SHDocVw import IWebBrowser print print "Default interface", o print "IWebBrowser interface", o.QueryInterface(IWebBrowser) o.Visible = True o.Visible = False o.Quit() if __name__ == "__main__": unittest.main()