Python win32com.client() Examples

The following are 30 code examples of win32com.client(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32com , or try the search function .
Example #1
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #2
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #3
Source File: gencache.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def GetGeneratePath():
	"""Returns the name of the path to generate to.
	Checks the directory is OK.
	"""
	assert not is_readonly, "Why do you want the genpath for a readonly store?"
	try:
		os.makedirs(win32com.__gen_path__)
		#os.mkdir(win32com.__gen_path__)
	except os.error:
		pass
	try:
		fname = os.path.join(win32com.__gen_path__, "__init__.py")
		os.stat(fname)
	except os.error:
		f = open(fname,"w")
		f.write('# Generated file - this directory may be deleted to reset the COM cache...\n')
		f.write('import win32com\n')
		f.write('if __path__[:-1] != win32com.__gen_path__: __path__.append(win32com.__gen_path__)\n')
		f.close()
	
	return win32com.__gen_path__

#
# The helpers for win32com.client.Dispatch and OCX clients.
# 
Example #4
Source File: gencache.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def EnsureDispatch(prog_id, bForDemand = 1): # New fn, so we default the new demand feature to on!
	"""Given a COM prog_id, return an object that is using makepy support, building if necessary"""
	disp = win32com.client.Dispatch(prog_id)
	if not disp.__dict__.get("CLSID"): # Eeek - no makepy support - try and build it.
		try:
			ti = disp._oleobj_.GetTypeInfo()
			disp_clsid = ti.GetTypeAttr()[0]
			tlb, index = ti.GetContainingTypeLib()
			tla = tlb.GetLibAttr()
			mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
			GetModuleForCLSID(disp_clsid)
			# Get the class from the module.
			import CLSIDToClass
			disp_class = CLSIDToClass.GetClass(str(disp_clsid))
			disp = disp_class(disp._oleobj_)
		except pythoncom.com_error:
			raise TypeError("This COM object can not automate the makepy process - please run makepy manually for this object")
	return disp 
Example #5
Source File: testMSOffice.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def TestAll():
    TestWord()

    print "Starting Excel for Dynamic test..."
    xl = win32com.client.dynamic.Dispatch("Excel.Application")
    TextExcel(xl)

    try:
        print "Starting Excel 8 for generated excel8.py test..."
        mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2, bForDemand=1)
        xl = win32com.client.Dispatch("Excel.Application")
        TextExcel(xl)
    except ImportError:
        print "Could not import the generated Excel 97 wrapper"

    try:
        import xl5en32
        mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 9, 1, 0)
        xl = win32com.client.Dispatch("Excel.Application.5")
        print "Starting Excel 95 for makepy test..."
        TextExcel(xl)
    except ImportError:
        print "Could not import the generated Excel 95 wrapper" 
Example #6
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #7
Source File: logreader.py    From PyEveLiveDPS with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, logPath, mainWindow):
        super().__init__(logPath, mainWindow)
        self.log = open(logPath, 'r', encoding="utf8")
        self.log.readline()
        self.log.readline()
        characterLine = self.log.readline()
        self.character, self.language = ProcessCharacterLine(characterLine)
        logging.info('Log language is ' + self.language)
        self.log.readline()
        self.log.readline()
        self.logLine = self.log.readline()
        if (self.logLine == "------------------------------------------------------------\n"):
            self.log.readline()
            collisionCharacter, language = ProcessCharacterLine(self.log.readline())
            logging.error('Log file collision on characters' + self.character + " and " + collisionCharacter)
            messagebox.showerror("Error", "Log file collision on characters:\n\n" + self.character + " and " + collisionCharacter +
                                "\n\nThis happens when both characters log in at exactly the same second.\n" + 
                                "This makes it impossible to know which character owns which log.\n\n" + 
                                "Please restart the client of the character you want to track to use this program.\n" + 
                                "If you already did, you can ignore this message, or delete this log file:\n" + logPath)
            raise BadLogException("log file collision")
        self.log.read()
        self.compileRegex() 
Example #8
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #9
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #10
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #11
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 6 votes vote down vote up
def eval(self, expression, identify_erros=True):
    """ Evaluates a matlab expression synchronously.

    If identify_erros is true, and the last output line after evaluating the
    expressions begins with '???' an excpetion is thrown with the matlab error
    following the '???'.
    The return value of the function is the matlab output following the call.
    """
    #print expression
    self._check_open()
    ret = self.client.Execute(expression)
    #print ret
    if identify_erros and ret.rfind('???') != -1:
      begin = ret.rfind('???') + 4
      end = ret.find('\n', begin)
      raise MatlabError(ret[begin:end])
    return ret 
Example #12
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def close(self):
    """ Closes the matlab COM client.
    """
    self._check_open()
    try:
      pass    #self.eval('quit();')
    except:
      pass
    del self.client 
Example #13
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def close(self):
    """ Closes the matlab COM client.
    """
    self._check_open()
    try:
      pass    #self.eval('quit();')
    except:
      pass
    del self.client 
Example #14
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def open(self, visible=False):
    """ Dispatches the matlab COM client.

    Note: If this method fails, try running matlab with the -regserver flag.
    """
    if self.client:
      raise MatlabConnectionError('Matlab(TM) COM client is still active. Use close to '
                      'close it')
    self.client = win32com.client.Dispatch('matlab.application')
    self.client.visible = visible 
Example #15
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def get(self, names_to_get, convert_to_numpy=True):
    """ Loads the requested variables from the matlab com client.

    names_to_get can be either a variable name or a list of variable names.
    If it is a variable name, the values is returned.
    If it is a list, a dictionary of variable_name -> value is returned.

    If convert_to_numpy is true, the method will all array values to numpy
    arrays. Scalars are left as regular python objects.

    """
    self._check_open()
    single_itme = isinstance(names_to_get, (unicode, str))
    if single_itme:
      names_to_get = [names_to_get]
    ret = {}
    for name in names_to_get:
      ret[name] = self.client.GetWorkspaceData(name, 'base')
      # TODO(daniv): Do we really want to reduce dimensions like that? what if this a row vector?
      while isinstance(ret[name], (tuple, list)) and len(ret[name]) == 1:
        ret[name] = ret[name][0]
      if convert_to_numpy and isinstance(ret[name], (tuple, list)):
        ret[name] = np.array(ret[name])
    if single_itme:
      return ret.values()[0]
    return ret 
Example #16
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def __init__(self, matlab_process_path=None, matlab_version=None):
    self.client = None 
Example #17
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def close(self):
    """ Closes the matlab COM client.
    """
    self._check_open()
    try:
      pass    #self.eval('quit();')
    except:
      pass
    del self.client 
Example #18
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def open(self, visible=False):
    """ Dispatches the matlab COM client.

    Note: If this method fails, try running matlab with the -regserver flag.
    """
    if self.client:
      raise MatlabConnectionError('Matlab(TM) COM client is still active. Use close to '
                      'close it')
    self.client = win32com.client.Dispatch('matlab.application')
    self.client.visible = visible 
Example #19
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def _check_open(self):
    if not self.client:
      raise MatlabConnectionError('Matlab(TM) process is not active.') 
Example #20
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def put(self, name_to_val):
    """ Loads a dictionary of variable names into the matlab com client.
    """
    self._check_open()
    for name, val in name_to_val.iteritems():
      # First try to put data as a matrix:
      try:
        self.client.PutFullMatrix(name, 'base', val, None)
      except:
        self.client.PutWorkspaceData(name, 'base', val) 
Example #21
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def get(self, names_to_get, convert_to_numpy=True):
    """ Loads the requested variables from the matlab com client.

    names_to_get can be either a variable name or a list of variable names.
    If it is a variable name, the values is returned.
    If it is a list, a dictionary of variable_name -> value is returned.

    If convert_to_numpy is true, the method will all array values to numpy
    arrays. Scalars are left as regular python objects.

    """
    self._check_open()
    single_itme = isinstance(names_to_get, (unicode, str))
    if single_itme:
      names_to_get = [names_to_get]
    ret = {}
    for name in names_to_get:
      ret[name] = self.client.GetWorkspaceData(name, 'base')
      # TODO(daniv): Do we really want to reduce dimensions like that? what if this a row vector?
      while isinstance(ret[name], (tuple, list)) and len(ret[name]) == 1:
        ret[name] = ret[name][0]
      if convert_to_numpy and isinstance(ret[name], (tuple, list)):
        ret[name] = np.array(ret[name])
    if single_itme:
      return ret.values()[0]
    return ret 
Example #22
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def open(self, visible=False):
    """ Dispatches the matlab COM client.

    Note: If this method fails, try running matlab with the -regserver flag.
    """
    if self.client:
      raise MatlabConnectionError('Matlab(TM) COM client is still active. Use close to '
                      'close it')
    self.client = win32com.client.Dispatch('matlab.application')
    self.client.visible = visible 
Example #23
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def close(self):
    """ Closes the matlab COM client.
    """
    self._check_open()
    try:
      pass    #self.eval('quit();')
    except:
      pass
    del self.client 
Example #24
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def __init__(self, matlab_process_path=None, matlab_version=None):
    self.client = None 
Example #25
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def _check_open(self):
    if not self.client:
      raise MatlabConnectionError('Matlab(TM) process is not active.') 
Example #26
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def put(self, name_to_val):
    """ Loads a dictionary of variable names into the matlab com client.
    """
    self._check_open()
    for name, val in name_to_val.iteritems():
      # First try to put data as a matrix:
      try:
        self.client.PutFullMatrix(name, 'base', val, None)
      except:
        self.client.PutWorkspaceData(name, 'base', val) 
Example #27
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def get(self, names_to_get, convert_to_numpy=True):
    """ Loads the requested variables from the matlab com client.

    names_to_get can be either a variable name or a list of variable names.
    If it is a variable name, the values is returned.
    If it is a list, a dictionary of variable_name -> value is returned.

    If convert_to_numpy is true, the method will all array values to numpy
    arrays. Scalars are left as regular python objects.

    """
    self._check_open()
    single_itme = isinstance(names_to_get, (unicode, str))
    if single_itme:
      names_to_get = [names_to_get]
    ret = {}
    for name in names_to_get:
      ret[name] = self.client.GetWorkspaceData(name, 'base')
      # TODO(daniv): Do we really want to reduce dimensions like that? what if this a row vector?
      while isinstance(ret[name], (tuple, list)) and len(ret[name]) == 1:
        ret[name] = ret[name][0]
      if convert_to_numpy and isinstance(ret[name], (tuple, list)):
        ret[name] = np.array(ret[name])
    if single_itme:
      return ret.values()[0]
    return ret 
Example #28
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def put(self, name_to_val):
    """ Loads a dictionary of variable names into the matlab com client.
    """
    self._check_open()
    for name, val in name_to_val.iteritems():
      # First try to put data as a matrix:
      try:
        self.client.PutFullMatrix(name, 'base', val, None)
      except:
        self.client.PutWorkspaceData(name, 'base', val) 
Example #29
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def open(self, visible=False):
    """ Dispatches the matlab COM client.

    Note: If this method fails, try running matlab with the -regserver flag.
    """
    if self.client:
      raise MatlabConnectionError('Matlab(TM) COM client is still active. Use close to '
                      'close it')
    self.client = win32com.client.Dispatch('matlab.application')
    self.client.visible = visible 
Example #30
Source File: matlabcom.py    From DeepLearning_Wavelet-LSTM with MIT License 5 votes vote down vote up
def _check_open(self):
    if not self.client:
      raise MatlabConnectionError('Matlab(TM) process is not active.')