Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions comtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
from comtypes import patcher # noqa
from comtypes._npsupport import interop as npsupport # noqa
from comtypes._tlib_version_checker import _check_version # noqa
from comtypes._py_instance_method import instancemethod # noqa
from comtypes._idl_stuff import defaultvalue, helpstring, dispid # noqa
from comtypes._idl_stuff import STDMETHOD, DISPMETHOD, DISPPROPERTY, COMMETHOD # noqa

_all_slice = slice(None, None, None)

Expand Down Expand Up @@ -169,6 +166,19 @@ def CoUninitialize():
com_coclass_registry = {}


################################################################
# IDL stuff

from comtypes._memberspec import ( # noqa
COMMETHOD,
DISPMETHOD,
DISPPROPERTY,
STDMETHOD,
defaultvalue,
dispid,
helpstring,
)

################################################################
# IUnknown, the root of all evil...
from comtypes._post_coinit import _shutdown
Expand All @@ -193,6 +203,7 @@ def CoUninitialize():
################################################################


from comtypes._post_coinit.instancemethod import instancemethod # noqa
from comtypes._post_coinit.misc import ( # noqa
_is_object,
CoGetObject,
Expand Down
67 changes: 0 additions & 67 deletions comtypes/_idl_stuff.py

This file was deleted.

72 changes: 72 additions & 0 deletions comtypes/_memberspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,78 @@ def _is_spec_prop(m: _MemberSpec):
return any(f in ("propget", "propput", "propputref") for f in m.idlflags)


################################################################
# IDL stuff


class helpstring(str):
"Specifies the helpstring for a COM method or property."


class defaultvalue(object):
"Specifies the default value for parameters marked optional."

def __init__(self, value):
self.value = value


class dispid(int):
"Specifies the DISPID of a method or property."


# XXX STDMETHOD, COMMETHOD, DISPMETHOD, and DISPPROPERTY should return
# instances with more methods or properties, and should not behave as an unpackable.


def STDMETHOD(restype, name, argtypes=()) -> _ComMemberSpec:
"Specifies a COM method slot without idlflags"
return _ComMemberSpec(restype, name, argtypes, None, (), None)


def DISPMETHOD(idlflags, restype, name, *argspec) -> _DispMemberSpec:
"Specifies a method of a dispinterface"
return _DispMemberSpec("DISPMETHOD", name, tuple(idlflags), restype, argspec)


def DISPPROPERTY(idlflags, proptype, name) -> _DispMemberSpec:
"Specifies a property of a dispinterface"
return _DispMemberSpec("DISPPROPERTY", name, tuple(idlflags), proptype, ())


# tuple(idlflags) is for the method itself: (dispid, 'readonly')

# sample generated code:
# DISPPROPERTY([5, 'readonly'], OLE_YSIZE_HIMETRIC, 'Height'),
# DISPMETHOD(
# [6], None, 'Render', ([], c_int, 'hdc'), ([], c_int, 'x'), ([], c_int, 'y')
# )


def COMMETHOD(idlflags, restype, methodname, *argspec) -> _ComMemberSpec:
"""Specifies a COM method slot with idlflags.

XXX should explain the sematics of the arguments.
"""
# collect all helpstring instances
# We should suppress docstrings when Python is started with -OO
# join them together(does this make sense?) and replace by None if empty.
helptext = "".join(t for t in idlflags if isinstance(t, helpstring)) or None
paramflags, argtypes = _resolve_argspec(argspec)
if "propget" in idlflags:
name = "_get_%s" % methodname
elif "propput" in idlflags:
name = "_set_%s" % methodname
elif "propputref" in idlflags:
name = "_setref_%s" % methodname
else:
name = methodname
return _ComMemberSpec(
restype, name, argtypes, paramflags, tuple(idlflags), helptext
)


################################################################

_PropFunc = Optional[Callable[..., Any]]
_DocType = Optional[str]

Expand Down
2 changes: 1 addition & 1 deletion comtypes/_post_coinit/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if TYPE_CHECKING:
from comtypes import hints as hints # noqa # type: ignore

from comtypes._idl_stuff import COMMETHOD # noqa
from comtypes._memberspec import COMMETHOD
from comtypes import CLSCTX_SERVER, CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER
from comtypes import _ole32, oledll, DWORD
from comtypes._post_coinit.unknwn import IUnknown
Expand Down
5 changes: 2 additions & 3 deletions comtypes/_post_coinit/unknwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from typing import List, Type

from comtypes import _ole32_nohresult, com_interface_registry
from comtypes._idl_stuff import STDMETHOD
from comtypes._memberspec import ComMemberGenerator, DispMemberGenerator
from comtypes._memberspec import _ComMemberSpec, _DispMemberSpec
from comtypes._memberspec import STDMETHOD, _ComMemberSpec, _DispMemberSpec
from comtypes._post_coinit import _cominterface_meta_patcher as _meta_patch
from comtypes._post_coinit.guid import GUID
from comtypes._py_instance_method import instancemethod
from comtypes._post_coinit.instancemethod import instancemethod

logger = logging.getLogger(__name__)

Expand Down