[sorry for the late reply...] Suraj Barkale schrieb: > On 12/13/07, Thomas Heller <[EMAIL PROTECTED]> wrote: >> It would probably be a good idea to change the "magic" that comtypes >> currently implements into something that is more compatible with VB >> (or other scripting languages). >> However, I fear that changing this may break some existing programs. >> > It would be good to have same conventions as VB because most of the > examples on web use it and similar syntax means lesser brain power > required :) But ultimately, only you can decide whether its > appropriate to make the change.
I will do this change later (in 0.5, maybe), because I fear backwards compat problems. > Continuing with the 'Range' object, I ran into a problem that it is > not iterable; although it provides _NewEnum member. I don't know if it > is a problem specific to my installation of Office 2000. I tried > following on the shell: > >>>> from comtypes.client import CreateObject >>>> xl = CreateObject("Excel.Application") >>>> wb = xl.Workbooks.Add() >>>> rng = xl.Range['A1:C1'] >>>> rng.Value[()] = (10,"20",31.4) >>>> for c in rng: > print c.Value() > > Traceback (most recent call last): > File "<pyshell#10>", line 1, in <module> > for c in rng: > TypeError: 'POINTER(Range)' object is not iterable > > I think following test case would cover this scenario. My sincerest > apologies for not providing a proper patch but I don't have access to > svn now. Well, tests are sometimes even more valuable than code patches ;-). I have fixed the problem in SVN, and will release this as 0.4.2 shortly. In the meantime you could probably test the attached patch which fixes it. Thomas --- snip --- Modified: ctypes/trunk/comtypes/comtypes/__init__.py ============================================================================== --- ctypes/trunk/comtypes/comtypes/__init__.py (original) +++ ctypes/trunk/comtypes/comtypes/__init__.py Wed Dec 19 18:01:33 2007 @@ -1,6 +1,6 @@ import new, types, sys, os -__version__ = "0.4.1" +__version__ = "0.4.2" from ctypes import * from _ctypes import COMError @@ -232,9 +232,14 @@ def __setattr__(self, name, value): if name == "_methods_": + # XXX I'm no longer sure why the code generator generates + # "_methods_ = []" in the interface definition, and later + # overrides this by "Interface._methods_ = [...] +## assert self.__dict__.get("_methods_", None) is None self._make_methods(value) self._make_specials() elif name == "_disp_methods_": + assert self.__dict__.get("_disp_methods_", None) is None self._make_dispmethods(value) self._make_specials() type.__setattr__(self, name, value) @@ -328,6 +333,9 @@ for m in methods: what, name, idlflags, restype, argspec = m + # is it a property set or property get? + is_prop = False + # argspec is a sequence of tuples, each tuple is: # ([paramflags], type, name) try: @@ -337,6 +345,7 @@ if what == "DISPPROPERTY": # DISPPROPERTY assert not argspec # XXX does not yet work for properties with parameters accessor = self._disp_property(memid, idlflags) + is_prop = True setattr(self, name, accessor) elif what == "DISPMETHOD": # DISPMETHOD # argspec is a tuple of (idlflags, type, name[, @@ -346,14 +355,26 @@ if 'propget' in idlflags: nargs = len(argspec) properties.setdefault((name, nargs), [None, None, None])[0] = method + is_prop = True elif 'propput' in idlflags: nargs = len(argspec)-1 properties.setdefault((name, nargs), [None, None, None])[1] = method + is_prop = True elif 'propputref' in idlflags: nargs = len(argspec)-1 properties.setdefault((name, nargs), [None, None, None])[2] = method + is_prop = True else: setattr(self, name, method) + # COM is case insensitive. + # + # For a method, this is the real name. For a property, + # this is the name WITHOUT the _set_ or _get_ prefix. + if self._case_insensitive_: + self.__map_case__[name.lower()] = name + if is_prop: + self.__map_case__[name[5:].lower()] = name[5:] + for (name, nargs), methods in properties.items(): # methods contains [propget or None, propput or None, propputref or None] if methods[1] and methods[2]: @@ -383,6 +404,10 @@ assert len(methods) <= 2 setattr(self, name, property(*methods)) + # COM is case insensitive + if self._case_insensitive_: + self.__map_case__[name.lower()] = name + # Some ideas, (not only) related to disp_methods: # # Should the functions/methods we create have restype and/or --- snip --- ------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users