Back to index

plone3  3.1.7
powerpnt.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
00004 # All Rights Reserved.
00005 # 
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00008 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00009 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00010 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00011 # FOR A PARTICULAR PURPOSE.
00012 # 
00013 ##############################################################################
00014 """External Editor MSPowerpoint Plugin
00015 
00016 $Id: powerpnt.py 67472 2003-03-31 22:26:18Z caseman $
00017 """
00018 
00019 import os
00020 from time import sleep
00021 import win32com
00022 from win32com import client # Initialize Client module
00023 
00024 class EditorProcess:
00025     def __init__(self, file):
00026         """Launch editor process"""
00027         ppt = win32com.client.Dispatch('Powerpoint.Application')
00028         ppt.Visible = 1
00029         # Try to open the file, keep retrying until we succeed or timeout
00030         i = 0
00031         timeout = 45
00032         while i < timeout:
00033             try:
00034                 ppt.Presentations.Open(file)
00035             except:
00036                 raise
00037                 i += 1
00038                 if i >= timeout:
00039                     raise RuntimeError('Could not launch Powerpoint.')
00040                 sleep(1)
00041             else:
00042                 break
00043         self.powerpntapp = ppt
00044         self.file = file
00045         
00046     def wait(self, timeout):
00047         """Wait for editor to exit or until timeout"""
00048         sleep(timeout)
00049             
00050     def isAlive(self):
00051         """Returns true if the editor process is still alive"""
00052         try:
00053             self.powerpntapp.Presentations(self.file)
00054         except:
00055             return 0
00056         else:
00057             return 1
00058 
00059 def test():
00060     import os
00061     from time import sleep
00062     from tempfile import mktemp
00063     fn = 'E:\Documents and Settings\Default User\Templates\powerpnt.ppt'
00064     print 'Connecting to Powerpoint...'
00065     f = EditorProcess(fn)
00066     print 'Attached to %s %s' % (`f.powerpntapp`, f.powerpntapp.Version)
00067     print ('%s is open...' % fn),
00068     if f.isAlive():
00069         print 'yes'
00070         print 'Test Passed.'
00071     else:
00072         print 'no'
00073         print 'Test Failed.'
00074     
00075 if __name__ == '__main__':
00076     test()