ctypes-commit Mailing List for ctypes (Page 46)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2005-06-30 20:16:20
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28161 Modified Files: Tag: branch_1_0 typedesc.py tlbparser.py codegenerator.py Log Message: Works for the first time!!! Needed typelib wrappers are generated on demand - tested with WORD. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.6 retrieving revision 1.4.2.7 diff -C2 -d -r1.4.2.6 -r1.4.2.7 *** tlbparser.py 30 Jun 2005 19:39:59 -0000 1.4.2.6 --- tlbparser.py 30 Jun 2005 20:16:11 -0000 1.4.2.7 *************** *** 465,471 **** tlib = self.tlib la = tlib.GetLibAttr() ! return "_%s_%s_%s_%s" % \ ! (str(la.guid)[1:-1].replace("-", "_"), ! la.lcid, la.wMajorVerNum, la.wMinorVerNum) def parse_typeinfo(self, tinfo): --- 465,475 ---- tlib = self.tlib la = tlib.GetLibAttr() ! ## return "_%s_%s_%s_%s" % \ ! ## (str(la.guid)[1:-1].replace("-", "_"), ! ## la.lcid, la.wMajorVerNum, la.wMinorVerNum) ! # this string doesn't have any meaning outside (except when filtering ! # in the codegenerator by names - which we don't do for COM typelibs), ! # so it does not have to be the same as the module name. ! return "%s%s%s%s" % (la.guid, la.lcid, la.wMajorVerNum, la.wMinorVerNum) def parse_typeinfo(self, tinfo): *************** *** 480,484 **** if tlib != self.tlib: typ = typedesc.External(tlib, ! self._typelib_module(tlib), name, tlib.GetDocumentation(-1)[:2]) --- 484,488 ---- if tlib != self.tlib: typ = typedesc.External(tlib, ! ## self._typelib_module(tlib), name, tlib.GetDocumentation(-1)[:2]) *************** *** 618,621 **** --- 622,626 ---- gen = Generator(ofi, + make_module = make_module, use_decorators=sys.version_info >= (2, 4), known_symbols=known_symbols, Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.7 retrieving revision 1.6.2.8 diff -C2 -d -r1.6.2.7 -r1.6.2.8 *** codegenerator.py 30 Jun 2005 19:40:00 -0000 1.6.2.7 --- codegenerator.py 30 Jun 2005 20:16:11 -0000 1.6.2.8 *************** *** 14,20 **** class Generator(ctypes.wrap.codegenerator.Generator): ! def __init__(self, *args, **kw): self._externals = {} ! super(Generator, self).__init__(*args, **kw) def type_name(self, t, generate=True): --- 14,21 ---- class Generator(ctypes.wrap.codegenerator.Generator): ! def __init__(self, ofi, make_module=None, *args, **kw): ! self._make_module = make_module self._externals = {} ! super(Generator, self).__init__(ofi, *args, **kw) def type_name(self, t, generate=True): *************** *** 59,75 **** # def External(self, ext): ! # ext.module - the module name # ext.docs - docstring of the type library # ext.name - the full name of the type (including module name) # # XXX ext.name is used by self.type_name()! ! assert ext.tlib ! if ext.module in self._externals: return ! if ext.docs: ! print >> self.imports, "# '%s' typelib (%s)" % ext.docs print >> self.imports, "import %s" % ext.module ! self._externals[ext.module] = None ! print "NEED to generate module", ext.module def SAFEARRAYType(self, sa): --- 60,84 ---- # def External(self, ext): ! ## # ext.module - the module name # ext.docs - docstring of the type library # ext.name - the full name of the type (including module name) # # XXX ext.name is used by self.type_name()! ! if ext in self._externals: return ! if self._make_module: ! # make_module will create if needed then import the module ! # and return it. ! print "NEED to generate module", ext ! result = self._make_module(ext.tlib) ! ext.module = result.__name__ ! ext.name = "%s.%s" % (ext.module, ext.name) ! else: ! raise "CANNOT GENERATE NEEDED TYPELIB" ! ## if ext.docs: ! ## print >> self.imports, "# '%s' typelib (%s)" % ext.docs print >> self.imports, "import %s" % ext.module ! ## self._externals[ext.module] = None ! self._externals[ext] = None def SAFEARRAYType(self, sa): Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/typedesc.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** typedesc.py 30 Jun 2005 19:39:59 -0000 1.1.2.3 --- typedesc.py 30 Jun 2005 20:16:11 -0000 1.1.2.4 *************** *** 4,11 **** class External(object): ! def __init__(self, tlib, module, name, docs=None): self.tlib = tlib ! self.module = module ! self.name = "%s.%s" % (module, name) self.docs = docs --- 4,13 ---- class External(object): ! def __init__(self, tlib, name, docs=None): ! # the type library containing the symbol self.tlib = tlib ! # name of symbol ! self.name = name ! # type lib description self.docs = docs |
From: Thomas H. <th...@us...> - 2005-06-30 19:40:09
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9801 Modified Files: Tag: branch_1_0 typedesc.py tlbparser.py codegenerator.py Log Message: We have to pass the ITypeLib pointer from tlbparser through typedesc to the code generator, so that it can generate code for required typelibs. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.5 retrieving revision 1.4.2.6 diff -C2 -d -r1.4.2.5 -r1.4.2.6 *** tlbparser.py 30 Jun 2005 19:29:25 -0000 1.4.2.5 --- tlbparser.py 30 Jun 2005 19:39:59 -0000 1.4.2.6 *************** *** 478,484 **** tlib = tinfo.GetContainingTypeLib()[0] - ## print "TLIB_%s.%s" % (str(tlib.GetLibAttr().guid)[1:-1].replace("-", "_"), name) if tlib != self.tlib: ! typ = typedesc.External(self._typelib_module(tlib), name, tlib.GetDocumentation(-1)[:2]) self._register(name, typ, tlib) return typ --- 478,486 ---- tlib = tinfo.GetContainingTypeLib()[0] if tlib != self.tlib: ! typ = typedesc.External(tlib, ! self._typelib_module(tlib), ! name, ! tlib.GetDocumentation(-1)[:2]) self._register(name, typ, tlib) return typ Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.6 retrieving revision 1.6.2.7 diff -C2 -d -r1.6.2.6 -r1.6.2.7 *** codegenerator.py 30 Jun 2005 19:17:13 -0000 1.6.2.6 --- codegenerator.py 30 Jun 2005 19:40:00 -0000 1.6.2.7 *************** *** 59,67 **** # def External(self, ext): if ext.module in self._externals: return ! print >> self.imports, "# '%s' typelib (%s)" % ext.docs print >> self.imports, "import %s" % ext.module self._externals[ext.module] = None def SAFEARRAYType(self, sa): --- 59,75 ---- # def External(self, ext): + # ext.module - the module name + # ext.docs - docstring of the type library + # ext.name - the full name of the type (including module name) + # + # XXX ext.name is used by self.type_name()! + assert ext.tlib if ext.module in self._externals: return ! if ext.docs: ! print >> self.imports, "# '%s' typelib (%s)" % ext.docs print >> self.imports, "import %s" % ext.module self._externals[ext.module] = None + print "NEED to generate module", ext.module def SAFEARRAYType(self, sa): Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/typedesc.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** typedesc.py 8 Jun 2005 09:59:11 -0000 1.1.2.2 --- typedesc.py 30 Jun 2005 19:39:59 -0000 1.1.2.3 *************** *** 4,8 **** class External(object): ! def __init__(self, module, name, docs=None): self.module = module self.name = "%s.%s" % (module, name) --- 4,9 ---- class External(object): ! def __init__(self, tlib, module, name, docs=None): ! self.tlib = tlib self.module = module self.name = "%s.%s" % (module, name) |
From: Thomas H. <th...@us...> - 2005-06-30 19:29:35
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4979 Modified Files: Tag: branch_1_0 tlbparser.py Log Message: Use decorators in generated code only for those Python versions that can handle it. Cleanup imports. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.4 retrieving revision 1.4.2.5 diff -C2 -d -r1.4.2.4 -r1.4.2.5 *** tlbparser.py 30 Jun 2005 17:20:44 -0000 1.4.2.4 --- tlbparser.py 30 Jun 2005 19:29:25 -0000 1.4.2.5 *************** *** 1,6 **** ! ##from comtypes import _automation as automation ! import comtypes.automation as automation ! import comtypes.typeinfo as typeinfo ! import typedesc ################################ --- 1,5 ---- ! import sys ! from comtypes import automation, typeinfo ! from comtypes.tools import typedesc ################################ *************** *** 596,600 **** gen = Generator(sys.stdout, ! use_decorators=True, known_symbols=known_symbols, ## searched_dlls=None, --- 595,599 ---- gen = Generator(sys.stdout, ! use_decorators=sys.version_info >= (2, 4), known_symbols=known_symbols, ## searched_dlls=None, *************** *** 602,606 **** gen.generate_code(items.values()) ! def generate_module(tlib, ofi): known_symbols = {} for name in ("comtypes.typeinfo", "comtypes.automation", "comtypes", "ctypes"): --- 601,605 ---- gen.generate_code(items.values()) ! def generate_module(tlib, ofi, make_module): known_symbols = {} for name in ("comtypes.typeinfo", "comtypes.automation", "comtypes", "ctypes"): *************** *** 617,621 **** gen = Generator(ofi, ! use_decorators=True, known_symbols=known_symbols, ) --- 616,620 ---- gen = Generator(ofi, ! use_decorators=sys.version_info >= (2, 4), known_symbols=known_symbols, ) |
From: Thomas H. <th...@us...> - 2005-06-30 19:17:27
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30817 Modified Files: Tag: branch_1_0 codegenerator.py Log Message: Import DISPPROPERTY. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.5 retrieving revision 1.6.2.6 diff -C2 -d -r1.6.2.5 -r1.6.2.6 *** codegenerator.py 30 Jun 2005 17:20:44 -0000 1.6.2.5 --- codegenerator.py 30 Jun 2005 19:17:13 -0000 1.6.2.6 *************** *** 52,56 **** if self._DISPMETHOD_defined: return ! print >> self.imports, "from comtypes import DISPMETHOD" self._DISPMETHOD_defined = True --- 52,56 ---- if self._DISPMETHOD_defined: return ! print >> self.imports, "from comtypes import DISPMETHOD, DISPPROPERTY" self._DISPMETHOD_defined = True *************** *** 87,91 **** print >> self.stream, " _clsid_ = GUID(%r)" % coclass.clsid print >> self.stream, " _idlflags_ = %s" % coclass.idlflags ! print >> self.stream, "POINTER(%s).__ctypes_from_outparam__ = wrap" % coclass.name for itf, idlflags in coclass.interfaces: self.generate(itf.get_head()) --- 87,91 ---- print >> self.stream, " _clsid_ = GUID(%r)" % coclass.clsid print >> self.stream, " _idlflags_ = %s" % coclass.idlflags ! ##X print >> self.stream, "POINTER(%s).__ctypes_from_outparam__ = wrap" % coclass.name for itf, idlflags in coclass.interfaces: self.generate(itf.get_head()) |
From: Thomas H. <th...@us...> - 2005-06-30 19:16:29
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30285 Modified Files: Tag: branch_1_0 automation.py Log Message: Add IEnumVARIANT interface. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.12.2.3 retrieving revision 1.12.2.4 diff -C2 -d -r1.12.2.3 -r1.12.2.4 *** automation.py 3 Jun 2005 09:47:56 -0000 1.12.2.3 --- automation.py 30 Jun 2005 19:16:17 -0000 1.12.2.4 *************** *** 2,6 **** from ctypes import * from _ctypes import CopyComPointer ! from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR import datetime # for VT_DATE, standard in Python 2.3 and up try: --- 2,6 ---- from ctypes import * from _ctypes import CopyComPointer ! from comtypes import IUnknown, GUID, IID, STDMETHOD, BSTR, COMMETHOD, dispid import datetime # for VT_DATE, standard in Python 2.3 and up try: *************** *** 283,286 **** --- 283,322 ---- del _from_param + ################################################################ + + class IEnumVARIANT(IUnknown): + _iid_ = GUID('{00020404-0000-0000-C000-000000000046}') + _idlflags_ = ['hidden'] + def __iter__(self): + return self + + def next(self): + item, fetched = self.Next(1) + if fetched: + return item + raise StopIteration + + def __getitem__(self, index): + self.Reset() + self.Skip(index) + item, fetched = self.Next(1) + if fetched: + return item + raise IndexError, index + + from comtypes.automation import VARIANT + IEnumVARIANT._methods_ = [ + COMMETHOD([dispid(1610678272)], HRESULT, 'Next', + ( ['in'], c_ulong, 'celt' ), + ( ['in'], POINTER(VARIANT), 'rgvar' ), + ( ['out'], POINTER(c_ulong), 'pceltFetched' )), + COMMETHOD([dispid(1610678273)], HRESULT, 'Skip', + ( ['in'], c_ulong, 'celt' )), + COMMETHOD([dispid(1610678274)], HRESULT, 'Reset'), + COMMETHOD([dispid(1610678275)], HRESULT, 'Clone', + ( ['out'], POINTER(POINTER(IEnumVARIANT)), 'ppenum' )), + ] + + ##from _ctypes import VARIANT_set ##import new |
From: Thomas H. <th...@us...> - 2005-06-30 19:09:45
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26804 Modified Files: Tag: branch_1_0 __init__.py Log Message: Fake a DISPPROPERTY, so thath we can import the code we generate. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.8 retrieving revision 1.25.2.9 diff -C2 -d -r1.25.2.8 -r1.25.2.9 *** __init__.py 30 Jun 2005 17:20:34 -0000 1.25.2.8 --- __init__.py 30 Jun 2005 19:09:37 -0000 1.25.2.9 *************** *** 314,317 **** --- 314,330 ---- return COMMETHOD(idlflags, restype, name, *argspec) + def DISPPROPERTY(idlflags, proptype, name): + # XXX WRONG WRONG WRONG + #? return COMMETHOD(idlflags, HRESULT, name, ([], proptype, 'rhs') ) + return COMMETHOD(idlflags, HRESULT, name, (['out', 'retval'], POINTER(proptype), 'rhs') ) + + + ## sample generated code: + ## DISPPROPERTY([5, 'readonly'], OLE_YSIZE_HIMETRIC, 'Height'), + ## DISPMETHOD([6], None, 'Render', + ## ( [], c_int, 'hdc' ), + ## ( [], c_int, 'x' ), + ## ( [], c_int, 'y' )) + ################################################################ |
From: Thomas H. <th...@us...> - 2005-06-30 17:24:18
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9076 Added Files: Tag: branch_1_0 test_safearray.py Log Message: Some tests for safearrays. --- NEW FILE: test_safearray.py --- import unittest, os from ctypes import * from ctypes.com import IUnknown, GUID from ctypes.com.automation import VARIANT, LoadTypeLibEx, \ VT_ARRAY, VT_VARIANT, VT_I4, VT_INT, oleaut32, IDispatch # test VT_ARRAY in VARIANTS class SAFEARRAYTest(unittest.TestCase): def test_VT_VARIANT(self): v = VARIANT() # lists... v.value = [1, "spam", [None, "foo"]] self.failUnlessEqual(v.value, [1, "spam", [None, "foo"]]) self.failUnlessEqual(v.vt, VT_VARIANT | VT_ARRAY) dim = oleaut32.SafeArrayGetDim(v._.voidp) self.failUnlessEqual(dim, 1) # and tuples. v.value = (1, "spam", (None, "foo")) self.failUnlessEqual(v.value, [1, "spam", [None, "foo"]]) def test_VT_INT(self): import array data = array.array("i", (1, 2, 3, 4, 5)) v = VARIANT() v.value = data self.failUnlessEqual(v.vt, VT_INT | VT_ARRAY) dim = oleaut32.SafeArrayGetDim(v._.voidp) self.failUnlessEqual(dim, 1) def _getrefcnt(self, comobj): comobj.AddRef() return comobj.Release() def test_VT_UNKNOWN(self): tlb = LoadTypeLibEx(r"c:\windows\system32\shdocvw.dll") self.failUnlessEqual(self._getrefcnt(tlb), 1) v = VARIANT() v.value = tlb self.failUnlessEqual(self._getrefcnt(tlb), 2) v.value = None self.failUnlessEqual(self._getrefcnt(tlb), 1) v.value = [tlb] self.failUnlessEqual(self._getrefcnt(tlb), 2) pcom = v.value[0] self.failUnlessEqual(self._getrefcnt(tlb), 3) self.failUnlessEqual(self._getrefcnt(pcom), 3) # ITypeLib derives from IUnknown, and VARIANT can only store IUnknown or IDispatch # pointers, so: self.failUnlessEqual(type(pcom), POINTER(IUnknown)) del pcom self.failUnlessEqual(self._getrefcnt(tlb), 2) v.value = None self.failUnlessEqual(self._getrefcnt(tlb), 1) def test_VT_DISPATCH(self): from ctypes.com.client import Dispatch p = Dispatch("MSScriptControl.ScriptControl") # any inproc IDispatch will do pdisp = p._comobj self.failUnlessEqual(self._getrefcnt(pdisp), 1) v = VARIANT() v.value = pdisp self.failUnlessEqual(self._getrefcnt(pdisp), 2) v.value = None self.failUnlessEqual(self._getrefcnt(pdisp), 1) v.value = [pdisp] self.failUnlessEqual(self._getrefcnt(pdisp), 2) pcom = v.value[0] self.failUnlessEqual(self._getrefcnt(pdisp), 3) self.failUnlessEqual(self._getrefcnt(pcom), 3) # ITypeLib derives from IUnknown, and VARIANT can only store IUnknown or IDispatch # pointers, so: self.failUnlessEqual(type(pcom), POINTER(IDispatch)) del pcom self.failUnlessEqual(self._getrefcnt(pdisp), 2) v.value = None self.failUnlessEqual(self._getrefcnt(pdisp), 1) ## def test_multidim() if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-06-30 17:20:53
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7708 Modified Files: Tag: branch_1_0 tlbparser.py codegenerator.py Log Message: Rename __ctypes_from_outparm__ to __ctypes_from_outparam__. Generate code for __ctypes_from_outparam__. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.3 retrieving revision 1.4.2.4 diff -C2 -d -r1.4.2.3 -r1.4.2.4 *** tlbparser.py 8 Jun 2005 10:01:41 -0000 1.4.2.3 --- tlbparser.py 30 Jun 2005 17:20:44 -0000 1.4.2.4 *************** *** 466,470 **** tlib = self.tlib la = tlib.GetLibAttr() ! return "tlb_%s_%s_%s_%s" % \ (str(la.guid)[1:-1].replace("-", "_"), la.lcid, la.wMajorVerNum, la.wMinorVerNum) --- 466,470 ---- tlib = self.tlib la = tlib.GetLibAttr() ! return "_%s_%s_%s_%s" % \ (str(la.guid)[1:-1].replace("-", "_"), la.lcid, la.wMajorVerNum, la.wMinorVerNum) *************** *** 602,606 **** gen.generate_code(items.values()) ! def test(tlib, ofi): known_symbols = {} for name in ("comtypes.typeinfo", "comtypes.automation", "comtypes", "ctypes"): --- 602,606 ---- gen.generate_code(items.values()) ! def generate_module(tlib, ofi): known_symbols = {} for name in ("comtypes.typeinfo", "comtypes.automation", "comtypes", "ctypes"): *************** *** 619,645 **** use_decorators=True, known_symbols=known_symbols, - ## searched_dlls=None, ) gen.generate_code(items.values()) if __name__ == "__main__": ! if 0: ! main() ! else: ! from comtypes.typeinfo import LoadRegTypeLib, LoadTypeLibEx ! from comtypes import GUID ! ## tlib = LoadTypeLibEx(r"c:\tss5\include\fpanel.tlb") ! ## tlib = LoadRegTypeLib(GUID("{6BC096BB-0CE6-11D1-BAAE-00C04FC2E20D}"), 1, 0) ! ! # stdole32 ! ## tlib = LoadRegTypeLib(GUID("{00020430-0000-0000-C000-000000000046}"), 1, 0) ! # from comtypes.typeinfo import QueryPathOfRegTypeLib ! # print QueryPathOfRegTypeLib(GUID("{00020430-0000-0000-C000-000000000046}"), 1, 0) ! ## import sys ! ## sys.exit() ! ## return ! tlib = LoadTypeLibEx(r"c:\progra~1\micros~3\Office\MSWORD8.OLB") ! ## tlib = LoadTypeLibEx(r"mshtml.tlb") ! import sys ! test(tlib, sys.stdout) --- 619,629 ---- use_decorators=True, known_symbols=known_symbols, ) gen.generate_code(items.values()) if __name__ == "__main__": ! from comtypes.typeinfo import LoadRegTypeLib, LoadTypeLibEx ! from comtypes import GUID ! tlib = LoadRegTypeLib(GUID("{0002E157-0000-0000-C000-000000000046}"), 5, 0) ! generate_module(tlib, open("_0002E157_0000_0000_C000_000000000046_0_5_0.py", "w")) Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.4 retrieving revision 1.6.2.5 diff -C2 -d -r1.6.2.4 -r1.6.2.5 *** codegenerator.py 29 Jun 2005 15:58:00 -0000 1.6.2.4 --- codegenerator.py 30 Jun 2005 17:20:44 -0000 1.6.2.5 *************** *** 87,97 **** print >> self.stream, " _clsid_ = GUID(%r)" % coclass.clsid print >> self.stream, " _idlflags_ = %s" % coclass.idlflags for itf, idlflags in coclass.interfaces: self.generate(itf.get_head()) - if coclass.interfaces: - # Hm. - print >> self.stream, "from ctypes import _pointer_type_cache" - print >> self.stream, "_pointer_type_cache[%s] = POINTER(%s)" % \ - (coclass.name, coclass.interfaces[0][0].name) implemented = [i[0].name for i in coclass.interfaces if i[1] & 2 == 0] --- 87,93 ---- print >> self.stream, " _clsid_ = GUID(%r)" % coclass.clsid print >> self.stream, " _idlflags_ = %s" % coclass.idlflags + print >> self.stream, "POINTER(%s).__ctypes_from_outparam__ = wrap" % coclass.name for itf, idlflags in coclass.interfaces: self.generate(itf.get_head()) implemented = [i[0].name for i in coclass.interfaces if i[1] & 2 == 0] |
From: Thomas H. <th...@us...> - 2005-06-30 17:20:43
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7601 Modified Files: Tag: branch_1_0 __init__.py Log Message: Rename __ctypes_from_outparm__ to __ctypes_from_outparam__. Generate code for __ctypes_from_outparam__. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.7 retrieving revision 1.25.2.8 diff -C2 -d -r1.25.2.7 -r1.25.2.8 *** __init__.py 30 Jun 2005 13:17:07 -0000 1.25.2.7 --- __init__.py 30 Jun 2005 17:20:34 -0000 1.25.2.8 *************** *** 100,104 **** p = type(_compointer_base)("POINTER(%s)" % cls.__name__, _ptr_bases, ! {"__ctypes_from_outparm__": lambda self: self}) from ctypes import _pointer_type_cache _pointer_type_cache[cls] = p --- 100,104 ---- p = type(_compointer_base)("POINTER(%s)" % cls.__name__, _ptr_bases, ! {"__ctypes_from_outparam__": lambda self: self}) from ctypes import _pointer_type_cache _pointer_type_cache[cls] = p *************** *** 148,152 **** func = prototype(i + vtbl_offset, name, paramflags) func.__doc__ = doc ! # make it an unbound method, so we don't have to pass 'self' mth = new.instancemethod(func, None, self) --- 148,152 ---- func = prototype(i + vtbl_offset, name, paramflags) func.__doc__ = doc ! # make it an unbound method. Remember, 'self' is a type here. mth = new.instancemethod(func, None, self) *************** *** 164,167 **** --- 164,170 ---- nargs = len([flags for flags in paramflags if flags[0] & 1]) + # XXX or should we do this? + # nargs = len([flags for flags in paramflags + # if (flags[0] & 1) or (flags[0] == 0)]) propname = name[len("_get_"):] getters[propname, doc, nargs] = func *************** *** 233,236 **** --- 236,241 ---- return bound_named_property(self.getter, self.setter, im_inst) + ################################################################ + class _compointer_meta(type(c_void_p), _cominterface_meta): "metaclass for COM interface pointer classes" *************** *** 478,481 **** --- 483,487 ---- ################################################################ + # IUnknown, the root of all evil... class IUnknown(object): *************** *** 510,513 **** --- 516,522 ---- # should these methods be in a mixin class, which the metaclass # adds when it detects the Count, Item, and _NewEnum methods? + # + # Hm, codegenerator adds __iter__, next, and __getitem__ when + # it detects an IEnumXXX interface... def __len__(self): try: *************** *** 555,562 **** "pass" ! # The code generation assigns a __ctypes_from_outparm__ to each # POINTER(<coclass>) when the <coclass> is generated. Maybe we could # avoid having c_void_p as baseclass in CoClass, generate the ! # __ctypes_from_outparm__ method in a metaclass, and also have the # metaclass mix in the c_void_p (or whatever) into the POINTER(...) # type? See the IUnknown magic... --- 564,571 ---- "pass" ! # The code generation assigns a __ctypes_from_outparam__ to each # POINTER(<coclass>) when the <coclass> is generated. Maybe we could # avoid having c_void_p as baseclass in CoClass, generate the ! # __ctypes_from_outparam__ method in a metaclass, and also have the # metaclass mix in the c_void_p (or whatever) into the POINTER(...) # type? See the IUnknown magic... |
From: Thomas H. <th...@us...> - 2005-06-30 14:37:06
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24318 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Rename __ctypes_from_outparm__ to __ctypes_from_outparam__. Install a default __ctypes_from_outparam__ in all ctypes types, this simplyfies and speeds up the _get_one() function. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.13 retrieving revision 1.226.2.14 diff -C2 -d -r1.226.2.13 -r1.226.2.14 *** _ctypes.c 29 Jun 2005 15:39:01 -0000 1.226.2.13 --- _ctypes.c 30 Jun 2005 14:36:52 -0000 1.226.2.14 *************** *** 1754,1757 **** --- 1754,1772 ---- } + /* + * default __ctypes_from_outparam__ method returns self. + */ + static PyObject * + CData_from_outparam(PyObject *self, PyObject *args) + { + Py_INCREF(self); + return self; + } + + static PyMethodDef CData_methods[] = { + { "__ctypes_from_outparam__", CData_from_outparam, METH_NOARGS, }, + { NULL, NULL }, + }; + PyTypeObject CData_Type = { PyObject_HEAD_INIT(NULL) *************** *** 1782,1787 **** 0, /* tp_weaklistoffset */ 0, /* tp_iter */ ! 0, /* tp_iternext */ ! 0, /* tp_methods */ CData_members, /* tp_members */ 0, /* tp_getset */ --- 1797,1801 ---- 0, /* tp_weaklistoffset */ 0, /* tp_iter */ ! 0, /* tp_iternext */ CData_methods, /* tp_methods */ CData_members, /* tp_members */ 0, /* tp_getset */ *************** *** 2708,2746 **** _get_one(PyObject *obj) { PyCArgObject *arg = (PyCArgObject *)obj; ! PyObject *result = arg->obj; ! StgDictObject *dict = PyObject_stgdict(result); ! ! /* ! XXX See large comment in comtypes.COMMETHOD. ! ! Hm. We really need a way to override getfunc in subclasses. ! */ ! { ! PyObject *mth = PyObject_GetAttrString(result, "__ctypes_from_outparm__"); ! if (mth == NULL) ! PyErr_Clear(); ! else { ! PyObject *r = PyObject_CallObject(mth, NULL); ! Py_DECREF(mth); ! return r; ! } ! } ! if (result->ob_type != &SimpleType_Type ! && dict->proto ! && PyString_CheckExact(dict->proto) ! && (PyString_AS_STRING(dict->proto)[0] == 'P')) { ! /* It's an instance of a subclass of c_void_p: return as is. ! * Required for COM. ! */ ! Py_INCREF(result); ! return result; ! } ! if (dict->getfunc) { ! CDataObject *c = (CDataObject *)result; ! return dict->getfunc(c->b_ptr, c->b_size); ! } ! Py_INCREF(result); ! return result; } --- 2722,2731 ---- _get_one(PyObject *obj) { + /* + __ctypes_from_outparam__ lets of specify how 'out' parameters are retrieved + from COM method class. + */ PyCArgObject *arg = (PyCArgObject *)obj; ! return PyObject_CallMethod(arg->obj, "__ctypes_from_outparam__", NULL); } *************** *** 3520,3523 **** --- 3505,3520 ---- }; + static PyObject * + Simple_from_outparm(PyObject *self, PyObject *args) + { + /* call stgdict->getfunc */ + return Simple_get_value((CDataObject *)self); + } + + static PyMethodDef Simple_methods[] = { + { "__ctypes_from_outparam__", Simple_from_outparm, METH_NOARGS, }, + { NULL, NULL }, + }; + static PyTypeObject Simple_Type = { PyObject_HEAD_INIT(NULL) *************** *** 3549,3553 **** 0, /* tp_iter */ 0, /* tp_iternext */ ! 0, /* tp_methods */ 0, /* tp_members */ Simple_getsets, /* tp_getset */ --- 3546,3550 ---- 0, /* tp_iter */ 0, /* tp_iternext */ ! Simple_methods, /* tp_methods */ 0, /* tp_members */ Simple_getsets, /* tp_getset */ |
From: Thomas H. <th...@us...> - 2005-06-30 13:17:23
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16255 Modified Files: Tag: branch_1_0 __init__.py Log Message: Slight reorg. CoClass derives from c_void_p, and ideas how to avoid this. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.6 retrieving revision 1.25.2.7 diff -C2 -d -r1.25.2.6 -r1.25.2.7 *** __init__.py 10 Jun 2005 19:57:08 -0000 1.25.2.6 --- __init__.py 30 Jun 2005 13:17:07 -0000 1.25.2.7 *************** *** 100,104 **** p = type(_compointer_base)("POINTER(%s)" % cls.__name__, _ptr_bases, ! {}) from ctypes import _pointer_type_cache _pointer_type_cache[cls] = p --- 100,104 ---- p = type(_compointer_base)("POINTER(%s)" % cls.__name__, _ptr_bases, ! {"__ctypes_from_outparm__": lambda self: self}) from ctypes import _pointer_type_cache _pointer_type_cache[cls] = p *************** *** 114,118 **** try: return sum([len(itf.__dict__["_methods_"]) ! for itf in self.__mro__[1:-1]]) except KeyError, (name,): if name == "_methods_": --- 114,118 ---- try: return sum([len(itf.__dict__["_methods_"]) ! for itf in self.mro()[1:-1]]) except KeyError, (name,): if name == "_methods_": *************** *** 202,205 **** --- 202,209 ---- setattr(self, name, prop) + ################################################################ + # helper classes for COM propget / propput + # Should they be implemented in C for speed? + class bound_named_property(object): def __init__(self, getter, setter, im_inst): *************** *** 229,241 **** return bound_named_property(self.getter, self.setter, im_inst) - class NotYetImplemented(Warning): - pass - - # metaclass for COM interface pointer classes class _compointer_meta(type(c_void_p), _cominterface_meta): ! pass - # base class for COM interface pointer classes class _compointer_base(c_void_p): __metaclass__ = _compointer_meta def __del__(self): --- 233,242 ---- return bound_named_property(self.getter, self.setter, im_inst) class _compointer_meta(type(c_void_p), _cominterface_meta): ! "metaclass for COM interface pointer classes" ! # (no functionality, but avoids a metaclass confict) class _compointer_base(c_void_p): + "base class for COM interface pointer classes" __metaclass__ = _compointer_meta def __del__(self): *************** *** 247,253 **** def __nonzero__(self): # get the .value property of the baseclass, this is the pointer value - # both variants below do the same, and both are equally unreadable ;-) return bool(super(_compointer_base, self).value) - ## return bool(c_void_p.value.__get__(self)) def __cmp__(self, other): --- 248,252 ---- *************** *** 279,282 **** --- 278,282 ---- class BSTR(_SimpleCData): + "The windows BSTR data type" _type_ = "X" def __repr__(self): *************** *** 287,290 **** --- 287,291 ---- ################################################################ + # IDL stuff class helpstring(object): *************** *** 299,302 **** --- 300,312 ---- pass + def STDMETHOD(restype, name, argtypes=()): + "Specifies a COM method slot without idlflags" + # restype, name, argtypes, paramflags, idlflags, docstring + return restype, name, argtypes, None, (), None + + def DISPMETHOD(idlflags, restype, name, *argspec): + # XXX WRONG WRONG WRONG + return COMMETHOD(idlflags, restype, name, *argspec) + ################################################################ *************** *** 314,321 **** return result & 3 # that's what _ctypes accept - def DISPMETHOD(idlflags, restype, name, *argspec): - # XXX WRONG WRONG WRONG - return COMMETHOD(idlflags, restype, name, *argspec) - _NOTHING = object() def _unpack_argspec(idl, typ, name=None, defval=_NOTHING): --- 324,327 ---- *************** *** 436,442 **** # comtypes.automation sets it from the outside into # this module, when it is imported. Hack, hack. - # - # XXX Should probably use a different name, so that it - # can't be imported from this module by accident. if _VARIANT_type_hack and typ is _VARIANT_type_hack: # XXX make this a classmethod of VARIANT! --- 442,445 ---- *************** *** 474,482 **** return restype, methodname, tuple(argtypes), tuple(paramflags), tuple(idlflags), helptext - def STDMETHOD(restype, name, argtypes=()): - "Specifies a COM method slot without idlflags" - # restype, name, argtypes, paramflags, idlflags, docstring - return restype, name, argtypes, None, (), None - ################################################################ --- 477,480 ---- *************** *** 554,560 **** ################ ! class CoClass(object): "pass" # creation, and so on --- 552,564 ---- ################ ! class CoClass(c_void_p): "pass" + # The code generation assigns a __ctypes_from_outparm__ to each + # POINTER(<coclass>) when the <coclass> is generated. Maybe we could + # avoid having c_void_p as baseclass in CoClass, generate the + # __ctypes_from_outparm__ method in a metaclass, and also have the + # metaclass mix in the c_void_p (or whatever) into the POINTER(...) + # type? See the IUnknown magic... # creation, and so on |
From: Thomas H. <th...@us...> - 2005-06-29 15:58:09
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25574 Modified Files: Tag: branch_1_0 codegenerator.py Log Message: Generate Python support for IEnumXXX interfaces. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.4 diff -C2 -d -r1.6.2.3 -r1.6.2.4 *** codegenerator.py 8 Jun 2005 09:58:37 -0000 1.6.2.3 --- codegenerator.py 29 Jun 2005 15:58:00 -0000 1.6.2.4 *************** *** 108,111 **** --- 108,121 ---- self.generate(itf.get_body()) + def _is_enuminterface(self, itf): + # Check if this is an IEnumXXX interface + if not itf.name.startswith("IEnum"): + return False + member_names = [mth.name for mth in itf.members] + for name in ("Next", "Skip", "Reset", "Clone"): + if name not in member_names: + return False + return True + def ComInterfaceHead(self, head): self.generate(head.itf.base) *************** *** 117,120 **** --- 127,166 ---- print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags + if self._is_enuminterface(head.itf): + print >> self.stream, " def __iter__(self):" + print >> self.stream, " return self" + print >> self.stream + + # Well, not sure if they are really broken, but sometimes + # the last parameter to Next is marked [in, out], + # sometimes it is only [out]. + NextIsBroken = False + for mth in head.itf.members: + if mth.name == "Next": + NextIsBroken = 'in' in mth.arguments[-1][2] + break + + print >> self.stream, " def next(self):" + if NextIsBroken: + print >> self.stream, " item, fetched = self.Next(1, 0)" + else: + print >> self.stream, " item, fetched = self.Next(1)" + print >> self.stream, " if fetched:" + print >> self.stream, " return item" + print >> self.stream, " raise StopIteration" + print >> self.stream + + print >> self.stream, " def __getitem__(self, index):" + print >> self.stream, " self.Reset()" + print >> self.stream, " self.Skip(index)" + if NextIsBroken: + print >> self.stream, " item, fetched = self.Next(1, 0)" + else: + print >> self.stream, " item, fetched = self.Next(1)" + print >> self.stream, " if fetched:" + print >> self.stream, " return item" + print >> self.stream, " raise IndexError, index" + print >> self.stream + def ComInterfaceBody(self, body): # make sure we can generate the body |
From: Thomas H. <th...@us...> - 2005-06-29 15:39:10
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14741 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Reformulate a docstring. Try to call a __ctypes_from_outparm__ method in _get_one(). Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.12 retrieving revision 1.226.2.13 diff -C2 -d -r1.226.2.12 -r1.226.2.13 *** _ctypes.c 20 May 2005 20:09:18 -0000 1.226.2.12 --- _ctypes.c 29 Jun 2005 15:39:01 -0000 1.226.2.13 *************** *** 1716,1720 **** { "_objects", T_OBJECT, offsetof(CDataObject, b_objects), READONLY, ! "internal objects tree (NEVER CHANGE THIS LIST!)"}, { NULL }, }; --- 1716,1720 ---- { "_objects", T_OBJECT, offsetof(CDataObject, b_objects), READONLY, ! "internal objects tree (NEVER CHANGE THIS OBJECT!)"}, { NULL }, }; *************** *** 2713,2727 **** /* ! XXX See comments in comtypes::COMMETHOD2. Urgent need to clean this up: ! replace with a _from_outparam_ slot call. */ ! if (dict-> proto && PyString_CheckExact(dict->proto)) { ! char *tag = PyString_AS_STRING(dict->proto); ! /* simple data type, but no pointer */ ! if (tag[0] == 'P') { ! Py_INCREF(result); ! return result; } } if (dict->getfunc) { CDataObject *c = (CDataObject *)result; --- 2713,2740 ---- /* ! XXX See large comment in comtypes.COMMETHOD. ! ! Hm. We really need a way to override getfunc in subclasses. */ ! { ! PyObject *mth = PyObject_GetAttrString(result, "__ctypes_from_outparm__"); ! if (mth == NULL) ! PyErr_Clear(); ! else { ! PyObject *r = PyObject_CallObject(mth, NULL); ! Py_DECREF(mth); ! return r; } } + if (result->ob_type != &SimpleType_Type + && dict->proto + && PyString_CheckExact(dict->proto) + && (PyString_AS_STRING(dict->proto)[0] == 'P')) { + /* It's an instance of a subclass of c_void_p: return as is. + * Required for COM. + */ + Py_INCREF(result); + return result; + } if (dict->getfunc) { CDataObject *c = (CDataObject *)result; |
From: Thomas H. <th...@us...> - 2005-06-10 19:57:18
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23909 Modified Files: Tag: branch_1_0 __init__.py Log Message: Update todo comments. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.5 retrieving revision 1.25.2.6 diff -C2 -d -r1.25.2.5 -r1.25.2.6 *** __init__.py 8 Jun 2005 09:40:29 -0000 1.25.2.5 --- __init__.py 10 Jun 2005 19:57:08 -0000 1.25.2.6 *************** *** 185,188 **** --- 185,189 ---- # create public properties / attribute accessors + # XXX Das sieht mir aber komisch aus! for item in set(getters.keys()) | set(getters.keys()): name, doc, nargs = item *************** *** 390,401 **** # ! # Another use case for this is a coclass* in the parameter list. ! # According to MSDN, this means the same as IUnknown*. ! # So, we could make IUnknown a base class of CoClass so that ! # it is a ctypes type at least. Or should some metaclass magic ! # make a CoClass a subclass of the coclass's default com interface? # ! # But, this doesn't seem to be compatible with the role that the ! # CoClass would play with COM server stuff. for item in argspec: --- 391,429 ---- # ! # What about coclass* in the parameter list? According to MSDN, ! # this means the same as IUnknown*. ! # So, it seems we should QueryInterface the received pointer ! # for a 'better' interface, maybe the coclass' default interface? # ! # Several problems to solve: ! # - How to preserve the type information in the generated code? ! # ! # The coclass could have the default interface as base class. ! # ! # The code generation could insert in entry into the ! # _pointer_type_cache, so that ! # POINTER(<coclass>) == <default_interface> ! # ! # The generated code could look like this (in STDMETHOD): ! # ..., POINTER(<coclass>._com_interfaces_[0] ! # ! # Best would be if we could insert something that ! # would allow the get_one() function to call specialized ! # code that would QI for the default interface, and still ! # contains the coclass itself. ! ! # Hm. This: ! # ! # class App(coclass): ! # _ctype_ = IDefaultInterface ! # @classmethod ! # def from_param(self, parm): ! # ... ! # def from_outparm(self, value): ! # # value is an instance of self._ctype_ ! # ... ! # ! # All this needs to be specified very carefully. And I should ! # collect links to ctypes-users posts where this was discussed. for item in argspec: |
From: Thomas H. <th...@us...> - 2005-06-10 18:21:49
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5925 Modified Files: Tag: branch_1_0 __init__.py Log Message: Document the full function signatures of CFUNCTYPE and WINFUNCTYPE. DRY: Get the WINFUNCTYPE docstring from CFUNCTYPE's docstring. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.6 retrieving revision 1.61.2.7 diff -C2 -d -r1.61.2.6 -r1.61.2.7 *** __init__.py 15 Apr 2005 18:20:25 -0000 1.61.2.6 --- __init__.py 10 Jun 2005 18:21:40 -0000 1.61.2.7 *************** *** 76,82 **** callable object: ! prototype(vtbl_index, method_name) - a function that calls a COM method ! prototype(callable) - returns a C callable function that calls callable ! prototype(funct_name, dll) - a function that calls an exported function in a dll """ try: --- 76,82 ---- callable object: ! prototype(funct) - returns a C callable function calling funct ! prototype(vtbl_index, method_name[, paramflags]) - a Python callable that calls a COM method ! prototype(funct_name, dll[, paramflags]) - a Python callable that calls an exported function in a dll """ try: *************** *** 98,113 **** _win_functype_cache = {} def WINFUNCTYPE(restype, *argtypes): ! """WINFUNCTYPE(restype, *argtypes) -> function prototype. ! ! restype: the result type ! argtypes: a sequence specifying the argument types ! ! The function prototype can be called in three ways to create a ! callable object: ! ! prototype(vtbl_index, method_name) - a function that calls a COM method ! prototype(callable) - returns a C callable function that calls callable ! prototype(funct_name, dll) - a function that calls an exported function in a dll ! """ try: return _win_functype_cache[(restype, argtypes)] --- 98,102 ---- _win_functype_cache = {} def WINFUNCTYPE(restype, *argtypes): ! # docstring set later (very similar to CFUNCTYPE.__doc__) try: return _win_functype_cache[(restype, argtypes)] *************** *** 119,122 **** --- 108,112 ---- _win_functype_cache[(restype, argtypes)] = WinFunctionType return WinFunctionType + WINFUNCTYPE.__doc__ = CFUNCTYPE.__doc__.replace("CFUNCTYPE", "WINFUNCTYPE") elif _os.name == "posix": |
From: Thomas H. <th...@us...> - 2005-06-10 08:28:26
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11605 Removed Files: Tag: branch_1_0 helpers.py Log Message: No longer needed. --- helpers.py DELETED --- |
From: Thomas H. <th...@us...> - 2005-06-09 19:23:24
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28042 Modified Files: Tag: branch_1_0 typeinfo.py Log Message: Wrap ITypeInfo::CreateInstance. Index: typeinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/typeinfo.py,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -C2 -d -r1.3.2.3 -r1.3.2.4 *** typeinfo.py 8 Jun 2005 10:06:15 -0000 1.3.2.3 --- typeinfo.py 9 Jun 2005 19:23:15 -0000 1.3.2.4 *************** *** 295,298 **** --- 295,303 ---- ## STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), + def CreateInstance(self, punkouter=None, interface=IUnknown, iid=None): + if iid is None: + iid = interface._iid_ + return self._CreateInstance(punkouter, byref(interface._iid_)) + ## def GetMops(self, index): ## "Get marshalling opcodes (whatever that is...)" *************** *** 543,547 **** (['out'], POINTER(POINTER(ITypeInfo)))), STDMETHOD(HRESULT, 'AddressOfMember', [MEMBERID, INVOKEKIND, POINTER(PVOID)]), ! STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), COMMETHOD([], HRESULT, 'GetMops', (['in'], MEMBERID, 'memid'), --- 548,555 ---- (['out'], POINTER(POINTER(ITypeInfo)))), STDMETHOD(HRESULT, 'AddressOfMember', [MEMBERID, INVOKEKIND, POINTER(PVOID)]), ! COMMETHOD([], HRESULT, 'CreateInstance', ! (['in'], POINTER(IUnknown), 'pUnkOuter'), ! (['in'], POINTER(IID), 'refiid'), ! (['out'], POINTER(POINTER(IUnknown)))), COMMETHOD([], HRESULT, 'GetMops', (['in'], MEMBERID, 'memid'), |
From: Thomas H. <th...@us...> - 2005-06-08 10:07:10
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19785 Modified Files: Tag: branch_1_0 test_typeinfo.py Log Message: ITypeInfo.GetContainingTypeLib() return values changed their order. Index: test_typeinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/test_typeinfo.py,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** test_typeinfo.py 10 Mar 2005 14:37:52 -0000 1.3 --- test_typeinfo.py 8 Jun 2005 10:06:57 -0000 1.3.2.1 *************** *** 33,37 **** tlib.GetTypeInfoType(i) ! index, c_tlib = ti.GetContainingTypeLib() self.failUnlessEqual(c_tlib, tlib) self.failUnlessEqual(index, i) --- 33,37 ---- tlib.GetTypeInfoType(i) ! c_tlib, index = ti.GetContainingTypeLib() self.failUnlessEqual(c_tlib, tlib) self.failUnlessEqual(index, i) |
From: Thomas H. <th...@us...> - 2005-06-08 10:06:25
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19484 Modified Files: Tag: branch_1_0 typeinfo.py Log Message: Use COMMETHOD instead of STDMETHOD to get automatic, high-level wrapping of client side COM methods. Index: typeinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/typeinfo.py,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -C2 -d -r1.3.2.2 -r1.3.2.3 *** typeinfo.py 2 Jun 2005 12:07:16 -0000 1.3.2.2 --- typeinfo.py 8 Jun 2005 10:06:15 -0000 1.3.2.3 *************** *** 175,178 **** --- 175,187 ---- ################################################################ + # a helper + def _deref_with_release(ptr, release): + # Given a POINTER instance, return the pointed to value. + # Call the 'release' function with 'ptr' to release resources + # when the value is no longer needed. + result = ptr[0] + result.__ref__ = weakref.ref(result, lambda dead: release(ptr)) + return result + # interfaces *************** *** 180,237 **** _iid_ = GUID("{00020402-0000-0000-C000-000000000046}") ! def GetTypeInfoCount(self): ! "Return the number of type informations" ! return self.__com_GetTypeInfoCount() ! def GetTypeInfo(self, index): ! "Load type info by index" ! ti = POINTER(ITypeInfo)() ! self.__com_GetTypeInfo(index, byref(ti)) ! return ti ! def GetTypeInfoType(self, index): ! "Return the TYPEKIND of type information" ! tkind = TYPEKIND() ! self.__com_GetTypeInfoType(index, byref(tkind)) ! return tkind.value def GetTypeInfoOfGuid(self, guid): "Return type information for a guid" ! ti = POINTER(ITypeInfo)() ! self.__com_GetTypeInfoOfGuid(byref(guid), byref(ti)) ! return ti def GetLibAttr(self): "Return type library attributes" ! ptla = POINTER(TLIBATTR)() ! self.__com_GetLibAttr(byref(ptla)) ! result = ptla[0] ! result.__ref__ = weakref.ref(result, lambda dead: self.ReleaseTLibAttr(ptla)) ! return result ! def GetTypeComp(self): ! "Return an ITypeComp pointer." ! tc = POINTER(ITypeComp)() ! self.__com_GetTypeComp(byref(tc)) ! return tc ! def GetDocumentation(self, index): ! "Return documentation for a type description." ! name = BSTR() ! docstring = BSTR() ! helpcontext = DWORD() ! helpfile = BSTR() ! self.__com_GetDocumentation(index, byref(name), byref(docstring), ! byref(helpcontext), byref(helpfile)) ! return name.value, docstring.value, helpcontext.value, helpfile.value ! def IsName(self, name, lHashVal=0): ! "Check if there is type information for this name" ! result = BOOL() ! self.__com_IsName(name, lHashVal, byref(result)) ! return result.value def FindName(self, name, lHashVal=0): # Hm... found = c_ushort(1) tinfo = POINTER(ITypeInfo)() --- 189,227 ---- _iid_ = GUID("{00020402-0000-0000-C000-000000000046}") ! # Commented out methods use the default implementation that comtypes ! # automatically creates for COM methods. ! ! ## def GetTypeInfoCount(self): ! ## "Return the number of type informations" ! ## def GetTypeInfo(self, index): ! ## "Load type info by index" ! ## def GetTypeInfoType(self, index): ! ## "Return the TYPEKIND of type information" def GetTypeInfoOfGuid(self, guid): "Return type information for a guid" ! return self._GetTypeInfoOfGuid(byref(guid)) def GetLibAttr(self): "Return type library attributes" ! return _deref_with_release(self._GetLibAttr(), self.ReleaseTLibAttr) ! ## def GetTypeComp(self): ! ## "Return an ITypeComp pointer." ! ## def GetDocumentation(self, index): ! ## "Return documentation for a type description." ! # Oops: IsName modifies the case of the passed in buffer, ! # if the value is found. ! # XXX MUST BE FIXED! ! ## def IsName(self, name, lHashVal=0): ! ## "Check if there is type information for this name" def FindName(self, name, lHashVal=0): # Hm... + # Could search for more than one name - should we support this? found = c_ushort(1) tinfo = POINTER(ITypeInfo)() *************** *** 241,247 **** return memid.value, tinfo ! def ReleaseTLibAttr(self, ptla): ! "Release TLIBATTR" ! self.__com_ReleaseTLibAttr(ptla) ################ --- 231,236 ---- return memid.value, tinfo ! ## def ReleaseTLibAttr(self, ptla): ! ## "Release TLIBATTR" ################ *************** *** 251,282 **** def GetTypeAttr(self): ! "Return TYPEATTR for this type" ! pta = POINTER(TYPEATTR)() ! self.__com_GetTypeAttr(byref(pta)) ! result = pta[0] ! result.__ref__ = weakref.ref(result, lambda dead: self.ReleaseTypeAttr(pta)) ! return result ! def GetTypeComp(self): ! "Return ITypeComp pointer for this type" ! tc = POINTER(ITypeComp)() ! self.__com_GetTypeComp(byref(tc)) ! return tc def GetFuncDesc(self, index): "Return FUNCDESC for index" ! pfd = POINTER(FUNCDESC)() ! self.__com_GetFuncDesc(index, byref(pfd)) ! fd = pfd[0] ! fd.__ref__ = weakref.ref(fd, lambda dead: self.ReleaseFuncDesc(pfd)) ! return fd def GetVarDesc(self, index): "Return VARDESC for index" ! pvd = POINTER(VARDESC)() ! self.__com_GetVarDesc(index, byref(pvd)) ! vd = pvd[0] ! vd.__ref__ = weakref.ref(vd, lambda dead: self.ReleaseVarDesc(pvd)) ! return vd def GetNames(self, memid, count=1): --- 240,256 ---- def GetTypeAttr(self): ! "Return the TYPEATTR for this type" ! return _deref_with_release(self._GetTypeAttr(), self.ReleaseTypeAttr) ! ## def GetTypeComp(self): ! ## "Return ITypeComp pointer for this type" def GetFuncDesc(self, index): "Return FUNCDESC for index" ! return _deref_with_release(self._GetFuncDesc(index), self.ReleaseFuncDesc) def GetVarDesc(self, index): "Return VARDESC for index" ! return _deref_with_release(self._GetVarDesc(index), self.ReleaseVarDesc) def GetNames(self, memid, count=1): *************** *** 287,301 **** return names[:cnames.value] ! def GetRefTypeOfImplType(self, index): ! "Get the reftype of an implemented type" ! href = HREFTYPE() ! self.__com_GetRefTypeOfImplType(index, byref(href)) ! return href.value ! def GetImplTypeFlags(self, index): ! "Get IMPLTYPEFLAGS" ! flags = c_int() ! self.__com_GetImplTypeFlags(index, byref(flags)) ! return flags.value def GetIDsOfNames(self, *names): --- 261,269 ---- return names[:cnames.value] ! ## def GetRefTypeOfImplType(self, index): ! ## "Get the reftype of an implemented type" ! ## def GetImplTypeFlags(self, index): ! ## "Get IMPLTYPEFLAGS" def GetIDsOfNames(self, *names): *************** *** 307,365 **** ## STDMETHOD(HRESULT, 'Invoke', [PVOID, MEMBERID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), ! def GetDocumentation(self, memid): ! "Return documentation for a type" ! name = BSTR() ! docstring = BSTR() ! helpcontext = DWORD() ! helpfile = BSTR() ! self.__com_GetDocumentation(memid, byref(name), byref(docstring), ! byref(helpcontext), byref(helpfile)) ! return name.value, docstring.value, helpcontext.value, helpfile.value ! ! def GetDllEntry(self, memid, invkind): ! "Return the dll name, function name, and ordinal for a function and invkind." ! dllname = BSTR() ! name = BSTR() ! ordinal = c_ushort() ! self.__com_GetDllEntry(memid, invkind, byref(dllname), byref(name), byref(ordinal)) ! return dllname.value, name.value, ordinal.value ! def GetRefTypeInfo(self, href): ! "Get type info for reftype" ! ti = POINTER(ITypeInfo)() ! self.__com_GetRefTypeInfo(href, byref(ti)) ! return ti def AddressOfMember(self, memid, invkind): "Get the address of a function in a dll" p = c_void_p() self.__com_AddressOfMember(memid, invkind, byref(p)) return p.value ## STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), ! def GetMops(self, index): ! "Get marshalling opcodes (whatever that is...)" ! mops = BSTR() ! self.__com_GetMops(index, byref(mops)) ! return mops.value ! def GetContainingTypeLib(self): ! "Return index into and the containing type lib itself" ! index = c_uint() ! tlib = POINTER(ITypeLib)() ! self.__com_GetContainingTypeLib(byref(tlib), byref(index)) ! return index.value, tlib ! def ReleaseTypeAttr(self, pta): ! self.__com_ReleaseTypeAttr(pta) ! def ReleaseFuncDesc(self, pfd): ! self.__com_ReleaseFuncDesc(pfd) ! def ReleaseVarDesc(self, pvd): ! self.__com_ReleaseVarDesc(pvd) ################ --- 275,309 ---- + # not yet wrapped ## STDMETHOD(HRESULT, 'Invoke', [PVOID, MEMBERID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), ! ## def GetDllEntry(self, memid, invkind): ! ## "Return the dll name, function name, and ordinal for a function and invkind." ! ## def GetRefTypeInfo(self, href): ! ## "Get type info for reftype" def AddressOfMember(self, memid, invkind): "Get the address of a function in a dll" + raise "Check Me" p = c_void_p() self.__com_AddressOfMember(memid, invkind, byref(p)) + # XXX Would the default impl return the value of p? return p.value + # not yet wrapped ## STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), ! ## def GetMops(self, index): ! ## "Get marshalling opcodes (whatever that is...)" ! ## def GetContainingTypeLib(self): ! ## "Return index into and the containing type lib itself" ! ## def ReleaseTypeAttr(self, pta): ! ## def ReleaseFuncDesc(self, pfd): ! ## def ReleaseVarDesc(self, pvd): ################ *************** *** 523,561 **** ITypeLib._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 4455 ! STDMETHOD(UINT, 'GetTypeInfoCount', []), ! STDMETHOD(HRESULT, 'GetTypeInfo', [UINT, POINTER(POINTER(ITypeInfo))]), ! STDMETHOD(HRESULT, 'GetTypeInfoType', [UINT, POINTER(TYPEKIND)]), ! STDMETHOD(HRESULT, 'GetTypeInfoOfGuid', [POINTER(GUID), POINTER(POINTER(ITypeInfo))]), ! STDMETHOD(HRESULT, 'GetLibAttr', [POINTER(POINTER(TLIBATTR))]), ! STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), ! STDMETHOD(HRESULT, 'GetDocumentation', [INT, POINTER(BSTR), POINTER(BSTR), POINTER(DWORD), POINTER(BSTR)]), ! STDMETHOD(HRESULT, 'IsName', [LPOLESTR, DWORD, POINTER(BOOL)]), STDMETHOD(HRESULT, 'FindName', [LPOLESTR, DWORD, POINTER(POINTER(ITypeInfo)), POINTER(MEMBERID), POINTER(USHORT)]), ! STDMETHOD(None, 'ReleaseTLibAttr', [POINTER(TLIBATTR)]), ] ITypeInfo._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 3230 ! STDMETHOD(HRESULT, 'GetTypeAttr', [POINTER(POINTER(TYPEATTR))]), ! STDMETHOD(HRESULT, 'GetTypeComp', [POINTER(POINTER(ITypeComp))]), ! STDMETHOD(HRESULT, 'GetFuncDesc', [UINT, POINTER(POINTER(FUNCDESC))]), ! STDMETHOD(HRESULT, 'GetVarDesc', [UINT, POINTER(POINTER(VARDESC))]), STDMETHOD(HRESULT, 'GetNames', [MEMBERID, POINTER(BSTR), UINT, POINTER(UINT)]), ! STDMETHOD(HRESULT, 'GetRefTypeOfImplType', [UINT, POINTER(HREFTYPE)]), ! STDMETHOD(HRESULT, 'GetImplTypeFlags', [UINT, POINTER(INT)]), ## STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(LPOLESTR), UINT, POINTER(MEMBERID)]), # this one changed, to accept c_wchar_p array STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(c_wchar_p), UINT, POINTER(MEMBERID)]), STDMETHOD(HRESULT, 'Invoke', [PVOID, MEMBERID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), ! STDMETHOD(HRESULT, 'GetDocumentation', [MEMBERID, POINTER(BSTR), POINTER(BSTR), POINTER(DWORD), POINTER(BSTR)]), ! STDMETHOD(HRESULT, 'GetDllEntry', [MEMBERID, INVOKEKIND, POINTER(BSTR), POINTER(BSTR), POINTER(WORD)]), ! STDMETHOD(HRESULT, 'GetRefTypeInfo', [HREFTYPE, POINTER(POINTER(ITypeInfo))]), STDMETHOD(HRESULT, 'AddressOfMember', [MEMBERID, INVOKEKIND, POINTER(PVOID)]), STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), ! STDMETHOD(HRESULT, 'GetMops', [MEMBERID, POINTER(BSTR)]), ! STDMETHOD(HRESULT, 'GetContainingTypeLib', [POINTER(POINTER(ITypeLib)), POINTER(UINT)]), ! STDMETHOD(None, 'ReleaseTypeAttr', [POINTER(TYPEATTR)]), ! STDMETHOD(None, 'ReleaseFuncDesc', [POINTER(FUNCDESC)]), ! STDMETHOD(None, 'ReleaseVarDesc', [POINTER(VARDESC)]), ] --- 467,559 ---- ITypeLib._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 4455 ! COMMETHOD([], UINT, 'GetTypeInfoCount'), ! COMMETHOD([], HRESULT, 'GetTypeInfo', ! (['in'], UINT, 'index'), ! (['out'], POINTER(POINTER(ITypeInfo)))), ! COMMETHOD([], HRESULT, 'GetTypeInfoOfType', ! (['in'], UINT, 'index'), ! (['out'], POINTER(TYPEKIND))), ! COMMETHOD([], HRESULT, 'GetTypeInfoOfGuid', ! (['in'], POINTER(GUID)), ! (['out'], POINTER(POINTER(ITypeInfo)))), ! COMMETHOD([], HRESULT, 'GetLibAttr', ! (['out'], POINTER(POINTER(TLIBATTR)))), ! COMMETHOD([], HRESULT, 'GetTypeComp', ! (['out'], POINTER(POINTER(ITypeComp)))), ! COMMETHOD([], HRESULT, 'GetDocumentation', ! (['in'], INT, 'index'), ! (['out'], POINTER(BSTR)), ! (['out'], POINTER(BSTR)), ! (['out'], POINTER(DWORD)), ! (['out'], POINTER(BSTR))), ! COMMETHOD([], HRESULT, 'IsName', ! # Strange. Marking this [in, out], and calling it with a string yields ! # TypeError: one character unicode string expected. ! # Marking it [in] accepts the string.?! ! # ! # Both are wrong, because IsName changes the case of the name ! # if it is found - so we must pass a mutable buffer. ! (['in', 'out'], LPOLESTR, 'name'), ! ## (['in'], LPOLESTR, 'name'), ! (['in', 'optional'], DWORD, 'lHashVal', 0), ! (['out'], POINTER(BOOL))), STDMETHOD(HRESULT, 'FindName', [LPOLESTR, DWORD, POINTER(POINTER(ITypeInfo)), POINTER(MEMBERID), POINTER(USHORT)]), ! COMMETHOD([], HRESULT, 'ReleaseTLibAttr', ! (['in'], POINTER(TLIBATTR))) ] ITypeInfo._methods_ = [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 3230 ! COMMETHOD([], HRESULT, 'GetTypeAttr', ! (['out'], POINTER(POINTER(TYPEATTR)), 'ppTypeAttr')), ! COMMETHOD([], HRESULT, 'GetTypeComp', ! (['out'], POINTER(POINTER(ITypeComp)))), ! COMMETHOD([], HRESULT, 'GetFuncDesc', ! (['in'], UINT, 'index'), ! (['out'], POINTER(POINTER(FUNCDESC)))), ! COMMETHOD([], HRESULT, 'GetVarDesc', ! (['in'], UINT, 'index'), ! (['out'], POINTER(POINTER(VARDESC)))), STDMETHOD(HRESULT, 'GetNames', [MEMBERID, POINTER(BSTR), UINT, POINTER(UINT)]), ! COMMETHOD([], HRESULT, 'GetRefTypeOfImplType', ! (['in'], UINT, 'index'), ! (['out'], POINTER(HREFTYPE))), ! COMMETHOD([], HRESULT, 'GetImplTypeFlags', ! (['in'], UINT, 'index'), ! (['out'], POINTER(INT))), ## STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(LPOLESTR), UINT, POINTER(MEMBERID)]), # this one changed, to accept c_wchar_p array STDMETHOD(HRESULT, 'GetIDsOfNames', [POINTER(c_wchar_p), UINT, POINTER(MEMBERID)]), STDMETHOD(HRESULT, 'Invoke', [PVOID, MEMBERID, WORD, POINTER(DISPPARAMS), POINTER(VARIANT), POINTER(EXCEPINFO), POINTER(UINT)]), ! ! COMMETHOD([], HRESULT, 'GetDocumentation', ! (['in'], MEMBERID, 'memid'), ! (['out'], POINTER(BSTR), 'pBstrName'), ! (['out'], POINTER(BSTR), 'pBstrDocString'), ! (['out'], POINTER(DWORD), 'pdwHelpContext'), ! (['out'], POINTER(BSTR), 'pBstrHelpFile')), ! COMMETHOD([], HRESULT, 'GetDllEntry', ! (['in'], MEMBERID, 'index'), ! (['in'], INVOKEKIND, 'invkind'), ! (['out'], POINTER(BSTR), 'pBstrDllName'), ! (['out'], POINTER(BSTR), 'pBstrName'), ! (['out'], POINTER(WORD), 'pwOrdinal')), ! COMMETHOD([], HRESULT, 'GetRefTypeInfo', ! (['in'], HREFTYPE, 'hRefType'), ! (['out'], POINTER(POINTER(ITypeInfo)))), STDMETHOD(HRESULT, 'AddressOfMember', [MEMBERID, INVOKEKIND, POINTER(PVOID)]), STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), ! COMMETHOD([], HRESULT, 'GetMops', ! (['in'], MEMBERID, 'memid'), ! (['out'], POINTER(BSTR))), ! COMMETHOD([], HRESULT, 'GetContainingTypeLib', ! (['out'], POINTER(POINTER(ITypeLib))), ! (['out'], POINTER(UINT))), ! COMMETHOD([], None, 'ReleaseTypeAttr', ! (['in'], POINTER(TYPEATTR))), ! COMMETHOD([], None, 'ReleaseFuncDesc', ! (['in'], POINTER(FUNCDESC))), ! COMMETHOD([], None, 'ReleaseVarDesc', ! (['in'], POINTER(VARDESC))), ] |
From: Thomas H. <th...@us...> - 2005-06-08 10:01:51
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17419 Modified Files: Tag: branch_1_0 tlbparser.py Log Message: Generate external symbols. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -C2 -d -r1.4.2.2 -r1.4.2.3 *** tlbparser.py 3 Jun 2005 09:51:18 -0000 1.4.2.2 --- tlbparser.py 8 Jun 2005 10:01:41 -0000 1.4.2.3 *************** *** 122,126 **** enum_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) enum = typedesc.Enumeration(enum_name, 32, 32) ! self.items[enum_name] = enum for i in range(ta.cVars): --- 122,126 ---- enum_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1) enum = typedesc.Enumeration(enum_name, 32, 32) ! self._register(enum_name, enum) for i in range(ta.cVars): *************** *** 142,146 **** bases=[], size=ta.cbSizeInstance*8) ! self.items[struct_name] = struct for i in range(ta.cVars): --- 142,146 ---- bases=[], size=ta.cbSizeInstance*8) ! self._register(struct_name, struct) for i in range(ta.cVars): *************** *** 179,184 **** func.doc = func_doc.encode("mbcs") func.dllname = dllname ! self.items[func_name] = func ! for i in range(fd.cParams): argtype = self.make_type(fd.lprgelemdescParam[i].tdesc, tinfo) --- 179,183 ---- func.doc = func_doc.encode("mbcs") func.dllname = dllname ! self._register(func_name, func) for i in range(fd.cParams): argtype = self.make_type(fd.lprgelemdescParam[i].tdesc, tinfo) *************** *** 193,197 **** var_value = vd._.lpvarValue[0].value v = typedesc.Variable(name, typ, repr(var_value)) ! self.items[name] = v if var_doc is not None: v.doc = var_doc --- 192,196 ---- var_value = vd._.lpvarValue[0].value v = typedesc.Variable(name, typ, repr(var_value)) ! self._register(name, v) if var_doc is not None: v.doc = var_doc *************** *** 214,218 **** iid=str(ta.guid), idlflags=self.interface_type_flags(ta.wTypeFlags)) ! self.items[itf_name] = itf assert ta.cVars == 0, "vars on an Interface?" --- 213,217 ---- iid=str(ta.guid), idlflags=self.interface_type_flags(ta.wTypeFlags)) ! self._register(itf_name, itf) assert ta.cVars == 0, "vars on an Interface?" *************** *** 259,263 **** idlflags=self.interface_type_flags(ta.wTypeFlags)) itf.doc = str(doc) ! self.items[itf_name] = itf flags = ta.wTypeFlags & (typeinfo.TYPEFLAG_FDISPATCHABLE | typeinfo.TYPEFLAG_FDUAL) --- 258,262 ---- idlflags=self.interface_type_flags(ta.wTypeFlags)) itf.doc = str(doc) ! self._register(itf_name, itf) flags = ta.wTypeFlags & (typeinfo.TYPEFLAG_FDISPATCHABLE | typeinfo.TYPEFLAG_FDUAL) *************** *** 411,418 **** # version, control, hidden, and appobject coclass_name, doc = tinfo.GetDocumentation(-1)[0:2] coclass = typedesc.CoClass(coclass_name, str(ta.guid), self.coclass_type_flags(ta.wTypeFlags)) if doc is not None: coclass.doc = str(doc) ! self.items[coclass_name] = coclass for i in range(ta.cImplTypes): hr = tinfo.GetRefTypeOfImplType(i) --- 410,419 ---- # version, control, hidden, and appobject coclass_name, doc = tinfo.GetDocumentation(-1)[0:2] + ## print tinfo.GetContainingTypeLib()[0].GetLibAttr().guid, coclass_name coclass = typedesc.CoClass(coclass_name, str(ta.guid), self.coclass_type_flags(ta.wTypeFlags)) if doc is not None: coclass.doc = str(doc) ! self._register(coclass_name, coclass) ! for i in range(ta.cImplTypes): hr = tinfo.GetRefTypeOfImplType(i) *************** *** 428,432 **** typ = self.make_type(ta.tdescAlias, tinfo) alias = typedesc.Typedef(name, typ) ! self.items[name] = alias return alias --- 429,433 ---- typ = self.make_type(ta.tdescAlias, tinfo) alias = typedesc.Typedef(name, typ) ! self._register(name, alias) return alias *************** *** 440,444 **** bases=[], size=ta.cbSizeInstance*8) ! self.items[union_name] = union for i in range(ta.cVars): --- 441,445 ---- bases=[], size=ta.cbSizeInstance*8) ! self._register(union_name, union) for i in range(ta.cVars): *************** *** 457,468 **** ################################################################ def parse_typeinfo(self, tinfo): name = tinfo.GetDocumentation(-1)[0] try: ! return self.items[name] except KeyError: pass ta = tinfo.GetTypeAttr() tkind = ta.typekind if tkind == typeinfo.TKIND_ENUM: # 0 return self.ParseEnum(tinfo, ta) --- 458,491 ---- ################################################################ + def _register(self, name, value, tlib=None): + modname = self._typelib_module(tlib) + self.items["%s.%s" % (modname, name)] = value + + def _typelib_module(self, tlib=None): + if tlib is None: + tlib = self.tlib + la = tlib.GetLibAttr() + return "tlb_%s_%s_%s_%s" % \ + (str(la.guid)[1:-1].replace("-", "_"), + la.lcid, la.wMajorVerNum, la.wMinorVerNum) + def parse_typeinfo(self, tinfo): name = tinfo.GetDocumentation(-1)[0] + modname = self._typelib_module() try: ! return self.items["%s.%s" % (modname, name)] except KeyError: pass + + tlib = tinfo.GetContainingTypeLib()[0] + ## print "TLIB_%s.%s" % (str(tlib.GetLibAttr().guid)[1:-1].replace("-", "_"), name) + if tlib != self.tlib: + typ = typedesc.External(self._typelib_module(tlib), name, tlib.GetDocumentation(-1)[:2]) + self._register(name, typ, tlib) + return typ + ta = tinfo.GetTypeAttr() tkind = ta.typekind + if tkind == typeinfo.TKIND_ENUM: # 0 return self.ParseEnum(tinfo, ta) *************** *** 475,478 **** --- 498,503 ---- elif tkind == typeinfo.TKIND_DISPATCH: # 4 try: + # GetRefTypeOfImplType(-1) returns the custom portion + # of a dispinterface, if it is dual href = tinfo.GetRefTypeOfImplType(-1) except WindowsError: *************** *** 599,608 **** if __name__ == "__main__": ! if 1: main() else: ! from comtypes.typeinfo import LoadRegTypeLib from comtypes import GUID import sys - tlib = LoadRegTypeLib(GUID("{6BC096BB-0CE6-11D1-BAAE-00C04FC2E20D}"), 1, 0) test(tlib, sys.stdout) --- 624,645 ---- if __name__ == "__main__": ! if 0: main() else: ! from comtypes.typeinfo import LoadRegTypeLib, LoadTypeLibEx from comtypes import GUID + ## tlib = LoadTypeLibEx(r"c:\tss5\include\fpanel.tlb") + ## tlib = LoadRegTypeLib(GUID("{6BC096BB-0CE6-11D1-BAAE-00C04FC2E20D}"), 1, 0) + + # stdole32 + ## tlib = LoadRegTypeLib(GUID("{00020430-0000-0000-C000-000000000046}"), 1, 0) + # from comtypes.typeinfo import QueryPathOfRegTypeLib + # print QueryPathOfRegTypeLib(GUID("{00020430-0000-0000-C000-000000000046}"), 1, 0) + ## import sys + ## sys.exit() + ## return + tlib = LoadTypeLibEx(r"c:\progra~1\micros~3\Office\MSWORD8.OLB") + ## tlib = LoadTypeLibEx(r"mshtml.tlb") + import sys test(tlib, sys.stdout) |
From: Thomas H. <th...@us...> - 2005-06-08 09:59:57
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16305 Modified Files: Tag: branch_1_0 typedesc.py Log Message: Generate external symbols. Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/typedesc.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** typedesc.py 2 Jun 2005 12:15:28 -0000 1.1.2.1 --- typedesc.py 8 Jun 2005 09:59:11 -0000 1.1.2.2 *************** *** 3,6 **** --- 3,12 ---- from ctypes.wrap.typedesc import * + class External(object): + def __init__(self, module, name, docs=None): + self.module = module + self.name = "%s.%s" % (module, name) + self.docs = docs + class SAFEARRAYType(object): def __init__(self, typ): *************** *** 99,100 **** --- 105,109 ---- self.interfaces.append((itf, idlflags)) + if __name__ == "__main__": + import tlbparser + tlbparser.test() |
From: Thomas H. <th...@us...> - 2005-06-08 09:58:46
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15895 Modified Files: Tag: branch_1_0 codegenerator.py Log Message: Fixes for coclass code generation. Generate external symbols. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.2 retrieving revision 1.6.2.3 diff -C2 -d -r1.6.2.2 -r1.6.2.3 *** codegenerator.py 3 Jun 2005 09:49:30 -0000 1.6.2.2 --- codegenerator.py 8 Jun 2005 09:58:37 -0000 1.6.2.3 *************** *** 14,17 **** --- 14,21 ---- class Generator(ctypes.wrap.codegenerator.Generator): + def __init__(self, *args, **kw): + self._externals = {} + super(Generator, self).__init__(*args, **kw) + def type_name(self, t, generate=True): # Return a string, containing an expression which can be used to *************** *** 19,22 **** --- 23,28 ---- if isinstance(t, typedesc.SAFEARRAYType): return "_midlSAFEARRAY(%s)" % self.type_name(t.typ) + ## if isinstance(t, typedesc.CoClass): + ## return "%s._com_interfaces_[0]" % t.name return super(Generator, self).type_name(t, generate) *************** *** 52,55 **** --- 58,68 ---- # top-level typedesc generators # + def External(self, ext): + if ext.module in self._externals: + return + print >> self.imports, "# '%s' typelib (%s)" % ext.docs + print >> self.imports, "import %s" % ext.module + self._externals[ext.module] = None + def SAFEARRAYType(self, sa): self.generate(sa.typ) *************** *** 75,79 **** print >> self.stream, " _idlflags_ = %s" % coclass.idlflags for itf, idlflags in coclass.interfaces: ! self.generate(itf) implemented = [i[0].name for i in coclass.interfaces if i[1] & 2 == 0] --- 88,97 ---- print >> self.stream, " _idlflags_ = %s" % coclass.idlflags for itf, idlflags in coclass.interfaces: ! self.generate(itf.get_head()) ! if coclass.interfaces: ! # Hm. ! print >> self.stream, "from ctypes import _pointer_type_cache" ! print >> self.stream, "_pointer_type_cache[%s] = POINTER(%s)" % \ ! (coclass.name, coclass.interfaces[0][0].name) implemented = [i[0].name for i in coclass.interfaces if i[1] & 2 == 0] |
From: Thomas H. <th...@us...> - 2005-06-08 09:40:38
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7513 Modified Files: Tag: branch_1_0 __init__.py Log Message: Fix comparing COM pointers: if __eq__ is implemented, other rich comparison methods should also. So, __cmp__ is much simpler. VARIANT is set from outside (hack). Handle optional parameters correctly by providing a default value. Some comments about coclass. Implement sequence methods in IUnknown, they forward to _NewEnum, Count, and Item. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.4 retrieving revision 1.25.2.5 diff -C2 -d -r1.25.2.4 -r1.25.2.5 *** __init__.py 3 Jun 2005 09:44:44 -0000 1.25.2.4 --- __init__.py 8 Jun 2005 09:40:29 -0000 1.25.2.5 *************** *** 250,254 **** ## return bool(c_void_p.value.__get__(self)) ! def __eq__(self, other): # COM identity rule # --- 250,254 ---- ## return bool(c_void_p.value.__get__(self)) ! def __cmp__(self, other): # COM identity rule # *************** *** 257,263 **** # compare the pointer values? if not isinstance(other, _compointer_base): ! return False # get the value property of the c_void_p baseclass, this is the pointer value ! return super(_compointer_base, self).value == super(_compointer_base, other).value # override the .value property of c_void_p --- 257,263 ---- # compare the pointer values? if not isinstance(other, _compointer_base): ! return 1 # get the value property of the c_void_p baseclass, this is the pointer value ! return cmp(super(_compointer_base, self).value, super(_compointer_base, other).value) # override the .value property of c_void_p *************** *** 321,324 **** --- 321,326 ---- return idl, typ, name, defval + # will be overwritten when comtypes.automation is imported. + _VARIANT_type_hack = None def COMMETHOD(idlflags, restype, methodname, *argspec): *************** *** 387,390 **** --- 389,402 ---- # Something like _from_outarg_. # + + # Another use case for this is a coclass* in the parameter list. + # According to MSDN, this means the same as IUnknown*. + # So, we could make IUnknown a base class of CoClass so that + # it is a ctypes type at least. Or should some metaclass magic + # make a CoClass a subclass of the coclass's default com interface? + # + # But, this doesn't seem to be compatible with the role that the + # CoClass would play with COM server stuff. + for item in argspec: idl, typ, argname, defval = _unpack_argspec(*item) *************** *** 399,406 **** # XXX Should probably use a different name, so that it # can't be imported from this module by accident. ! if typ is VARIANT: ! defval = VARIANT() ! elif typ is POINTER(VARIANT): ! defval = pointer(VARIANT()) else: msg = "'optional' only allowed for VARIANT and VARIANT*, not for %s" \ --- 411,434 ---- # XXX Should probably use a different name, so that it # can't be imported from this module by accident. ! if _VARIANT_type_hack and typ is _VARIANT_type_hack: ! # XXX make this a classmethod of VARIANT! ! # VARIANT.missing or so... ! v = _VARIANT_type_hack() ! VT_ERROR = 10 ! VT_EMPTY = 0 ! v.vt = VT_EMPTY ! ## v.vt = VT_ERROR ! ## v._.VT_I4 = 0x80020004L ! defval = v ! ## defval = _VARIANT_type_hack() ! elif _VARIANT_type_hack and typ is POINTER(_VARIANT_type_hack): ! v = _VARIANT_type_hack() ! VT_ERROR = 10 ! ## VT_EMPTY = 0 ! ## v.vt = VT_EMPTY ! v.vt = VT_ERROR ! v._.VT_I4 = 0x80020004L ! ! defval = pointer(v) else: msg = "'optional' only allowed for VARIANT and VARIANT*, not for %s" \ *************** *** 454,457 **** --- 482,509 ---- return self.__com_Release() + # should these methods be in a mixin class, which the metaclass + # adds when it detects the Count, Item, and _NewEnum methods? + def __len__(self): + try: + length = self.Count + except AttributeError: + raise TypeError, "len() of unsized object" + else: + return length + + ## def __iter__(self): + ## print "__iter__", self._NewEnum + + def __getitem__(self, index): + try: + mth = self.Item + except AttributeError: + raise TypeError, "unsubscriptable object" + else: + try: + return mth(index + 1) + except WindowsError, detail: + raise IndexError, detail + ################################################################ *************** *** 469,472 **** --- 521,527 ---- ################################################################ + # What's a coclass? + # a POINTER to a coclass is allowed as parameter in a function declaration: + # http://msdn.microsoft.com/library/en-us/midl/midl/oleautomation.asp ################ |
From: Thomas H. <th...@us...> - 2005-06-03 19:07:39
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15980 Modified Files: Tag: branch_1_0 w32_user.py sum_user.py sum_gen.py sum.tlb sum.py sum.idl Added Files: Tag: branch_1_0 w32_ct.py Log Message: sum object supporting events. Index: sum.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/sum.py,v retrieving revision 1.8 retrieving revision 1.8.8.1 diff -C2 -d -r1.8 -r1.8.8.1 *** sum.py 9 Jul 2003 19:08:19 -0000 1.8 --- sum.py 3 Jun 2005 19:07:26 -0000 1.8.8.1 *************** *** 12,16 **** # interface, coclass, typelib ! from sum_gen import IDualSum, CSum, SumLib # special code for this sample, to make sure sum_gen contains --- 12,16 ---- # interface, coclass, typelib ! from sum_gen import IDualSum, CSum, SumLib, DSumEvents # special code for this sample, to make sure sum_gen contains *************** *** 25,34 **** # This object implements a dual interface described in a type library, # and ctypes.com provides a handy bas class we can use: ! from ctypes.com.automation import DualObjImpl from ctypes.com.server import CLSCTX_LOCAL_SERVER, CLSCTX_INPROC_SERVER ! class SumObject(DualObjImpl): # A sequence of COM interfaces this object implements ! _com_interfaces_ = [IDualSum] # The type library we need, SumLib has the correct attributes _typelib_ = SumLib --- 25,40 ---- # This object implements a dual interface described in a type library, # and ctypes.com provides a handy bas class we can use: ! from ctypes.com.automation import DualObjImpl, COMObject, DualObjWithEventsImpl from ctypes.com.server import CLSCTX_LOCAL_SERVER, CLSCTX_INPROC_SERVER + from ctypes.com.connectionpoints import IConnectionPointContainer, IConnectionPoint + from ctypes.com.hresult import * ! class SumObject(DualObjWithEventsImpl): # A sequence of COM interfaces this object implements ! # It makes also sense to implement IProvideClassInfo2 ! # on an object having events. ! _com_interfaces_ = [IDualSum, IConnectionPointContainer] ! _outgoing_interface_ = DSumEvents ! # The type library we need, SumLib has the correct attributes _typelib_ = SumLib *************** *** 42,46 **** _reg_clsid_ = CSum._reg_clsid_ ! _reg_clsctx_ = CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_SERVER # It is absolutely essential that you call the base class __init__ --- 48,53 ---- _reg_clsid_ = CSum._reg_clsid_ ! ## _reg_clsctx_ = CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_SERVER ! _reg_clsctx_ = CLSCTX_LOCAL_SERVER # It is absolutely essential that you call the base class __init__ *************** *** 62,67 **** # floats, and presult is the result pointer which also points # to a c_double. ! presult[0] = a + b # The method must return a HRESULT, 0 is the same as S_OK return 0 --- 69,76 ---- # floats, and presult is the result pointer which also points # to a c_double. ! result = a + b # The method must return a HRESULT, 0 is the same as S_OK + self._connectionpoint.Fire_Event("Added", a, b, result) + presult[0] = result return 0 Index: sum_user.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/sum_user.py,v retrieving revision 1.3 retrieving revision 1.3.10.1 diff -C2 -d -r1.3 -r1.3.10.1 *** sum_user.py 28 May 2003 19:53:43 -0000 1.3 --- sum_user.py 3 Jun 2005 19:07:26 -0000 1.3.10.1 *************** *** 1,9 **** # ctypes client code, using the CSum COM object - ##import pywintypes from ctypes import * from ctypes.com import CreateInstance from ctypes.com.automation import IDispatch ! from sum_gen import CSum CLSCTX_INPROC_SERVER = 0x1 --- 1,9 ---- # ctypes client code, using the CSum COM object from ctypes import * from ctypes.com import CreateInstance from ctypes.com.automation import IDispatch ! from ctypes.com.connectionpoints import dispinterface_EventReceiver ! from sum_gen import CSum, DSumEvents CLSCTX_INPROC_SERVER = 0x1 *************** *** 18,21 **** --- 18,27 ---- clsctx = CLSCTX_LOCAL_SERVER + class SumEvents(dispinterface_EventReceiver): + _com_interfaces_ = [DSumEvents] + + def Added(self, this, a, b, result): + print "*** Added Event", a, b, result + sum = CreateInstance(CSum, clsctx=clsctx) result = c_double() *************** *** 23,26 **** --- 29,38 ---- print "Added 3.14 and 3.14, result", result.value + events = SumEvents() + cookie = events.connect(sum) + sum.Add(2.718, 2.718, byref(result)) + print "Added 2.718 and 2.718, result", result.value + events.disconnect(cookie) + idisp = pointer(IDispatch()) --- NEW FILE: w32_ct.py --- # ctypes client code, using the CSum COM object from ctypes.com.client import Dispatch, DispatchWithEvents class events: def Added(self, *args): print "Added", args def test(): s = DispatchWithEvents("ctypes.SumObject", events) print "Adding" print s.Add(3.14, 2.78) ## pythoncom.CoUninitialize() del s if __name__ == "__main__": test() Index: w32_user.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/w32_user.py,v retrieving revision 1.1 retrieving revision 1.1.10.1 diff -C2 -d -r1.1 -r1.1.10.1 *** w32_user.py 28 May 2003 19:54:59 -0000 1.1 --- w32_user.py 3 Jun 2005 19:07:25 -0000 1.1.10.1 *************** *** 1,28 **** # ctypes client code, using the CSum COM object ! from ctypes import * ! from ctypes.com import IUnknown, ole32, GUID ! CLSCTX_INPROC_SERVER = 0x1 ! CLSCTX_LOCAL_SERVER = 0x4 ! clsid = GUID('{d0329e37-14c1-4d71-a4d8-df9534c7ebdf}') ! p = pointer(IUnknown()) ! import sys ! if "inproc_server" in sys.argv: ! print "Using CLSCTX_INPROC_SERVER" ! clsctx = CLSCTX_INPROC_SERVER ! # XXX to avoid a crash in pywintypes, we have to import pywintypes ! # before using a win32com implemented inproc server. ! import pywintypes ! else: ! print "Using CLSCTX_LOCAL_SERVER" ! clsctx = CLSCTX_LOCAL_SERVER ! ole32.CoCreateInstance(byref(clsid), ! 0, ! clsctx, ! byref(IUnknown._iid_), ! byref(p)) ! assert((2, 1) == (p.AddRef(), p.Release())) --- 1,27 ---- # ctypes client code, using the CSum COM object ! from win32com.client import Dispatch, DispatchWithEvents ! import pythoncom ! class events: ! def OnAdded(self, *args): ! print "OnAdded", args ! def test(): ! s = DispatchWithEvents("ctypes.SumObject", events) ! ## s = Dispatch("ctypes.SumObject") ! print "Adding" ! print s.Add(3.14, 2.78) ! del s ! print "pythoncom._GetInterfaceCount():", pythoncom._GetInterfaceCount() ! print "pythoncom._GetGatewayCount():", pythoncom._GetGatewayCount() ! print "pythoncom.CoUninitialize()" ! pythoncom.CoUninitialize() ! print "pythoncom._GetInterfaceCount():", pythoncom._GetInterfaceCount() ! print "pythoncom._GetGatewayCount():", pythoncom._GetGatewayCount() ! ! ! if __name__ == "__main__": ! test() Index: sum.idl =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/sum.idl,v retrieving revision 1.3 retrieving revision 1.3.8.1 diff -C2 -d -r1.3 -r1.3.8.1 *** sum.idl 15 Jan 2004 18:49:32 -0000 1.3 --- sum.idl 3 Jun 2005 19:07:26 -0000 1.3.8.1 *************** *** 23,26 **** --- 23,36 ---- [ + uuid(892f2813-62d7-4967-a0bd-c6e58559db5a), + helpstring("DSumEvents Interface"), + ] + dispinterface DSumEvents { + properties: + methods: + [id(1000)] double Added(double a, double b); + }; + + [ uuid(2e0504a1-1a23-443f-939d-869a6c731521), helpstring("CSum Class") *************** *** 30,33 **** --- 40,44 ---- { [default] interface IDualSum; + [source] interface DSumEvents; } }; Index: sum_gen.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/sum_gen.py,v retrieving revision 1.4 retrieving revision 1.4.10.1 diff -C2 -d -r1.4 -r1.4.10.1 *** sum_gen.py 3 Jul 2003 20:06:37 -0000 1.4 --- sum_gen.py 3 Jun 2005 19:07:26 -0000 1.4.10.1 *************** *** 1,4 **** # -*- python -*- ! # Generated from C:\sf\ctypes_head\win32\com\samples\server\sum.tlb ############################################################### --- 1,4 ---- # -*- python -*- ! # Generated from C:\sf\ctypes_dist_X\win32\com\samples\server\sum.tlb ############################################################### *************** *** 21,25 **** version = (1, 0) flags = 0x8 ! path = 'C:\\sf\\ctypes_head\\win32\\com\\samples\\server\\sum.tlb' ############################################################################## --- 21,25 ---- version = (1, 0) flags = 0x8 ! path = 'C:\\sf\\ctypes_dist_X\\win32\\com\\samples\\server\\sum.tlb' ############################################################################## *************** *** 30,37 **** --- 30,46 ---- + class DSumEvents(dispinterface): + """DSumEvents Interface""" + _iid_ = GUID('{892F2813-62D7-4967-A0BD-C6E58559DB5A}') + + IDualSum._methods_ = IDispatch._methods_ + [ STDMETHOD(HRESULT, "Add", c_double, c_double, POINTER(c_double)), ] + DSumEvents._dispmethods_ = [ + DISPMETHOD(0x3e8L, c_double, "Added", c_double, c_double), + ] + ############################################################################## *************** *** 40,42 **** --- 49,52 ---- _reg_clsid_ = '{2E0504A1-1A23-443F-939D-869A6C731521}' _com_interfaces_ = [IDualSum] + _outgoing_interfaces_ = [DSumEvents] Index: sum.tlb =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/samples/server/sum.tlb,v retrieving revision 1.3 retrieving revision 1.3.8.1 diff -C2 -d -r1.3 -r1.3.8.1 Binary files /tmp/cvsRxMy1C and /tmp/cvsKvTopR differ |
From: Thomas H. <th...@us...> - 2005-06-03 18:02:39
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15077 Modified Files: Tag: branch_1_0 client.py Log Message: Allow to access COM properties with parameters. The syntax is obj.prop["name"] and obj.prop["name"] = value Index: client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/client.py,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -C2 -d -r1.9 -r1.9.2.1 *** client.py 16 Feb 2005 16:39:04 -0000 1.9 --- client.py 3 Jun 2005 18:02:16 -0000 1.9.2.1 *************** *** 242,246 **** return None fd = bp.lpfuncdesc[0] - ## assert fd.funckind == FUNC_DISPATCH return _funcdesc(fd, ti) --- 242,245 ---- *************** *** 265,271 **** def __getattr__(self, name): ! fd = self._get_funcdesc(name, DISPATCH_METHOD + DISPATCH_PROPERTYGET) if fd is None: raise AttributeError, name if fd.invkind == DISPATCH_PROPERTYGET: if fd.cParams == 0: --- 264,280 ---- def __getattr__(self, name): ! try: ! fd = self._get_funcdesc(name, DISPATCH_METHOD | DISPATCH_PROPERTYGET) ! except WindowsError: ! try: ! fd = self._get_funcdesc(name, DISPATCH_PROPERTYPUT) ! except WindowsError: ! raise AttributeError, name if fd is None: raise AttributeError, name + + if fd.invkind == DISPATCH_METHOD: + return _DispMethod(name, self._comobj, fd) + if fd.invkind == DISPATCH_PROPERTYGET: if fd.cParams == 0: *************** *** 274,287 **** # Guesswork. InternetExplorer, and other typelibs, # have propget properties with cParams == 1, and cParamsOpt == 0. ! # The parameter type is VT_PTR | VT_..., and wPARAMFlags == PARAMFLAG_FOPT. ! # # And calling those without any parameter via Invoke works great... if fd.lprgelemdescParam[0].paramdesc.wPARAMFlags == 10: return self.__prop_get(fd.memid) ! return _DispMethod(name, self._comobj, fd) ! elif fd.invkind == DISPATCH_METHOD: ! return _DispMethod(name, self._comobj, fd) ! else: ! raise "What's this", fd.invkind def __call__(self): --- 283,294 ---- # Guesswork. InternetExplorer, and other typelibs, # have propget properties with cParams == 1, and cParamsOpt == 0. ! # The parameter type is VT_PTR | VT_..., and wPARAMFlags == P.._FOUT | P.._FRETVAL. # And calling those without any parameter via Invoke works great... if fd.lprgelemdescParam[0].paramdesc.wPARAMFlags == 10: return self.__prop_get(fd.memid) ! return _DispProperty(name, self._comobj, fd) ! ! if fd.invkind == DISPATCH_PROPERTYPUT: ! raise "What's this", (name, fd.invkind) def __call__(self): *************** *** 327,330 **** --- 334,371 ---- return _wrap(result) + class _DispProperty(_InvokeMixin): + def __init__(self, name, comobj, fd): + self.name = name + self._comobj = comobj + self.fd = fd + + def _build_parms(self, *args): + parms = DISPPARAMS() + parms.cArgs = len(args) + parms.cNamedArgs = 1 + parms.rgvarg = rgvarg = (VARIANT * parms.cArgs)() + + parms.rgdispidNamedArgs = rgdispids = (DISPID * 1)() + rgdispids[0] = DISPID_PROPERTYPUT + + arguments = [_unwrap(a) for a in args] + arguments.reverse() # that's the required ordering + for i, a in enumerate(arguments): + rgvarg[i].value = a + + return parms + + def __setitem__(self, index, value): + parms = self._build_parms(index, value) + self._do_invoke(self.fd.memid, DISPATCH_PROPERTYPUT, parms) + + def __getitem__(self, index): + parms = DISPPARAMS() + parms.cArgs = 1 + parms.cNamedArgs = 0 + parms.rgvarg = rgvarg = (VARIANT * parms.cArgs)() + rgvarg[0].value = index + return _wrap(self._do_invoke(self.fd.memid, DISPATCH_PROPERTYGET, parms)) + class _DispMethod(_InvokeMixin): def __init__(self, name, comobj, fd): |