[ctypes-commit] ctypes/win32/com client.py,1.9,1.9.2.1
Brought to you by:
theller
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): |