本文整理汇总了Python中pywintypes.com_error方法的典型用法代码示例。如果您正苦于以下问题:Python pywintypes.com_error方法的具体用法?Python pywintypes.com_error怎么用?Python pywintypes.com_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywintypes
的用法示例。
在下文中一共展示了pywintypes.com_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MakeModuleForTypelib
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes 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)
示例2: MakeModuleForTypelibInterface
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes 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)
示例3: EnsureDispatch
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes 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
示例4: extract_attachments
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def extract_attachments(msg, out_dir):
attachment_attribs = [
'DisplayName', 'FileName', 'PathName', 'Position', 'Size'
]
i = 1 # Attachments start at 1
while True:
try:
attachment = msg.Attachments(i)
except pywintypes.com_error:
break
print("\nAttachment {}".format(i))
print("=" * 15)
for entry in attachment_attribs:
print('{}: {}'.format(entry, getattr(attachment, entry,
"N/A")))
outfile = os.path.join(os.path.abspath(out_dir),
os.path.split(args.MSG_FILE)[-1])
if not os.path.exists(outfile):
os.makedirs(outfile)
outfile = os.path.join(outfile, attachment.FileName)
attachment.SaveAsFile(outfile)
print("Exported: {}".format(outfile))
i += 1
示例5: display_msg_recipients
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def display_msg_recipients(msg):
# Display Recipient Information
recipient_attrib = [
'Address', 'AutoResponse', 'Name', 'Resolved', 'Sendable'
]
i = 1
while True:
try:
recipient = msg.Recipients(i)
except pywintypes.com_error:
break
print("\nRecipient {}".format(i))
print("=" * 15)
for entry in recipient_attrib:
print("{}: {}".format(entry, getattr(recipient, entry, 'N/A')))
i += 1
示例6: _setNativeSelection
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def _setNativeSelection(self, selection):
"""
\remarks implements the AbstractScene._setNativeSelection to select the inputed native objects in the scene
\param nativeObjects <list> [ <PySoftimage.xsi.Object> nativeObject, .. ]
\return <bool> success
"""
if isinstance(selection, basestring):
try:
xsi.SelectObj(selection)
except com_error:
pass
finally:
return True
else:
xsiCollSelection = xsiFactory.CreateObject('XSI.Collection')
xsiCollSelection.AddItems(selection)
xsi.SelectObj(xsiCollSelection)
return True
示例7: _addToNativeSelection
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def _addToNativeSelection(self, selection):
"""
\remarks implements the AbstractScene._addToNativeSelection to select the inputed native objects in the scene
\param nativeObjects <list> [ <PySoftimage.xsi.Object> nativeObject, .. ]
\return <bool> success
"""
if isinstance(selection, basestring):
try:
xsi.AddToSelection(selection)
except com_error:
pass
finally:
return True
else:
xsiCollSelection = xsiFactory.CreateObject('XSI.Collection')
xsiCollSelection.AddItems(selection)
xsi.AddToSelection(xsiCollSelection)
示例8: askOpenFolderWin32
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def askOpenFolderWin32(title, initialDir):
try:
desktop_pidl = shell.SHGetFolderLocation(0, shellcon.CSIDL_DESKTOP, 0, 0)
pidl, display_name, image_list = shell.SHBrowseForFolder (
win32gui.GetDesktopWindow(),
desktop_pidl,
"Choose a folder",
0,
None,
None
)
return shell.SHGetPathFromIDList(pidl)
except pywintypes.com_error as e:
if e.args[0] == -2147467259:
print "Invalid folder selected"
pass
示例9: handle_com_error
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def handle_com_error(err=None):
"""Convenience wrapper for displaying all manner of COM errors.
Raises a :exc:`x_wmi` exception with more useful information attached
:param err: The structure attached to a `pywintypes.com_error`
"""
if err is None:
_, err, _ = sys.exc_info()
hresult_code, hresult_name, additional_info, parameter_in_error = err.args
hresult_code = signed_to_unsigned(hresult_code)
exception_string = ["%s - %s" % (hex(hresult_code), hresult_name)]
scode = None
if additional_info:
wcode, source_of_error, error_description, whlp_file, whlp_context, scode = additional_info
scode = signed_to_unsigned(scode)
exception_string.append(" Error in: %s" % source_of_error)
exception_string.append(" %s - %s" % (hex(scode), (error_description or "").strip()))
for error_code, klass in WMI_EXCEPTIONS.items():
if error_code in (hresult_code, scode):
break
else:
klass = x_wmi
raise klass(com_error=err)
示例10: set
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def set(self, **kwargs):
"""Set several properties of the underlying object
at one go. This is particularly useful in combination
with the new () method below. However, an instance
which has been spawned in this way won't have enough
information to write pack, so only try if the
instance has a path.
"""
if kwargs:
try:
for attribute, value in kwargs.items():
if attribute in self.properties:
self._cached_properties(attribute).set(value)
else:
raise AttributeError(attribute)
#
# Only try to write the attributes
# back if the object exists.
#
if self.ole_object.Path_.Path:
self.ole_object.Put_()
except pywintypes.com_error:
handle_com_error()
示例11: _cached_associated_classes
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def _cached_associated_classes(self):
if self._associated_classes is None:
if isinstance(self, _wmi_class):
params = {'bSchemaOnly': True}
else:
params = {'bClassesOnly': True}
try:
associated_classes = dict(
(assoc.Path_.Class, _wmi_class(self._namespace, assoc)) for
assoc in self.ole_object.Associators_(**params)
)
_set(self, "_associated_classes", associated_classes)
except pywintypes.com_error:
handle_com_error()
return self._associated_classes
示例12: associators
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def associators(self, wmi_association_class="", wmi_result_class=""):
"""Return a list of objects related to this one, optionally limited
either by association class (ie the name of the class which relates
them) or by result class (ie the name of the class which would be
retrieved)::
c = wmi.WMI ()
pp = c.Win32_ParallelPort ()[0]
for i in pp.associators (wmi_association_class="Win32_PortResource"):
print i
for i in pp.associators (wmi_result_class="Win32_PnPEntity"):
print i
"""
try:
return [
_wmi_object(i) for i in \
self.ole_object.Associators_(
strAssocClass=wmi_association_class,
strResultClass=wmi_result_class
)
]
except pywintypes.com_error:
handle_com_error()
示例13: __call__
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def __call__(self, timeout_ms=-1):
"""When called, return the instance which caused the event. Supports
timeout in milliseconds (defaulting to infinite). If the watcher
times out, :exc:`x_wmi_timed_out` is raised. This makes it easy to support
watching for multiple objects.
"""
try:
event = self.wmi_event.NextEvent(timeout_ms)
if self.is_extrinsic:
return _wmi_event(event, None, self.fields)
else:
return _wmi_event(
event.Properties_("TargetInstance").Value,
_wmi_object(event, property_map=self._event_property_map),
self.fields
)
except pywintypes.com_error:
handle_com_error()
示例14: Registry
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def Registry(
computer=None,
impersonation_level="Impersonate",
authentication_level="Default",
authority=None,
privileges=None,
moniker=None
):
warnings.warn("This function can be implemented using wmi.WMI (namespace='DEFAULT').StdRegProv", DeprecationWarning)
if not moniker:
moniker = construct_moniker(
computer=computer,
impersonation_level=impersonation_level,
authentication_level=authentication_level,
authority=authority,
privileges=privileges,
namespace="default",
suffix="StdRegProv"
)
try:
return _wmi_object(GetObject(moniker))
except pywintypes.com_error:
handle_com_error()
示例15: active_document
# 需要导入模块: import pywintypes [as 别名]
# 或者: from pywintypes import com_error [as 别名]
def active_document(self):
"""
.. admonition:: Note
CAA V5 Visual Basic Help (2020-06-11 12:40:47.360445)
| o Property ActiveDocument() As Document (Read Only)
|
| Returns the active document. The active document is the document the end
| user is being editing.
|
| Example:
| This example retrieves in ActiveDoc the active document of the CATIA
| application.
|
| Dim ActiveDoc As Document
| Set ActiveDoc = CATIA.ActiveDocument
:return: Document()
"""
try:
return Document(self.application.ActiveDocument)
except com_error:
raise CATIAApplicationException('Is there an active document?')