Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
ExternalEditor.Plugins.excel.EditorProcess Class Reference

List of all members.

Public Member Functions

def __init__
def wait
def isAlive

Public Attributes

 excelapp
 file

Detailed Description

Definition at line 25 of file excel.py.


Constructor & Destructor Documentation

Launch editor process

Definition at line 26 of file excel.py.

00026 
00027     def __init__(self, file):
00028         """Launch editor process"""
00029         excel = win32com.client.Dispatch('Excel.Application')
00030         # Try to open the file, keep retrying until we succeed or timeout
00031         i = 0
00032         timeout = 45
00033         while i < timeout:
00034             try:
00035                 excel.Workbooks.Open(file)
00036             except:
00037                 i += 1
00038                 if i >= timeout:
00039                     raise RuntimeError('Could not launch Excel.')
00040                 sleep(1)
00041             else:
00042                 break
00043         excel.Visible = 1
00044         self.excelapp = excel
00045         self.file = file
        

Member Function Documentation

Returns true if the editor process is still alive

Definition at line 50 of file excel.py.

00050 
00051     def isAlive(self):
00052         """Returns true if the editor process is still alive"""
00053         tries = 0
00054         head, tail = os.path.split(self.file)
00055         head, tail = head.lower(), tail.lower()
00056 
00057         try:
00058             for doc in self.excelapp.Workbooks:
00059                 if head == doc.Path.lower() and tail == doc.Name.lower():
00060                     return 1
00061             return 0
00062         except pythoncom.com_error, why:
00063             # COM will reject the call to enumerate the docs if the user is
00064             # doing anything interactive at the time the call is made.  The
00065             # symptom is a COM error numbered -2147418111 named "Call rejected
00066             # by callee".  This could happen indefinitely while a user is
00067             # camped on a cell waiting for input, so the only sane thing to do
00068             # is to return true and wait til the next call to really do the
00069             # check.
00070             if why[0] == -2147418111:
00071                 return 1
00072             else:
00073                 raise
00074         except AttributeError, why:
00075             # No one knows why this happens but sometimes while a user is
00076             # editing, win32com\client\dynamic.py will raise an error
00077             # signifying that the attributes we attempt to look up on the Excel
00078             # document can't be found.  Ignore this and return 1 if so,
00079             # waiting for the next go-around to check again (eventually we do
00080             # get access to the attributes).
00081             if (isinstance(why, types.StringType) or
00082                 isinstance(why, types.UnicodeType)):
00083                 if why.endswith('Path') or why.endswith('Name'):
00084                     return 1
00085             raise
00086         except TypeError, why:
00087             # Again, who knows why this happens but the enumeration of
00088             # workbooks can occasionally lead to a type error, e.g.:
00089             # Traceback (most recent call last):
00090             # File "zopeedit.py", line 764, in ?
00091             # File "zopeedit.py", line 372, in launch
00092             # File "Plugins\excel.pyc", line 57, in isAlive
00093             # File "win32com\client\dynamic.pyc", line 210, in __getitem__
00094             # TypeError: This object does not support enumeration
00095             # We ignore this and return true.
00096             why = str(why)
00097             if why.endswith('enumeration'):
00098                 return 1
00099             raise

def ExternalEditor.Plugins.excel.EditorProcess.wait (   self,
  timeout 
)
Wait for editor to exit or until timeout

Definition at line 46 of file excel.py.

00046 
00047     def wait(self, timeout):
00048         """Wait for editor to exit or until timeout"""
00049         sleep(timeout)
            

Member Data Documentation

Definition at line 43 of file excel.py.

Definition at line 44 of file excel.py.


The documentation for this class was generated from the following file: