sorry. I forgot the attachment.

Christian

import unittest
import comtypes.client

import wx

class EventHandler(object):
    """Instances are called when the COM object fires events."""
    def __init__(self, view, name):
        self.view = view
        self.name = name

    def __call__(self, this, *args, **kw):
        self.view.write(unicode("Event %s fired" % self.name, args, kw))

class Events(object):
    """Provide handlers for COM events."""
    def __init__(self, view):
        self.view = view
        self._event_names = set()

    def __getattr__(self, name):
        if name.startswith("__") and name.endswith("__"):
            raise AttributeError(name)
        self.view.write("# event found: %s"%name)
        self._event_names.add(name)
        return EventHandler(self.view, name)

class Panel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)
        
        self.txt = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE|wx.TE_READONLY)
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.txt, 1 ,wx.EXPAND)
        self.SetSizer(box)
        self.Layout()
        
    def write(self, txt):
        self.txt.SetValue(self.txt.GetValue()+unicode(txt)+'\n')

class Listener(object):
    def __init__(self):
        app = wx.PySimpleApp(0)
        self.f = wx.Frame(None, -1, 'listener')
        self.view = Panel(self.f)
            
        self.com_init()
        
        self.f.Show()
        app.MainLoop()

    def com_init(self):
        sink = Events(self.view)
        self.o = comtypes.client.CreateObject("Outlook.Application", sink = 
sink)


if __name__ == "__main__":
    Listener()
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to