comtypes 1.1.14__zip → 1.2.1__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. {comtypes-1.1.14 → comtypes-1.2.1}/CHANGES.txt +37 -0
  2. comtypes-1.2.1/PKG-INFO +79 -0
  3. comtypes-1.2.1/README.md +59 -0
  4. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/__init__.py +302 -555
  5. comtypes-1.2.1/comtypes/_memberspec.py +520 -0
  6. comtypes-1.2.1/comtypes/_npsupport.py +143 -0
  7. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/automation.py +99 -11
  8. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/__init__.py +80 -26
  9. comtypes-1.2.1/comtypes/client/_generate.py +274 -0
  10. comtypes-1.2.1/comtypes/hints.pyi +26 -0
  11. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/persist.py +14 -0
  12. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/safearray.py +22 -21
  13. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/__init__.py +0 -7
  14. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_client.py +35 -0
  15. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_dict.py +0 -4
  16. comtypes-1.2.1/comtypes/test/test_npsupport.py +343 -0
  17. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_safearray.py +2 -235
  18. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_variant.py +6 -59
  19. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/codegenerator.py +454 -337
  20. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/tlbparser.py +56 -75
  21. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/typedesc.py +31 -3
  22. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/typedesc_base.py +28 -1
  23. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/typeinfo.py +291 -121
  24. comtypes-1.2.1/comtypes.egg-info/PKG-INFO +79 -0
  25. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes.egg-info/SOURCES.txt +4 -1
  26. {comtypes-1.1.14 → comtypes-1.2.1}/setup.cfg +0 -1
  27. {comtypes-1.1.14 → comtypes-1.2.1}/setup.py +15 -8
  28. comtypes-1.1.14/PKG-INFO +0 -50
  29. comtypes-1.1.14/README.md +0 -31
  30. comtypes-1.1.14/comtypes/client/_generate.py +0 -257
  31. comtypes-1.1.14/comtypes/npsupport.py +0 -125
  32. comtypes-1.1.14/comtypes.egg-info/PKG-INFO +0 -50
  33. {comtypes-1.1.14 → comtypes-1.2.1}/LICENSE.txt +0 -0
  34. {comtypes-1.1.14 → comtypes-1.2.1}/MANIFEST.in +0 -0
  35. {comtypes-1.1.14 → comtypes-1.2.1}/clear_comtypes_cache.py +0 -0
  36. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/GUID.py +0 -0
  37. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/_comobject.py +0 -0
  38. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/_meta.py +0 -0
  39. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/_safearray.py +0 -0
  40. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/_code_cache.py +0 -0
  41. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/_constants.py +0 -0
  42. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/_events.py +0 -0
  43. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/dynamic.py +0 -0
  44. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/lazybind.py +0 -0
  45. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/connectionpoints.py +0 -0
  46. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/errorinfo.py +0 -0
  47. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/git.py +0 -0
  48. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/hresult.py +0 -0
  49. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/logutil.py +0 -0
  50. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/messageloop.py +0 -0
  51. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/patcher.py +0 -0
  52. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/__init__.py +0 -0
  53. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/automation.py +0 -0
  54. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/connectionpoints.py +0 -0
  55. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/inprocserver.py +0 -0
  56. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/localserver.py +0 -0
  57. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/register.py +0 -0
  58. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/w_getopt.py +0 -0
  59. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/shelllink.py +0 -0
  60. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestComServer.idl +0 -0
  61. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestComServer.py +0 -0
  62. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestComServer.tlb +0 -0
  63. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestDispServer.idl +0 -0
  64. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestDispServer.py +0 -0
  65. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestDispServer.tlb +0 -0
  66. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/find_memleak.py +0 -0
  67. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/mylib.idl +0 -0
  68. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/mytypelib.idl +0 -0
  69. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/runtests.py +0 -0
  70. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/setup.py +0 -0
  71. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_BSTR.py +0 -0
  72. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_DISPPARAMS.py +0 -0
  73. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_GUID.py +0 -0
  74. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_QueryService.py +0 -0
  75. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_agilent.py +0 -0
  76. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_avmc.py +0 -0
  77. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_basic.py +0 -0
  78. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_casesensitivity.py +0 -0
  79. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_collections.py +0 -0
  80. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_comserver.py +0 -0
  81. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_createwrappers.py +0 -0
  82. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_dispinterface.py +0 -0
  83. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_dyndispatch.py +0 -0
  84. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_excel.py +0 -0
  85. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_findgendir.py +0 -0
  86. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_getactiveobj.py +0 -0
  87. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_ie.py +0 -0
  88. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_jscript.js +0 -0
  89. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_msscript.py +0 -0
  90. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_outparam.py +0 -0
  91. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_propputref.py +0 -0
  92. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_pump_events.py +0 -0
  93. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_sapi.py +0 -0
  94. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_server.py +0 -0
  95. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_showevents.py +0 -0
  96. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_subinterface.py +0 -0
  97. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_typeinfo.py +0 -0
  98. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_urlhistory.py +0 -0
  99. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_win32com_interop.py +0 -0
  100. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_wmi.py +0 -0
  101. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_word.py +0 -0
  102. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/__init__.py +0 -0
  103. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/util.py +0 -0
  104. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/viewobject.py +0 -0
  105. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes.egg-info/dependency_links.txt +0 -0
  106. {comtypes-1.1.14 → comtypes-1.2.1}/comtypes.egg-info/top_level.txt +0 -0
@@ -7,10 +7,12 @@ import sys
7
7
  from ctypes import *
8
8
  from ctypes import _Pointer
9
9
  from _ctypes import CopyComPointer
10
- from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR, COMMETHOD, COMError
10
+ from comtypes import (
11
+ BSTR, COMError, COMMETHOD, GUID, IID, IUnknown, STDMETHOD, TYPE_CHECKING,
12
+ )
11
13
  from comtypes.hresult import *
12
14
  import comtypes.patcher
13
- from comtypes import npsupport
15
+ import comtypes
14
16
  try:
15
17
  from comtypes import _safearray
16
18
  except (ImportError, AttributeError):
@@ -19,6 +21,12 @@ except (ImportError, AttributeError):
19
21
 
20
22
  from ctypes.wintypes import DWORD, LONG, UINT, VARIANT_BOOL, WCHAR, WORD
21
23
 
24
+ if TYPE_CHECKING:
25
+ from typing import (
26
+ Any, Callable, ClassVar, List, Optional, Tuple, Union as _UnionT,
27
+ )
28
+ from comtypes import hints
29
+
22
30
 
23
31
  if sys.version_info >= (3, 0):
24
32
  int_types = (int, )
@@ -149,6 +157,13 @@ DECIMAL = tagDEC
149
157
  # The VARIANT structure is a good candidate for implementation in a C
150
158
  # helper extension. At least the get/set methods.
151
159
  class tagVARIANT(Structure):
160
+ if TYPE_CHECKING:
161
+ vt = hints.AnnoField() # type: int
162
+ _ = hints.AnnoField() # type: U_VARIANT1.__tagVARIANT.U_VARIANT2
163
+ null = hints.AnnoField() # type: ClassVar[VARIANT]
164
+ empty = hints.AnnoField() # type: ClassVar[VARIANT]
165
+ missing = hints.AnnoField() # type: ClassVar[VARIANT]
166
+
152
167
  class U_VARIANT1(Union):
153
168
  class __tagVARIANT(Structure):
154
169
  # The C Header file defn of VARIANT is much more complicated, but
@@ -205,6 +220,12 @@ class tagVARIANT(Structure):
205
220
  def __repr__(self):
206
221
  if self.vt & VT_BYREF:
207
222
  return "VARIANT(vt=0x%x, byref(%r))" % (self.vt, self[0])
223
+ elif self is type(self).null:
224
+ return "VARIANT.null"
225
+ elif self is type(self).empty:
226
+ return "VARIANT.empty"
227
+ elif self is type(self).missing:
228
+ return "VARIANT.missing"
208
229
  return "VARIANT(vt=0x%x, %r)" % (self.vt, self.value)
209
230
 
210
231
  @classmethod
@@ -284,9 +305,9 @@ class tagVARIANT(Structure):
284
305
  com_days = delta.days + (delta.seconds + delta.microseconds * 1e-6) / 86400.
285
306
  self.vt = VT_DATE
286
307
  self._.VT_R8 = com_days
287
- elif npsupport.isdatetime64(value):
288
- com_days = value - npsupport.com_null_date64
289
- com_days /= npsupport.numpy.timedelta64(1, 'D')
308
+ elif comtypes.npsupport.isdatetime64(value):
309
+ com_days = value - comtypes.npsupport.com_null_date64
310
+ com_days /= comtypes.npsupport.numpy.timedelta64(1, 'D')
290
311
  self.vt = VT_DATE
291
312
  self._.VT_R8 = com_days
292
313
  elif decimal is not None and isinstance(value, decimal.Decimal):
@@ -308,10 +329,10 @@ class tagVARIANT(Structure):
308
329
  obj = _midlSAFEARRAY(typ).create(value)
309
330
  memmove(byref(self._), byref(obj), sizeof(obj))
310
331
  self.vt = VT_ARRAY | obj._vartype_
311
- elif npsupport.isndarray(value):
332
+ elif comtypes.npsupport.isndarray(value):
312
333
  # Try to convert a simple array of basic types.
313
334
  descr = value.dtype.descr[0][1]
314
- typ = npsupport.typecodes.get(descr)
335
+ typ = comtypes.npsupport.typecodes.get(descr)
315
336
  if typ is None:
316
337
  # Try for variant
317
338
  obj = _midlSAFEARRAY(VARIANT).create(value)
@@ -553,7 +574,7 @@ v._.VT_I4 = 0x80020004
553
574
  del v
554
575
 
555
576
  _carg_obj = type(byref(c_int()))
556
- from _ctypes import Array as _CArrayType
577
+ from ctypes import Array as _CArrayType
557
578
 
558
579
  @comtypes.patcher.Patch(POINTER(VARIANT))
559
580
  class _(object):
@@ -650,6 +671,17 @@ IEnumVARIANT._methods_ = [
650
671
 
651
672
 
652
673
  class tagEXCEPINFO(Structure):
674
+ if TYPE_CHECKING:
675
+ wCode = hints.AnnoField() # type: int
676
+ wReserved = hints.AnnoField() # type: int
677
+ bstrSource = hints.AnnoField() # type: str
678
+ bstrDescription = hints.AnnoField() # type: str
679
+ bstrHelpFile = hints.AnnoField() # type: str
680
+ dwHelpContext = hints.AnnoField() # type: int
681
+ pvReserved = hints.AnnoField() # type: Optional[int]
682
+ pfnDeferredFillIn = hints.AnnoField() # type: Optional[int]
683
+ scode = hints.AnnoField() # type: int
684
+
653
685
  def __repr__(self):
654
686
  return "<EXCEPINFO %s>" % \
655
687
  ((self.wCode, self.bstrSource, self.bstrDescription, self.bstrHelpFile, self.dwHelpContext,
@@ -669,6 +701,11 @@ tagEXCEPINFO._fields_ = [
669
701
  EXCEPINFO = tagEXCEPINFO
670
702
 
671
703
  class tagDISPPARAMS(Structure):
704
+ if TYPE_CHECKING:
705
+ rgvarg = hints.AnnoField() # type: Array[VARIANT]
706
+ rgdispidNamedArgs = hints.AnnoField() # type: _Pointer[DISPID]
707
+ cArgs = hints.AnnoField() # type: int
708
+ cNamedArgs = hints.AnnoField() # type: int
672
709
  _fields_ = [
673
710
  # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 696
674
711
  ('rgvarg', POINTER(VARIANTARG)),
@@ -691,7 +728,29 @@ DISPID_CONSTRUCTOR = -6
691
728
  DISPID_DESTRUCTOR = -7
692
729
  DISPID_COLLECT = -8
693
730
 
731
+
732
+ if TYPE_CHECKING:
733
+ RawGetIDsOfNamesFunc = Callable[
734
+ [_byref_type, Array[c_wchar_p], int, int, Array[DISPID]], int,
735
+ ]
736
+ RawInvokeFunc = Callable[
737
+ [
738
+ int, _byref_type, int, int, # dispIdMember, riid, lcid, wFlags
739
+ _UnionT[_byref_type, DISPPARAMS], # *pDispParams
740
+ _UnionT[_byref_type, VARIANT], # pVarResult
741
+ _UnionT[_byref_type, EXCEPINFO, None], # pExcepInfo
742
+ _UnionT[_byref_type, c_uint], # puArgErr
743
+ ],
744
+ int
745
+ ]
746
+
694
747
  class IDispatch(IUnknown):
748
+ if TYPE_CHECKING:
749
+ _disp_methods_ = hints.AnnoField() # type: ClassVar[List[comtypes._DispMemberSpec]]
750
+ _GetTypeInfo = hints.AnnoField() # type: Callable[[int, int], IUnknown]
751
+ __com_GetIDsOfNames = hints.AnnoField() # type: RawGetIDsOfNamesFunc
752
+ __com_Invoke = hints.AnnoField() # type: RawInvokeFunc
753
+
695
754
  _iid_ = GUID("{00020400-0000-0000-C000-000000000046}")
696
755
  _methods_ = [
697
756
  COMMETHOD([], HRESULT, 'GetTypeInfoCount',
@@ -699,9 +758,9 @@ class IDispatch(IUnknown):
699
758
  COMMETHOD([], HRESULT, 'GetTypeInfo',
700
759
  (['in'], UINT, 'index'),
701
760
  (['in'], LCID, 'lcid', 0),
702
- ## Normally, we would declare this parameter in this way:
703
- ## (['out'], POINTER(POINTER(ITypeInfo)) ) ),
704
- ## but we cannot import comtypes.typeinfo at the top level (recursive imports!).
761
+ # Normally, we would declare this parameter in this way:
762
+ # (['out'], POINTER(POINTER(ITypeInfo)) ) ),
763
+ # but we cannot import comtypes.typeinfo at the top level (recursive imports!).
705
764
  (['out'], POINTER(POINTER(IUnknown)) ) ),
706
765
  STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(IID), POINTER(c_wchar_p),
707
766
  UINT, LCID, POINTER(DISPID)]),
@@ -711,12 +770,14 @@ class IDispatch(IUnknown):
711
770
  ]
712
771
 
713
772
  def GetTypeInfo(self, index, lcid=0):
773
+ # type: (int, int) -> hints.ITypeInfo
714
774
  """Return type information. Index 0 specifies typeinfo for IDispatch"""
715
775
  import comtypes.typeinfo
716
776
  result = self._GetTypeInfo(index, lcid)
717
777
  return result.QueryInterface(comtypes.typeinfo.ITypeInfo)
718
778
 
719
779
  def GetIDsOfNames(self, *names, **kw):
780
+ # type: (str, Any) -> List[int]
720
781
  """Map string names to integer ids."""
721
782
  lcid = kw.pop("lcid", 0)
722
783
  assert not kw
@@ -726,6 +787,7 @@ class IDispatch(IUnknown):
726
787
  return ids[:]
727
788
 
728
789
  def _invoke(self, memid, invkind, lcid, *args):
790
+ # type: (int, int, int, Any) -> Any
729
791
  var = VARIANT()
730
792
  argerr = c_uint()
731
793
  dp = DISPPARAMS()
@@ -747,6 +809,7 @@ class IDispatch(IUnknown):
747
809
  return var._get_value(dynamic=True)
748
810
 
749
811
  def Invoke(self, dispid, *args, **kw):
812
+ # type: (int, Any, Any) -> Any
750
813
  """Invoke a method or property."""
751
814
 
752
815
  # Memory management in Dispatch::Invoke calls:
@@ -896,3 +959,28 @@ try:
896
959
  from comtypes.safearray import _midlSAFEARRAY
897
960
  except (ImportError, AttributeError):
898
961
  pass
962
+
963
+
964
+ __known_symbols__ = [
965
+ 'CURRENCY', 'CY', 'tagCY', 'DECIMAL', 'tagDEC', 'DISPATCH_METHOD',
966
+ 'DISPATCH_PROPERTYGET', 'DISPATCH_PROPERTYPUT', 'DISPATCH_PROPERTYPUTREF',
967
+ 'DISPID', 'DISPID_COLLECT', 'DISPID_CONSTRUCTOR', 'DISPID_DESTRUCTOR',
968
+ 'DISPID_EVALUATE', 'DISPID_NEWENUM', 'DISPID_PROPERTYPUT',
969
+ 'DISPID_UNKNOWN', 'DISPID_VALUE', 'DISPPARAMS', 'tagDISPPARAMS',
970
+ 'EXCEPINFO', 'tagEXCEPINFO', 'IDispatch', 'IEnumVARIANT', 'IID_NULL',
971
+ 'INVOKE_FUNC', 'INVOKE_PROPERTYGET', 'INVOKE_PROPERTYPUT',
972
+ 'INVOKE_PROPERTYPUTREF', 'INVOKEKIND', 'tagINVOKEKIND', '_midlSAFEARRAY',
973
+ 'SCODE', '_SysAllocStringLen', 'VARENUM', 'VARIANT','tagVARIANT',
974
+ 'VARIANTARG', '_VariantChangeType', '_VariantClear', '_VariantCopy',
975
+ '_VariantCopyInd', 'VARTYPE', 'VT_ARRAY', 'VT_BLOB', 'VT_BLOB_OBJECT',
976
+ 'VT_BOOL', 'VT_BSTR', 'VT_BSTR_BLOB', 'VT_BYREF', 'VT_CARRAY', 'VT_CF',
977
+ 'VT_CLSID', 'VT_CY', 'VT_DATE', 'VT_DECIMAL', 'VT_DISPATCH', 'VT_EMPTY',
978
+ 'VT_ERROR', 'VT_FILETIME', 'VT_HRESULT', 'VT_I1', 'VT_I2', 'VT_I4',
979
+ 'VT_I8', 'VT_ILLEGAL', 'VT_ILLEGALMASKED', 'VT_INT', 'VT_INT_PTR',
980
+ 'VT_LPSTR', 'VT_LPWSTR', 'VT_NULL', 'VT_PTR', 'VT_R4', 'VT_R8',
981
+ 'VT_RECORD', 'VT_RESERVED', 'VT_SAFEARRAY', 'VT_STORAGE',
982
+ 'VT_STORED_OBJECT', 'VT_STREAM', 'VT_STREAMED_OBJECT', 'VT_TYPEMASK',
983
+ 'VT_UI1', 'VT_UI2', 'VT_UI4', 'VT_UI8', 'VT_UINT', 'VT_UINT_PTR',
984
+ 'VT_UNKNOWN', 'VT_USERDEFINED', 'VT_VARIANT', 'VT_VECTOR',
985
+ 'VT_VERSIONED_STREAM', 'VT_VOID',
986
+ ]
@@ -9,43 +9,47 @@
9
9
  #
10
10
  ################################################################
11
11
 
12
- import sys, os
13
12
  import ctypes
13
+ import logging
14
+ import os
15
+ import sys
14
16
 
15
17
  import comtypes
16
18
  from comtypes.hresult import *
17
- import comtypes.automation
18
- import comtypes.typeinfo
19
+ from comtypes import (
20
+ automation, CoClass, GUID, IUnknown, TYPE_CHECKING, typeinfo,
21
+ )
19
22
  import comtypes.client.dynamic
20
-
21
23
  from comtypes.client._constants import Constants
22
24
  from comtypes.client._events import GetEvents, ShowEvents, PumpEvents
23
25
  from comtypes.client._generate import GetModule
24
-
25
- import logging
26
- logger = logging.getLogger(__name__)
27
-
28
- __all__ = ["CreateObject", "GetActiveObject", "CoGetObject",
29
- "GetEvents", "ShowEvents", "PumpEvents", "GetModule",
30
- "GetClassObject"]
31
-
32
26
  from comtypes.client._code_cache import _find_gen_dir
33
27
 
34
28
  gen_dir = _find_gen_dir()
35
29
  import comtypes.gen
36
-
37
30
  ### for testing
38
31
  ##gen_dir = None
39
32
 
33
+ if TYPE_CHECKING:
34
+ from typing import Any, Optional, overload, Type, TypeVar, Union as _UnionT
35
+ from comtypes import hints
36
+ _T_IUnknown = TypeVar("_T_IUnknown", bound=IUnknown)
37
+
38
+ logger = logging.getLogger(__name__)
39
+
40
+
40
41
  def wrap_outparam(punk):
42
+ # type: (Any) -> Any
41
43
  logger.debug("wrap_outparam(%s)", punk)
42
44
  if not punk:
43
45
  return None
44
- if punk.__com_interface__ == comtypes.automation.IDispatch:
46
+ if punk.__com_interface__ == automation.IDispatch:
45
47
  return GetBestInterface(punk)
46
48
  return punk
47
49
 
50
+
48
51
  def GetBestInterface(punk):
52
+ # type: (Any) -> Any
49
53
  """Try to QueryInterface a COM pointer to the 'most useful'
50
54
  interface.
51
55
 
@@ -60,13 +64,13 @@ def GetBestInterface(punk):
60
64
  logger.debug("GetBestInterface(%s)", punk)
61
65
  try:
62
66
  try:
63
- pci = punk.QueryInterface(comtypes.typeinfo.IProvideClassInfo)
67
+ pci = punk.QueryInterface(typeinfo.IProvideClassInfo)
64
68
  logger.debug("Does implement IProvideClassInfo")
65
69
  except comtypes.COMError:
66
70
  # Some COM objects support IProvideClassInfo2, but not IProvideClassInfo.
67
71
  # These objects are broken, but we support them anyway.
68
72
  logger.debug("Does NOT implement IProvideClassInfo, trying IProvideClassInfo2")
69
- pci = punk.QueryInterface(comtypes.typeinfo.IProvideClassInfo2)
73
+ pci = punk.QueryInterface(typeinfo.IProvideClassInfo2)
70
74
  logger.debug("Does implement IProvideClassInfo2")
71
75
  tinfo = pci.GetClassInfo() # TypeInfo for the CoClass
72
76
  # find the interface marked as default
@@ -86,7 +90,7 @@ def GetBestInterface(punk):
86
90
  except comtypes.COMError:
87
91
  logger.debug("Does NOT implement IProvideClassInfo/IProvideClassInfo2")
88
92
  try:
89
- pdisp = punk.QueryInterface(comtypes.automation.IDispatch)
93
+ pdisp = punk.QueryInterface(automation.IDispatch)
90
94
  except comtypes.COMError:
91
95
  logger.debug("No Dispatch interface: %s", punk)
92
96
  return punk
@@ -131,13 +135,23 @@ def GetBestInterface(punk):
131
135
  wrap = GetBestInterface
132
136
 
133
137
  # Should we do this for POINTER(IUnknown) also?
134
- ctypes.POINTER(comtypes.automation.IDispatch).__ctypes_from_outparam__ = wrap_outparam
138
+ ctypes.POINTER(automation.IDispatch).__ctypes_from_outparam__ = wrap_outparam # type: ignore
135
139
 
136
140
  ################################################################
137
141
  #
138
142
  # Object creation
139
143
  #
144
+ if comtypes.TYPE_CHECKING:
145
+ @overload
146
+ def GetActiveObject(progid):
147
+ # type: (_UnionT[str, CoClass, GUID]) -> Any
148
+ pass
149
+ @overload
150
+ def GetActiveObject(progid, interface):
151
+ # type: (_UnionT[str, CoClass, GUID], Type[_T_IUnknown]) -> _T_IUnknown
152
+ pass
140
153
  def GetActiveObject(progid, interface=None, dynamic=False):
154
+ # type: (_UnionT[str, CoClass, GUID], Optional[Any], bool) -> Any
141
155
  """Return a pointer to a running COM object that has been
142
156
  registered with COM.
143
157
 
@@ -147,11 +161,11 @@ def GetActiveObject(progid, interface=None, dynamic=False):
147
161
  'interface' allows to force a certain interface.
148
162
  'dynamic=True' will return a dynamic dispatch object.
149
163
  """
150
- clsid = comtypes.GUID.from_progid(progid)
164
+ clsid = GUID.from_progid(progid)
151
165
  if dynamic:
152
166
  if interface is not None:
153
167
  raise ValueError("interface and dynamic are mutually exclusive")
154
- interface = comtypes.automation.IDispatch
168
+ interface = automation.IDispatch
155
169
  elif interface is None:
156
170
  interface = getattr(progid, "_com_interfaces_", [None])[0]
157
171
  obj = comtypes.GetActiveObject(clsid, interface=interface)
@@ -159,32 +173,55 @@ def GetActiveObject(progid, interface=None, dynamic=False):
159
173
  return comtypes.client.dynamic.Dispatch(obj)
160
174
  return _manage(obj, clsid, interface=interface)
161
175
 
176
+
162
177
  def _manage(obj, clsid, interface):
178
+ # type: (Any, Optional[GUID], Optional[Type[IUnknown]]) -> Any
163
179
  obj.__dict__['__clsid'] = str(clsid)
164
180
  if interface is None:
165
181
  obj = GetBestInterface(obj)
166
182
  return obj
167
183
 
184
+
185
+ if TYPE_CHECKING:
186
+ @overload
187
+ def GetClassObject(progid, clsctx=None, pServerInfo=None):
188
+ # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO]) -> hints.IClassFactory
189
+ pass
190
+ @overload
191
+ def GetClassObject(progid, clsctx=None, pServerInfo=None, interface=None):
192
+ # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO], Optional[Type[_T_IUnknown]]) -> _T_IUnknown
193
+ pass
168
194
  def GetClassObject(progid,
169
195
  clsctx=None,
170
196
  pServerInfo=None,
171
197
  interface=None):
198
+ # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[comtypes.COSERVERINFO], Optional[Type[IUnknown]]) -> IUnknown
172
199
  """Create and return the class factory for a COM object.
173
200
 
174
201
  'clsctx' specifies how to create the object, use the CLSCTX_... constants.
175
202
  'pServerInfo', if used, must be a pointer to a comtypes.COSERVERINFO instance
176
203
  'interface' may be used to request an interface other than IClassFactory
177
204
  """
178
- clsid = comtypes.GUID.from_progid(progid)
179
- return comtypes.CoGetClassObject(clsid,
180
- clsctx, pServerInfo, interface)
205
+ clsid = GUID.from_progid(progid)
206
+ return comtypes.CoGetClassObject(clsid, clsctx, pServerInfo, interface)
181
207
 
208
+
209
+ if TYPE_CHECKING:
210
+ @overload
211
+ def CreateObject(progid):
212
+ # type: (_UnionT[str, CoClass, GUID]) -> Any
213
+ pass
214
+ @overload
215
+ def CreateObject(progid, clsctx=None, machine=None, interface=None, dynamic=False, pServerInfo=None):
216
+ # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[str], Optional[Type[_T_IUnknown]], bool, Optional[comtypes.COSERVERINFO]) -> _T_IUnknown
217
+ pass
182
218
  def CreateObject(progid, # which object to create
183
219
  clsctx=None, # how to create the object
184
220
  machine=None, # where to create the object
185
221
  interface=None, # the interface we want
186
222
  dynamic=False, # use dynamic dispatch
187
223
  pServerInfo=None): # server info struct for remoting
224
+ # type: (_UnionT[str, CoClass, GUID], Optional[int], Optional[str], Optional[Type[IUnknown]], bool, Optional[comtypes.COSERVERINFO]) -> Any
188
225
  """Create a COM object from 'progid', and try to QueryInterface()
189
226
  it to the most useful interface, generating typelib support on
190
227
  demand. A pointer to this interface is returned.
@@ -201,12 +238,12 @@ def CreateObject(progid, # which object to create
201
238
 
202
239
  You can also later request to receive events with GetEvents().
203
240
  """
204
- clsid = comtypes.GUID.from_progid(progid)
241
+ clsid = GUID.from_progid(progid)
205
242
  logger.debug("%s -> %s", progid, clsid)
206
243
  if dynamic:
207
244
  if interface:
208
245
  raise ValueError("interface and dynamic are mutually exclusive")
209
- interface = comtypes.automation.IDispatch
246
+ interface = automation.IDispatch
210
247
  elif interface is None:
211
248
  interface = getattr(progid, "_com_interfaces_", [None])[0]
212
249
  if machine is None and pServerInfo is None:
@@ -226,7 +263,18 @@ def CreateObject(progid, # which object to create
226
263
  return comtypes.client.dynamic.Dispatch(obj)
227
264
  return _manage(obj, clsid, interface=interface)
228
265
 
266
+
267
+ if TYPE_CHECKING:
268
+ @overload
269
+ def CoGetObject(displayname, interface):
270
+ # type: (str, Type[_T_IUnknown]) -> _T_IUnknown
271
+ pass
272
+ @overload
273
+ def CoGetObject(displayname, interface=None, dynamic=False):
274
+ # type: (str, None, bool) -> Any
275
+ pass
229
276
  def CoGetObject(displayname, interface=None, dynamic=False):
277
+ # type: (str, Optional[Type[comtypes.IUnknown]], bool) -> Any
230
278
  """Create an object by calling CoGetObject(displayname).
231
279
 
232
280
  Additional parameters have the same meaning as in CreateObject().
@@ -234,10 +282,16 @@ def CoGetObject(displayname, interface=None, dynamic=False):
234
282
  if dynamic:
235
283
  if interface is not None:
236
284
  raise ValueError("interface and dynamic are mutually exclusive")
237
- interface = comtypes.automation.IDispatch
285
+ interface = automation.IDispatch
238
286
  punk = comtypes.CoGetObject(displayname, interface)
239
287
  if dynamic:
240
288
  return comtypes.client.dynamic.Dispatch(punk)
241
289
  return _manage(punk,
242
290
  clsid=None,
243
291
  interface=interface)
292
+
293
+
294
+ __all__ = [
295
+ "CreateObject", "GetActiveObject", "CoGetObject", "GetEvents",
296
+ "ShowEvents", "PumpEvents", "GetModule", "GetClassObject",
297
+ ]