Esempio n. 1
0
	def close(self):
		''' Close a Modelica/SimulationX model
		'''
		sim = None
		try:
			doc = win32com.client.Dispatch(pythoncom.CoUnmarshalInterface(self._marshalled_doc, pythoncom.IID_IDispatch))
			self._marshalled_doc.Seek(0, pythoncom.STREAM_SEEK_SET)
			if not type(doc) is types.NoneType:
				sim = doc.Application
				sim.Interactive = False
				doc.Close(False)
				doc = None
				pythoncom.CoReleaseMarshalData(self._marshalled_doc)
				self._marshalled_doc = None
		except win32com.client.pywintypes.com_error:
			print 'SimulationX: COM error.'
		except:
			print 'SimulationX: Error.'
		finally:
			SimulatorBase.Model.close(self)
			if not type(sim) is types.NoneType:
				sim.Interactive = True
				sim = None

		if hasattr(self, 'variableTree'):
			del self.variableTree
		if hasattr(self, '_availableIntegrationAlgorithms'):
			del self._availableIntegrationAlgorithms
		if hasattr(self, '_solverByName'):
			del self._solverByName
		if hasattr(self, '_IntegrationAlgorithmHasFixedStepSize'):
			del self._IntegrationAlgorithmHasFixedStepSize
		if hasattr(self, '_IntegrationAlgorithmCanProvideStepSizeResults'):
			del self._IntegrationAlgorithmCanProvideStepSizeResults
Esempio n. 2
0
 def GetExcelThroughMultiThreads(self):
     '''
     线程操作时取得ExcelCOM对象,注意使用锁操作机制保证取得的对象唯一性
     :return:
     '''
     self._myStream.Seek(0, 0)
     unMarshaledInterface = pythoncom.CoUnmarshalInterface(self._myStream, pythoncom.IID_IDispatch)
     xlApp = win32com.client.dynamic.Dispatch(unMarshaledInterface)
     return xlApp
 def GetExcelApplication(self):
     try:
         self.myStream.Seek(0,0)
         myUnmarshaledInterface = pythoncom.CoUnmarshalInterface(self.myStream, pythoncom.IID_IDispatch)    
         unmarshalledExcelApp = win32com.client.Dispatch(myUnmarshaledInterface)
         return unmarshalledExcelApp
     except Exception as ex:
         logging.info("MarshalledCallbackInfo.GetExcelApplication  error    : " + 
              LocalsEnhancedErrorMessager.Enhance(ex,str(locals())))
         raise 
Esempio n. 4
0
	def simulate(self):
		''' Run a simulation of a Modelica/SimulationX model
		'''
		sim = None
		try:
			doc = win32com.client.Dispatch(pythoncom.CoUnmarshalInterface(self._marshalled_doc, pythoncom.IID_IDispatch))
			self._marshalled_doc.Seek(0, pythoncom.STREAM_SEEK_SET)
			if not type(doc) is types.NoneType:
				sim = doc.Application
				sim.Interactive = False
				self._simulate_sync(doc)
		except win32com.client.pywintypes.com_error:
			print 'SimulationX: COM error.'
			raise(SimulatorBase.Stopping)
		except:
			raise(SimulatorBase.Stopping)
		finally:
			if not type(sim) is types.NoneType:
				sim.Interactive = True
Esempio n. 5
0
    def check_password(self, path, name, password):
        pythoncom.CoInitialize()
        
        xl = win32com.client.DispatchEx('Excel.Application')
        xls_stream = pythoncom.CreateStreamOnHGlobal()   
         
        pythoncom.CoMarshalInterface(xls_stream, 
                                    pythoncom.IID_IDispatch, 
                                    xl._oleobj_, 
                                    pythoncom.MSHCTX_LOCAL, 
                                    pythoncom.MSHLFLAGS_TABLESTRONG) 

        xls_stream.Seek(0,0)
        
        myUnmarshaledInterface = pythoncom.CoUnmarshalInterface(xls_stream, pythoncom.IID_IDispatch)    
        xl = win32com.client.Dispatch(myUnmarshaledInterface)

        try:
            xl_wb = xl.Workbooks.Open('%s\\%s' %(path,name), False, True, None, password)
            if xl_wb.Name:
                xl_wb.Close(False)

                xls_stream.Seek(0,0)
                pythoncom.CoReleaseMarshalData(xls_stream)
                xls_stream = None
                pythoncom.CoUninitialize()

                return password
        except:
            xls_stream.Seek(0,0)
            pythoncom.CoReleaseMarshalData(xls_stream)
            xls_stream = None
            pythoncom.CoUninitialize()
            return None

        xls_stream.Seek(0,0)
        pythoncom.CoReleaseMarshalData(xls_stream)
        xls_stream = None
        pythoncom.CoUninitialize()
        return None