本文整理汇总了Python中pythoncom.com_error方法的典型用法代码示例。如果您正苦于以下问题:Python pythoncom.com_error方法的具体用法?Python pythoncom.com_error怎么用?Python pythoncom.com_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pythoncom
的用法示例。
在下文中一共展示了pythoncom.com_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CreateISAPIFilter
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def CreateISAPIFilter(filterParams, options):
server = FindWebServer(options, filterParams.Server)
_CallHook(filterParams, "PreInstall", options)
try:
filters = GetObject(server+"/Filters")
except pythoncom.com_error, exc:
# Brand new sites don't have the '/Filters' collection - create it.
# Any errors other than 'not found' we shouldn't ignore.
if winerror.HRESULT_FACILITY(exc.hresult) != winerror.FACILITY_WIN32 or \
winerror.HRESULT_CODE(exc.hresult) != winerror.ERROR_PATH_NOT_FOUND:
raise
server_ob = GetObject(server)
filters = server_ob.Create(_IIS_FILTERS, "Filters")
filters.FilterLoadOrder = ""
filters.SetInfo()
# As for VirtualDir, delete an existing one.
示例2: _DumpObject
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def _DumpObject(ob, level = 0):
prefix = " " * level
print "%s%s object: %s" % (prefix, ob.Class, ob.Name)
# Do the directory object thing
try:
dir_ob = ADsGetObject(ob.ADsPath, IID_IDirectoryObject)
except pythoncom.com_error:
dir_ob = None
if dir_ob is not None:
info = dir_ob.GetObjectInformation()
print "%s RDN='%s', ObjectDN='%s'" % (prefix, info.RDN, info.ObjectDN)
# Create a list of names to fetch
names = ["distinguishedName"]
attrs = dir_ob.GetObjectAttributes(names)
for attr in attrs:
for val, typ in attr.Values:
print "%s Attribute '%s' = %s" % (prefix, attr.AttrName, val)
for child in ob:
_DumpObject(child, level+1)
示例3: ProcessAXScriptException
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def ProcessAXScriptException(scriptingSite, debugManager, exceptionInstance):
"""General function to handle any exception in AX code
This function creates an instance of our IActiveScriptError interface, and
gives it to the host, along with out exception class. The host will
likely call back on the IActiveScriptError interface to get the source text
and other information not normally in COM exceptions.
"""
# traceback.print_exc()
instance = IActiveScriptError()
instance._SetExceptionInfo(exceptionInstance)
gateway = win32com.server.util.wrap(instance, axscript.IID_IActiveScriptError)
if debugManager:
fCallOnError = debugManager.HandleRuntimeError()
if not fCallOnError:
return None
try:
result = scriptingSite.OnScriptError(gateway)
except pythoncom.com_error, details:
print "**OnScriptError failed:", details
print "Exception description:'%s'" % (repr(exceptionInstance.description))
print "Exception text:'%s'" % (repr(exceptionInstance.linetext))
result = winerror.S_FALSE
示例4: CloseApp
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def CloseApp(self):
traceenter("ClosingApp")
self.reset()
self.logicalbotframe = None
if self.stackSnifferCookie is not None:
try:
self.debugApplication.RemoveStackFrameSniffer(self.stackSnifferCookie)
except pythoncom.com_error:
trace("*** Could not RemoveStackFrameSniffer %d" % (self.stackSnifferCookie))
if self.stackSniffer:
_wrap_remove(self.stackSniffer)
self.stackSnifferCookie = self.stackSniffer = None
if self.appEventConnection is not None:
self.appEventConnection.Disconnect()
self.appEventConnection = None
self.debugApplication = None
self.appDebugger = None
if self.codeContainerProvider is not None:
self.codeContainerProvider.Close()
self.codeContainerProvider = None
示例5: OnInitDialog
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def OnInitDialog(self):
rc = dialog.Dialog.OnInitDialog(self)
self.editwindow = self.GetDlgItem(132)
self.editwindow.HookAllKeyStrokes(self.OnKey)
self.olectl = MySerialControl(self)
try:
self.olectl.CreateControl("OCX",
win32con.WS_TABSTOP | win32con.WS_VISIBLE,
(7,43,500,300), self._obj_, 131)
except win32ui.error:
self.MessageBox("The Serial Control could not be created")
self.olectl = None
self.EndDialog(win32con.IDCANCEL)
if self.olectl:
self.olectl.Settings = SERIAL_SETTINGS
self.olectl.CommPort = SERIAL_PORT
self.olectl.RThreshold = 1
try:
self.olectl.PortOpen = 1
except pythoncom.com_error, details:
print "Could not open the specified serial port - %s" % (details.excepinfo[2])
self.EndDialog(win32con.IDCANCEL)
示例6: OnConnection
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def OnConnection(self, application, connectMode, addin, custom):
print "OnConnection", application, connectMode, addin, custom
try:
self.appHostApp = application
cbcMyBar = self.appHostApp.CommandBars.Add(Name="PythonBar", Position=constants.msoBarTop, MenuBar=constants.msoBarTypeNormal, Temporary=True)
btnMyButton = cbcMyBar.Controls.Add(Type=constants.msoControlButton, Parameter="Greetings")
btnMyButton=self.toolbarButton = DispatchWithEvents(btnMyButton, ButtonEvent)
btnMyButton.Style = constants.msoButtonCaption
btnMyButton.BeginGroup = True
btnMyButton.Caption = "&Python"
btnMyButton.TooltipText = "Python rules the World"
btnMyButton.Width = "34"
cbcMyBar.Visible = True
except pythoncom.com_error, (hr, msg, exc, arg):
print "The Excel call failed with code %d: %s" % (hr, msg)
if exc is None:
print "There is no extended error information"
else:
wcode, source, text, helpFile, helpId, scode = exc
print "The source of the error is", source
print "The error message is", text
print "More info can be found in %s (id=%d)" % (helpFile, helpId)
示例7: _Build_CoClass
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def _Build_CoClass(self, type_info_tuple):
info, infotype, doc, attr = type_info_tuple
# find the source and dispinterfaces for the coclass
child_infos = []
for j in range(attr[8]):
flags = info.GetImplTypeFlags(j)
try:
refType = info.GetRefTypeInfo(info.GetRefTypeOfImplType(j))
except pythoncom.com_error:
# Can't load a dependent typelib?
continue
refAttr = refType.GetTypeAttr()
child_infos.append( (info, refAttr.typekind, refType, refType.GetDocumentation(-1), refAttr, flags) )
# Done generating children - now the CoClass itself.
newItem = CoClassItem(info, attr, doc)
return newItem, child_infos
示例8: Dispatch
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def Dispatch(IDispatch, userName = None, createClass = None, typeinfo = None, UnicodeToString=None, clsctx = pythoncom.CLSCTX_SERVER):
assert UnicodeToString is None, "this is deprecated and will go away"
IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
if createClass is None:
createClass = CDispatch
lazydata = None
try:
if typeinfo is None:
typeinfo = IDispatch.GetTypeInfo()
try:
#try for a typecomp
typecomp = typeinfo.GetTypeComp()
lazydata = typeinfo, typecomp
except pythoncom.com_error:
pass
except pythoncom.com_error:
typeinfo = None
olerepr = MakeOleRepr(IDispatch, typeinfo, lazydata)
return createClass(IDispatch, olerepr, userName, lazydata=lazydata)
示例9: GetModuleForProgID
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def GetModuleForProgID(progid):
"""Get a Python module for a Program ID
Given a Program ID, return a Python module which contains the
class which wraps the COM object.
Returns the Python module, or None if no module is available.
Params
progid -- A COM ProgramID or IID (eg, "Word.Application")
"""
try:
iid = pywintypes.IID(progid)
except pywintypes.com_error:
return None
return GetModuleForCLSID(iid)
示例10: MakeModuleForTypelib
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def MakeModuleForTypelib(typelibCLSID, lcid, major, minor, progressInstance = None, bGUIProgress = None, bForDemand = bForDemandDefault, bBuildHidden = 1):
"""Generate support for a type library.
Given the IID, LCID and version information for a type library, generate
and import the necessary support files.
Returns the Python module. No exceptions are caught.
Params
typelibCLSID -- IID of the type library.
major -- Integer major version.
minor -- Integer minor version.
lcid -- Integer LCID for the library.
progressInstance -- Instance to use as progress indicator, or None to
use the GUI progress bar.
"""
if bGUIProgress is not None:
print "The 'bGuiProgress' param to 'MakeModuleForTypelib' is obsolete."
import makepy
try:
makepy.GenerateFromTypeLibSpec( (typelibCLSID, lcid, major, minor), progressInstance=progressInstance, bForDemand = bForDemand, bBuildHidden = bBuildHidden)
except pywintypes.com_error:
return None
return GetModuleForTypelib(typelibCLSID, lcid, major, minor)
示例11: MakeModuleForTypelibInterface
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def MakeModuleForTypelibInterface(typelib_ob, progressInstance = None, bForDemand = bForDemandDefault, bBuildHidden = 1):
"""Generate support for a type library.
Given a PyITypeLib interface generate and import the necessary support files. This is useful
for getting makepy support for a typelibrary that is not registered - the caller can locate
and load the type library itself, rather than relying on COM to find it.
Returns the Python module.
Params
typelib_ob -- The type library itself
progressInstance -- Instance to use as progress indicator, or None to
use the GUI progress bar.
"""
import makepy
try:
makepy.GenerateFromTypeLibSpec( typelib_ob, progressInstance=progressInstance, bForDemand = bForDemandDefault, bBuildHidden = bBuildHidden)
except pywintypes.com_error:
return None
tla = typelib_ob.GetLibAttr()
guid = tla[0]
lcid = tla[1]
major = tla[3]
minor = tla[4]
return GetModuleForTypelib(guid, lcid, major, minor)
示例12: EnsureDispatch
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
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
示例13: _CreateInstance_
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def _CreateInstance_(self, clsid, reqIID):
"""Creates a new instance of a **wrapped** object
This method looks up a "@win32com.server.policy.regSpec@" % clsid entry
in the registry (using @DefaultPolicy@)
"""
try:
classSpec = win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT,
regSpec % clsid)
except win32api.error:
raise error("The object is not correctly registered - %s key can not be read" % (regSpec % clsid))
myob = call_func(classSpec)
self._wrap_(myob)
try:
return pythoncom.WrapObject(self, reqIID)
except pythoncom.com_error, (hr, desc, exc, arg):
from win32com.util import IIDToInterfaceName
desc = "The object '%r' was created, but does not support the " \
"interface '%s'(%s): %s" \
% (myob, IIDToInterfaceName(reqIID), reqIID, desc)
raise pythoncom.com_error(hr, desc, exc, arg)
示例14: _build_typeinfos_
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def _build_typeinfos_(self):
# Can only ever be one for now.
tlb_guid = getattr(self._obj_, '_typelib_guid_', None)
if tlb_guid is None:
return []
tlb_major, tlb_minor = getattr(self._obj_, '_typelib_version_', (1,0))
tlb = pythoncom.LoadRegTypeLib(tlb_guid, tlb_major, tlb_minor)
typecomp = tlb.GetTypeComp()
# Not 100% sure what semantics we should use for the default interface.
# Look for the first name in _com_interfaces_ that exists in the typelib.
for iname in self._obj_._com_interfaces_:
try:
type_info, type_comp = typecomp.BindType(iname)
if type_info is not None:
return [type_info]
except pythoncom.com_error:
pass
return []
示例15: testShellLink
# 需要导入模块: import pythoncom [as 别名]
# 或者: from pythoncom import com_error [as 别名]
def testShellLink(self):
desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP))
num = 0
shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
names = [os.path.join(desktop, n) for n in os.listdir(desktop)]
programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS))
names.extend([os.path.join(programs, n) for n in os.listdir(programs)])
for name in names:
try:
persistFile.Load(name,STGM_READ)
except pythoncom.com_error:
continue
# Resolve is slow - avoid it for our tests.
#shellLink.Resolve(0, shell.SLR_ANY_MATCH | shell.SLR_NO_UI)
fname, findData = shellLink.GetPath(0)
unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
num += 1
if num == 0:
# This isn't a fatal error, but is unlikely.
print "Could not find any links on your desktop or programs dir, which is unusual"