[python-win32] Events from Microsoft Word 97 (events for Word 2000 is ok) - troubles

Wojtek P wojtulek at gmail.com
Wed Jan 16 12:50:48 CET 2008


I have some troubles with events from word97. My application now works great
with Word2000 - but this is another python interface file (from makepy). But
when i try unistall w2k and install w97 i must write another events handler.
And now i have only OnDocumentChange event. Why i don't get any OnQuit
message?  Also when i ran testMSOfficeEvents.py test :|
But in 00020905-0000-0000-C000-000000000046x1033x8x0.py i see:
# Event Handlers
# If you create handlers, they should have the following prototypes:
#    def OnQuit(self):
#    def OnStartup(self):
#    def OnDocumentChange(self):

And another question - how to detect via win32com Word version - its my
self.wordVer variable.
Mayby i must write my own Document class? Please some help with this
problem!
[w.p.]

I use this code (incompleted):

########################
class KwWordEvents: # word2000
########################
  def OnQuit(self):
    print "OnQuit"
    self.seen_events["OnQuit"] = None

  def OnDocumentBeforeSave(self, Doc, SaveAsUI, Cancel):
    print "OnDocumentBeforeSave"
    self.seen_events["OnDocumentBeforeSave"] = None

  def OnDocumentBeforeClose(self, Doc, Cancel):
    print "OnDocumentBeforeClose"
    self.seen_events["OnDocumentBeforeClose"] = None


########################
class KwWordEvents8: # word 97
########################
  def OnQuit(self):
    print "w97 OnQuit"
    self.seen_events["OnQuit"] = None

  def OnStartup(self):
    print "w97 OnStartup"
    self.seen_events["OnStartup"] = None

  def OnDocumentChange(self):
    print "w97 OnDocumentChange"
    self.seen_events["OnDocumentChange"] = None

########################
class KwWord:
########################
  def __init__(self):
     self.wordVer = self.GetWordVer()
     if self.wordVer<=8:
       self.wordApp = win32com.client.DispatchWithEvents("Word.Application",
KwWordEvents8)
     else:
       self.wordApp = win32com.client.DispatchWithEvents("Word.Application",
KwWordEvents)

   def GetWordVer(self):
      ???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080116/c57b81d3/attachment.htm 


More information about the python-win32 mailing list