comtypes
comtypes copied to clipboard
Define enumerations in generated modules.
Currently, when we generate a Python module from a COM type library with client.GetModule, the stuffs defined as Enumeration in the COM type library are defined in Python as aliases for ctypes.c_int.
They are passed to STDMETHOD, COMMETHOD, DISPMETHOD or DISPPROPERTY to define method and property arguments and return values.
This makes it difficult to add functionality such as enumeration type member information to these symbols.
This problem has been left as a comment that marked XXX on the codegenerator, since this package was born.
https://github.com/enthought/comtypes/blob/cc9a0131edc76bd92073f75e9737aad40cd10c58/comtypes/tools/codegenerator.py#L406-L421
I propose the following procedure as a solution to this problem.
-
The args passed to functions like
STDMETHODwill be changed toctypes.c_intitself from the symbols defined asEnumerationandExternalorAliasthose referred toEnumerationin the COM type library.- Actual code will be below.
... XlCreator = c_int # enum ... DISPMETHOD([dispid(149), 'propget'], XlCreator, 'Creator'), ...↓
... XlCreator = c_int # enum ... DISPMETHOD([dispid(149), 'propget'], c_int, 'Creator'), ... -
The symbols currently defined as aliases of
ctypes.c_intwill be changed the definition as enumeration types.- The de facto standard for defining enumeration types in Python is the
enummodule. Theenummodule is supported since Py3.4, so it is not available in Py2.7 or Py3.3. Therefore, it will be after older Python versions are dropped that these will actually be changed.
- The de facto standard for defining enumeration types in Python is the