Skip to content

Commit

Permalink
adjust import part and references (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd authored Dec 31, 2022
1 parent 39d9e00 commit 0fecfea
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions comtypes/client/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import ctypes
import comtypes.automation
import comtypes.typeinfo
import comtypes.client
import comtypes.client.lazybind

from comtypes import COMError, IUnknown, _is_object
import comtypes.hresult as hres
from comtypes import automation
from comtypes.client import lazybind
from comtypes import COMError, hresult as hres, _is_object

# These errors generally mean the property or method exists,
# but can't be used in this context - eg, property instead of a method, etc.
Expand All @@ -24,12 +21,12 @@ def Dispatch(obj):
# via fully dynamic dispatch
if isinstance(obj, _Dispatch):
return obj
if isinstance(obj, ctypes.POINTER(comtypes.automation.IDispatch)):
if isinstance(obj, ctypes.POINTER(automation.IDispatch)):
try:
tinfo = obj.GetTypeInfo(0)
except (comtypes.COMError, WindowsError):
except (COMError, WindowsError):
return _Dispatch(obj)
return comtypes.client.lazybind.Dispatch(obj, tinfo)
return lazybind.Dispatch(obj, tinfo)
return obj


Expand All @@ -45,17 +42,17 @@ def __call__(self, *args):

def __getitem__(self, *args):
return self._obj._comobj.Invoke(
self._id, *args, _invkind=comtypes.automation.DISPATCH_PROPERTYGET
self._id, *args, _invkind=automation.DISPATCH_PROPERTYGET
)

def __setitem__(self, *args):
if _is_object(args[-1]):
self._obj._comobj.Invoke(
self._id, *args, _invkind=comtypes.automation.DISPATCH_PROPERTYPUTREF
self._id, *args, _invkind=automation.DISPATCH_PROPERTYPUTREF
)
else:
self._obj._comobj.Invoke(
self._id, *args, _invkind=comtypes.automation.DISPATCH_PROPERTYPUT
self._id, *args, _invkind=automation.DISPATCH_PROPERTYPUT
)


Expand All @@ -70,7 +67,7 @@ def __init__(self, comobj):

def __enum(self):
e = self._comobj.Invoke(-4) # DISPID_NEWENUM
return e.QueryInterface(comtypes.automation.IEnumVARIANT)
return e.QueryInterface(automation.IEnumVARIANT)

def __hash__(self):
return hash(self._comobj)
Expand Down Expand Up @@ -118,7 +115,7 @@ def __getattr__(self, name):
self.__dict__[name] = result
return result

flags = comtypes.automation.DISPATCH_PROPERTYGET
flags = automation.DISPATCH_PROPERTYGET
try:
result = self._comobj.Invoke(dispid, _invkind=flags)
except COMError as err:
Expand Down Expand Up @@ -149,8 +146,13 @@ def __iter__(self):
return _Collection(self.__enum())

# def __setitem__(self, index, value):
# self._comobj.Invoke(-3, index, value,
# _invkind=comtypes.automation.DISPATCH_PROPERTYPUT|comtypes.automation.DISPATCH_PROPERTYPUTREF)
# self._comobj.Invoke(
# -3,
# index,
# value,
# _invkind=automation.DISPATCH_PROPERTYPUT
# | automation.DISPATCH_PROPERTYPUTREF,
# )


class _Collection(object):
Expand Down

0 comments on commit 0fecfea

Please sign in to comment.