[Zope-CVS] CVS: Products/ExternalEditor/Plugins - msohtmed.py:1.1 __init__.py:1.3 excel.py:1.2 photoshp.py:1.2 powerpnt.py:1.2 winword.py:1.3

Casey Duncan casey@zope.com
Mon, 31 Mar 2003 17:26:49 -0500


Update of /cvs-repository/Products/ExternalEditor/Plugins
In directory cvs.zope.org:/tmp/cvs-serv18730/Plugins

Modified Files:
	__init__.py excel.py photoshp.py powerpnt.py winword.py 
Added Files:
	msohtmed.py 
Log Message:
Changes for 0.7 release
Fix visibility problem for ms office
Add plugin to handle msohtmed with word
Update version and docs


=== Added File Products/ExternalEditor/Plugins/msohtmed.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""External Editor msohtmed Plugin

$Id: msohtmed.py,v 1.1 2003/03/31 22:26:18 caseman Exp $
"""

import os
from time import sleep
import win32com
from win32com import client # Initialize Client module

class EditorProcess:
    def __init__(self, file):
        """Launch editor process"""
        word = win32com.client.Dispatch('Word.Application')
        # Try to open the file, keep retrying until we succeed or timeout
        i = 0
        timeout = 45
        while i < timeout:
            try:
                word.Documents.Open(file, Format=8)
		print 'Opening...'
            except:
                i += 1
                if i >= timeout:
                    raise RuntimeError('Could not launch Word.')
                sleep(1)
            else:
                break
        word.Visible = 1
        self.wordapp = word
        self.file = file
        
    def wait(self, timeout):
        """Wait for editor to exit or until timeout"""
        sleep(timeout)
            
    def isAlive(self):
        """Returns true if the editor process is still alive"""
       	try:
            self.wordapp.Documents(self.file)
        except:
            return 0
        else:
            return 1
        
def test():
    import os
    from time import sleep
    from tempfile import mktemp
    fn = mktemp('.html')
    f = open(fn, 'w')
    #f.write('<html>\n  <head></head>\n'
    #        '<body><h1>A Test Doc</h1></body>\n</html>')
    f.write('<p>hmmm</p>')
    f.close()
    print 'Connecting to Word...'
    f = EditorProcess(fn)
    print 'Attached to %s %s' % (`f.wordapp`, f.wordapp.Version)
    print ('%s is open...' % fn),
    if f.isAlive():
        print 'yes'
        print 'Test Passed.'
    else:
        print 'no'
        print 'Test Failed.'
    
if __name__ == '__main__':
    test()


=== Products/ExternalEditor/Plugins/__init__.py 1.2 => 1.3 ===
--- Products/ExternalEditor/Plugins/__init__.py:1.2	Sun Sep  1 01:03:43 2002
+++ Products/ExternalEditor/Plugins/__init__.py	Mon Mar 31 17:26:18 2003
@@ -4,7 +4,8 @@
     # Assert plugin dependancies for py2exe
     # All plugins must be imported here to be distributed
     # in the Windows binary package!
-    import homesite
-    import homesite5
-    import photoshop
-    import photoshp
+    import homesite, homesite5
+    import photoshop, photoshp
+    import word, winword
+    import excel
+    import powerpoint, powerpnt


=== Products/ExternalEditor/Plugins/excel.py 1.1 => 1.2 ===
--- Products/ExternalEditor/Plugins/excel.py:1.1	Fri Nov 29 00:34:02 2002
+++ Products/ExternalEditor/Plugins/excel.py	Mon Mar 31 17:26:18 2003
@@ -38,6 +38,7 @@
                 sleep(1)
             else:
                 break
+        excel.Visible = 1
         self.excelapp = excel
         self.file = file
         


=== Products/ExternalEditor/Plugins/photoshp.py 1.1 => 1.2 ===
--- Products/ExternalEditor/Plugins/photoshp.py:1.1	Sun Sep  1 01:03:43 2002
+++ Products/ExternalEditor/Plugins/photoshp.py	Mon Mar 31 17:26:18 2003
@@ -36,7 +36,6 @@
             try:
                 fileconn = ps.Open(file)
             except:
-                print 'open failure: ', i
                 i += 1
                 if i >= timeout:
                     raise RuntimeError('Could not launch Photoshop.')


=== Products/ExternalEditor/Plugins/powerpnt.py 1.1 => 1.2 ===
--- Products/ExternalEditor/Plugins/powerpnt.py:1.1	Fri Nov 29 00:47:56 2002
+++ Products/ExternalEditor/Plugins/powerpnt.py	Mon Mar 31 17:26:18 2003
@@ -25,6 +25,7 @@
     def __init__(self, file):
         """Launch editor process"""
         ppt = win32com.client.Dispatch('Powerpoint.Application')
+        ppt.Visible = 1
         # Try to open the file, keep retrying until we succeed or timeout
         i = 0
         timeout = 45
@@ -32,6 +33,7 @@
             try:
                 ppt.Presentations.Open(file)
             except:
+                raise
                 i += 1
                 if i >= timeout:
                     raise RuntimeError('Could not launch Powerpoint.')
@@ -47,18 +49,18 @@
             
     def isAlive(self):
         """Returns true if the editor process is still alive"""
-        head, tail = os.path.split(self.file)
-        head, tail = head.lower(), tail.lower()
-        for doc in self.powerpntapp.Presentations:
-            if head == doc.Path.lower() and tail == doc.Name.lower():
-                return 1
-        return 0
+        try:
+            self.powerpntapp.Presentations(self.file)
+        except:
+            return 0
+        else:
+            return 1
 
 def test():
     import os
     from time import sleep
     from tempfile import mktemp
-    fn = 'c:\\program files\\microsoft office\\office10\\1033\\quikanim.ppt'
+    fn = 'E:\Documents and Settings\Default User\Templates\powerpnt.ppt'
     print 'Connecting to Powerpoint...'
     f = EditorProcess(fn)
     print 'Attached to %s %s' % (`f.powerpntapp`, f.powerpntapp.Version)


=== Products/ExternalEditor/Plugins/winword.py 1.2 => 1.3 ===
--- Products/ExternalEditor/Plugins/winword.py:1.2	Fri Nov 29 00:30:46 2002
+++ Products/ExternalEditor/Plugins/winword.py	Mon Mar 31 17:26:18 2003
@@ -38,6 +38,7 @@
                 sleep(1)
             else:
                 break
+        word.Visible = 1
         self.wordapp = word
         self.file = file
         
@@ -47,13 +48,13 @@
             
     def isAlive(self):
         """Returns true if the editor process is still alive"""
-        head, tail = os.path.split(self.file)
-        head, tail = head.lower(), tail.lower()
-        for doc in self.wordapp.Documents:
-            if head == doc.Path.lower() and tail == doc.Name.lower():
-                return 1
-        return 0
-
+       	try:
+            self.wordapp.Documents(self.file)
+        except:
+            return 0
+        else:
+            return 1
+        
 def test():
     import os
     from time import sleep