From timr at probo.com Wed Feb 1 00:00:38 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 31 Jan 2006 15:00:38 -0800 Subject: [python-win32] Spawnv problem In-Reply-To: References: Message-ID: <43DFEC16.8050401@probo.com> On Tue, 31 Jan 2006 15:08:24 -0000,"Frank Peacock" wrote: >I cannot seem to spawn a subprocess. The subprocess does not seem to be run. > >Attached are my two files. There is a main.py file and a subprocess.py file. They simpy print their names. > >Can anyone suggest a reason? > Your code works properly for me, once I adjust the paths. You do have a backslash problem in there, in that your path to Python needs another backslash after the c:, but it will accidentally work because \p is not a recognized escape character. C:\tmp>type main.py # Main script import os print("main") os.spawnv(os.P_WAIT, 'c:\\apps\\python24\\python.exe',('python.exe','c:\\tmp\\subprocess.py')) print("exit") C:\tmp>type subprocess.py print("subprocess") C:\tmp>main.py main subprocess exit C:\tmp> There is a standard module called subprocess, but that shouldn't affect this. You're sure that your subprocess.py script lives in the root of your hard disk? You may not be aware that "print" is a statement, not a function. Those parentheses aren't really doing what you think they're doing. This does what you expect: print("main") because a single item in parentheses is taken to be the same as the item. But this: print("a","b") does something quite different. That creates a two-element tuple and prints that. C:\tmp>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print("a","b") ('a', 'b') >>> print "a","b" a b >>> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Wed Feb 1 03:22:57 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 31 Jan 2006 21:22:57 -0500 Subject: [python-win32] Re: Extracting share permissions References: <1138757301.43e00eb5b3fc0@wmtest.cc.vt.edu> Message-ID: ----- Original Message ----- From: "Brad Tilley" To: "Roger Upole" Cc: Sent: Tuesday, January 31, 2006 8:28 PM Subject: Re: [python-win32] Re: Extracting share permissions > Quoting Roger Upole : > >> [Sorry, somehow I massively screwed up the format the first time] >> >> There are a couple of different options for persisting a security >> descriptor. >> >> buffer(security_descriptor)[:] retrieves the raw bytes in binary form. >> This can be passed to pywintypes.SECURITY_DESCRIPTOR to recreate the >> PySECURITY_DESCRIPTOR. >> >> Also, you can use >> win32security.ConvertSecurityDescriptorToStringSecurityDescriptor >> to create a text representation and >> win32security.ConvertStringSecurityDescriptorToSecurityDescriptor >> to recreate the PySECURITY_DESCRIPTOR. >> >> That reminds me, there's a bug in the routine in win32net that parses >> info >> out of dictionaries. If you pass in None to indicate a NULL security >> descriptor, >> you get an access violation. I'll get a fix in for that soon. >> >> Roger > > Hey guys... thanks for all of the advice. I'm still trying to bang thru > this... > I've read msdn articles until I finally understand why Windows has so many > problems: it's too darn complex. Anyway, here's where I'm at. Just > experimenting. Please chip in and help me make sense of this: > > import win32net, win32security, pywintypes > > shares = win32net.NetShareEnum(None, 502) > for share in shares[0]: > try: > sd = share['security_descriptor'] > print sd.GetLength() > print sd.IsValid() > print type(sd) > text = > win32security.ConvertSecurityDescriptorToStringSecurityDescriptor(sd, > win32security.SDDL_REVISION_1, > win32security.OWNER_SECURITY_INFORMATION) You'll need to pass OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION| DACL_SECURITY_INFORMATION|SACL_SECURITY_INFORMATION to make sure you convert all the info in the security descriptor. Also, you probably ought to check if the returned security descriptor is None before trying to convert it, since shares can have a NULL security descriptor. > print text > bytes = buffer(sd) > print bytes, type(bytes), len(bytes) > except Exception, e: > print e > > Other than that, looks pretty good. Either of these approaches should give you something that can be stored to duplicate your current permissions. Roger From rtilley at vt.edu Wed Feb 1 02:28:21 2006 From: rtilley at vt.edu (Brad Tilley) Date: Tue, 31 Jan 2006 20:28:21 -0500 Subject: [python-win32] Extracting share permissions In-Reply-To: References: Message-ID: <1138757301.43e00eb5b3fc0@wmtest.cc.vt.edu> Quoting Roger Upole : > [Sorry, somehow I massively screwed up the format the first time] > > There are a couple of different options for persisting a security > descriptor. > > buffer(security_descriptor)[:] retrieves the raw bytes in binary form. > This can be passed to pywintypes.SECURITY_DESCRIPTOR to recreate the > PySECURITY_DESCRIPTOR. > > Also, you can use > win32security.ConvertSecurityDescriptorToStringSecurityDescriptor > to create a text representation and > win32security.ConvertStringSecurityDescriptorToSecurityDescriptor > to recreate the PySECURITY_DESCRIPTOR. > > That reminds me, there's a bug in the routine in win32net that parses info > out of dictionaries. If you pass in None to indicate a NULL security > descriptor, > you get an access violation. I'll get a fix in for that soon. > > Roger Hey guys... thanks for all of the advice. I'm still trying to bang thru this... I've read msdn articles until I finally understand why Windows has so many problems: it's too darn complex. Anyway, here's where I'm at. Just experimenting. Please chip in and help me make sense of this: import win32net, win32security, pywintypes shares = win32net.NetShareEnum(None, 502) for share in shares[0]: try: sd = share['security_descriptor'] print sd.GetLength() print sd.IsValid() print type(sd) text = win32security.ConvertSecurityDescriptorToStringSecurityDescriptor(sd, win32security.SDDL_REVISION_1, win32security.OWNER_SECURITY_INFORMATION) print text bytes = buffer(sd) print bytes, type(bytes), len(bytes) except Exception, e: print e From rtilley at vt.edu Wed Feb 1 16:11:06 2006 From: rtilley at vt.edu (Brad Tilley) Date: Wed, 1 Feb 2006 10:11:06 -0500 Subject: [python-win32] Extracting share permissions In-Reply-To: References: <1138757301.43e00eb5b3fc0@wmtest.cc.vt.edu> Message-ID: <1138806666.43e0cf8a02bcd@wmtest.cc.vt.edu> Quoting Roger Upole : > > ----- Original Message ----- > From: "Brad Tilley" > To: "Roger Upole" > Cc: > Sent: Tuesday, January 31, 2006 8:28 PM > Subject: Re: [python-win32] Re: Extracting share permissions > > > > Quoting Roger Upole : > > > >> [Sorry, somehow I massively screwed up the format the first time] > >> > >> There are a couple of different options for persisting a security > >> descriptor. > >> > >> buffer(security_descriptor)[:] retrieves the raw bytes in binary form. > >> This can be passed to pywintypes.SECURITY_DESCRIPTOR to recreate the > >> PySECURITY_DESCRIPTOR. > >> > >> Also, you can use > >> win32security.ConvertSecurityDescriptorToStringSecurityDescriptor > >> to create a text representation and > >> win32security.ConvertStringSecurityDescriptorToSecurityDescriptor > >> to recreate the PySECURITY_DESCRIPTOR. > >> > >> That reminds me, there's a bug in the routine in win32net that parses > >> info > >> out of dictionaries. If you pass in None to indicate a NULL security > >> descriptor, > >> you get an access violation. I'll get a fix in for that soon. > >> > >> Roger > > > > Hey guys... thanks for all of the advice. I'm still trying to bang thru > > this... > > I've read msdn articles until I finally understand why Windows has so many > > problems: it's too darn complex. Anyway, here's where I'm at. Just > > experimenting. Please chip in and help me make sense of this: > > > > import win32net, win32security, pywintypes > > > > shares = win32net.NetShareEnum(None, 502) > > for share in shares[0]: > > try: > > sd = share['security_descriptor'] > > print sd.GetLength() > > print sd.IsValid() > > print type(sd) > > text = > > win32security.ConvertSecurityDescriptorToStringSecurityDescriptor(sd, > > win32security.SDDL_REVISION_1, > > win32security.OWNER_SECURITY_INFORMATION) > > You'll need to pass OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION| > DACL_SECURITY_INFORMATION|SACL_SECURITY_INFORMATION > to make sure you convert all the info in the security descriptor. > Also, you probably ought to check if the returned security descriptor is > None before > trying to convert it, since shares can have a NULL security descriptor. > > > print text > > bytes = buffer(sd) > > print bytes, type(bytes), len(bytes) > > except Exception, e: > > print e > > > > > > Other than that, looks pretty good. Either of these approaches should give > you > something that can be stored to duplicate your current permissions. > > Roger OK, I think I've got it now... here is my logic... I'll post code later today... unless this is begining to get on people's nerves :) # To backup share info. 1. Get the share info with win32net.NetShareEnum(None, 502)... Thanks Mark! 2. Convert the PySECURITY_DESCRIPTOR object to text... Thanks Roger! 3. Then, pickle the share info. # To Recreate shares. 1. Unpickle the saved share info. 2. Convert the text representation of the security descriptor back to a PySECURITY_DESCRIPTOR object... buffer(sd_text) should do this, right? 3. Recreate the share with win32net.NetShareAdd() From wccppp at gmail.com Thu Feb 2 09:03:55 2006 From: wccppp at gmail.com (wccppp) Date: Wed, 1 Feb 2006 22:03:55 -1000 Subject: [python-win32] Autocad automation via COM: Passing coordinates as arguments (suggested fix within) In-Reply-To: <43D7D165.4050101@charter.net> References: <43D7D165.4050101@charter.net> Message-ID: <87bd46aa0602020003u65c55e36kcb0d97270334a951@mail.gmail.com> Dan, Thank you very much for taking time to examine the problem and offer a solution. Your approach seems a little daunting to me, since I'm fairly new to python. Also, as you mentioned, there are lots of AutoCAD methods that has point as argument. With new release coming out every year, ther might be new methods require point as argument too. I'll study your code when I have a little more free time. If it does fix my problem (after more testing), I would not mind using it. Now that I'm seeing more python codes, I'll have to force myself to write code with VBA, which I'm not proficient with anyway. Thanks again, - wcc On 1/25/06, Dan Glassman wrote: > > > From: wccppp > > Subject: [python-win32] question about COM again: variable type? > > > > [code] > > ms.AddPoint([0.0, 0.0, 0.0]) # this line gives the problem > > [/code] > > > > # Result is of type IAcadPoint > > def AddPoint(self, Point=defaultNamedNotOptArg): > > """Creates a Point object at a given location""" > > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, > > 1),),Point) > > if ret is not None: > > ret = Dispatch(ret, 'AddPoint', > > '{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0) > > return ret > > > Sorry for the long reply. > > The type library for AutoCad 2006 says that coordinates should be > passed as variants, so makepy's output is correct. But you can change > the makepy-generated file to process the argument as an array of doubles > instead of a variant and it will work. I'm not sure if that's because > the interface will also accept a 'raw' array, or if pythoncom is > magically wrapping the array in a variant. > > Taking from the AddPoint method of the IAcadModelSpace class that you've > included: > > [code] > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point) > [/code] > > The (12, 1) part describes the Point argument as an (Variant, Input), > roughly. This should be changed to (8197, 1), which is (Array of > Doubles, Input): > > [code] > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0),((8197,1),),Point) > [/code] > > Unfortunately, this happens all over the place -- not just the AddPoint > method. It would be very tedious to go through makepy's output and > make the >1500 changes. (12, 1) cannot be changed globally in there. It > also happens for more than just coordinate arguments; the Select methods > of SelectionSet objects have filters which are also arrays wrapped in a > variant. I haven't run across any others; the code below fixes > everything I've found. > > My solution was to change build.py (does some of makepy's work; located > in %pythoninstalldir%\lib\site-packages\win32com\client\) to apply this > Variant -> Array change for me when processing the type library. The > line numbers I reference are from pywin32 2.07; I tried to include > enough context to find the right parts of build.py in case yours is > different. > > My understanding of COM is not good, and these changes to build.py don't > seem suitably robust. It does a small check to see if it's processing > an Autocad library, but I suggest restoring build.py to its original > state after processing your Autocad type libraries. You'll lose these > fixes for dynamic dispatch in that case. > > I would be grateful if somebody could point out any red flags or suggest > a better approach. > > Near the top of build.py (~line 52): > > [code] > NoTranslateMap = {} > for v in NoTranslateTypes: > NoTranslateMap[v] = None > > #My addition starts here > AutocadTranslateMap = { > ('alignpoint','anglevertex','arccenter','arcpoint','axisdir', > 'axispoint','basepoint','boundry','center','centerpoint', > 'chordpoint','controlpoint','controlpoints','coordinates', > 'definitionpoint','dimlinelocation','direction', > 'directionvector','endpoint','endtangent','extline1point', > 'extline1startpoint','extline2endpoint','extline2point', > 'extline2startpoint','farchordpoint','firstendpoint','fitpoint', > 'fitpoints','frompoint','insertionpoint','inspoint','jogpoint', > 'knots','knotvalues','leader1point','leader2point', > 'leaderendpoint','limits','lowerleft','lowleft','majoraxis', > 'normal','origin','overridecenter','overridecenterpos', > 'plotorigin','point','point1','point2','point3','point4', > 'pointsarray','pointslist','pointsmatrix','porigin', > 'secondendpoint','secondpoint','snapbasepoint','startpoint', > 'starttangent','target','targetpoint','textalignmentpoint', > 'textpoint','textpos','textposition','topoint', > 'transformationmatrix','upperright','vertex','vertexlist', > 'vertices','verticeslist','weights','wpt','wpt1','wpt2', > 'xaxispoint','xline1point','xline2point','xvector', > 'yaxispoint','yvector'): 8197, > ('filtertype',): 8193, > ('filterdata',): 8204 > } > #My addition ends here > > class MapEntry: > "Simple holder for named attibutes - items in a map." > def __init__(self, desc_or_id, names=None, doc=None, > resultCLSID=pythoncom.IID_NULL, resultDoc = None, hidden=0): > [/code] > > Then, in the _AddFunc_ method of class DispatchItem (~line 175): > > Note that the code below has been stripped of its indentation to > hopefully make it more readable in email. Indentation within the posted > code is correct, but the entire code block needs to be indented to match > its context in build.py. > > [code] > fdesc.rettype = typerepr, flag, defval, resultCLSID > # Translate any Alias or Enums in argument list. > argList = [] > > #Changes begin here; > #for argDesc in fdesc.args: > for index, argDesc in enumerate(fdesc.args): > typerepr, flag, defval = argDesc > > #Catch only if reasonably sure this is Autocad > if self.python_name[:5] == 'IAcad': > #Catch (VT_VARIANT, FIN) and (VT_VARIANT, FIN|FOPT) > #Outputs seem to translate into tuples just fine already > if typerepr == 12 and (flag == 1 or flag == 17): > if len(fdesc.args) == len(names): #???Properties??? > replace = [key for key in AutocadTranslateMap.keys() \ > if names[index].lower() in key] > if replace: > typerepr = AutocadTranslateMap[replace[0]] > else: #names[0] is method name; names[1:] is arg names > replace = [key for key in AutocadTranslateMap.keys() \ > if names[index+1].lower() in key] > if replace: > typerepr = AutocadTranslateMap[replace[0]] > #Changes end here; > > arg_type, arg_clsid, arg_doc = _ResolveType(typerepr, typeinfo) > > argDesc = arg_type, flag, defval, arg_clsid > # sys.stderr.write("%s\n" % (argDesc[0],)) > argList.append(argDesc) > fdesc.args = tuple(argList) > [/code] > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Regards, - wcc -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060201/3113e9b3/attachment.htm From wccppp at gmail.com Thu Feb 2 09:23:26 2006 From: wccppp at gmail.com (wccppp) Date: Wed, 1 Feb 2006 22:23:26 -1000 Subject: [python-win32] Autocad automation via COM: Passing coordinates as arguments (suggested fix within) In-Reply-To: References: <43D7D165.4050101@charter.net> Message-ID: <87bd46aa0602020023v73e2c682v2e416fa82fe1667b@mail.gmail.com> Mark, Thank you for your suggestion. If I can do something like this: v = Variant(VT_DOUBLE, (1.0, 2.0, 3.0)) ms.AddPoint(v) That would be great! But I am not sure how to write the "Variant" class as you suggested. I bought your book "Python Programming on Win32" beause I wanted to automate windows applications, mostly AutoCAD, with python. Unfortunately the usage of InvokeTypes() was not covered in your book. Can you give a little more detailed guide on how to write this "Variant" class? Thank you. - wcc On 1/26/06, Mark Hammond wrote: > > Your changes look reasonable for the job they are designed to do, but > doesn't provide a general solution I can try to adopt (which is fine!). > Ultimately though, the question is "why does autocad's typelib not match > its > behaviour?". Can you find a reference to an autocad bug about this, or is > it worth contacting their support with a request for assistance? It may > turn out that both/either autocad or pywin32 are "correct", but incomplete > in some subtle way - eg, if autocad could explain why it is *not* a bug in > their typelib, it may help work out what bit of the puzzle is missing. > > Another alternative would be for pywin32 to grow a way to easily indicate > exact types to be passed in Variant calls. > > For example, your code could say something like: > > v = Variant(VT_DOUBLE, (1.0, 2.0, 3.0)) > ms.AddPoint(v) > > This needn't be that hard. The "Variant" object could be a class defined > in > a .py file. The IDispatch::Invoke method would grow support for detecting > this object and forming the correct Variant. The only query would be how > InvokeTypes should handle such an object - ignoring the explicitly passed > typeinfo seems wrong (but does seem practical!) > > I'd be happy to assist with this, but am unlikely to actually drive it > until > I personally need it. Sadly I don't think autocad will be used by me in > the > near future :) > > Mark > > > -----Original Message----- > > From: python-win32-bounces at python.org > > [mailto:python-win32-bounces at python.org]On Behalf Of Dan Glassman > > Sent: Thursday, 26 January 2006 6:29 AM > > To: python-win32 at python.org > > Subject: [python-win32] Autocad automation via COM: Passing coordinates > > as arguments (suggested fix within) > > > > > > > From: wccppp > > > Subject: [python-win32] question about COM again: variable type? > > > > > > [code] > > > ms.AddPoint([0.0, 0.0, 0.0]) # this line gives the problem > > > [/code] > > > > > > # Result is of type IAcadPoint > > > def AddPoint(self, Point=defaultNamedNotOptArg): > > > """Creates a Point object at a given location""" > > > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, > > > 1),),Point) > > > if ret is not None: > > > ret = Dispatch(ret, 'AddPoint', > > > '{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0) > > > return ret > > > > > Sorry for the long reply. > > > > The type library for AutoCad 2006 says that coordinates should be > > passed as variants, so makepy's output is correct. But you can change > > the makepy-generated file to process the argument as an array of doubles > > instead of a variant and it will work. I'm not sure if that's because > > the interface will also accept a 'raw' array, or if pythoncom is > > magically wrapping the array in a variant. > > > > Taking from the AddPoint method of the IAcadModelSpace class that you've > > included: > > > > [code] > > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point) > > [/code] > > > > The (12, 1) part describes the Point argument as an (Variant, Input), > > roughly. This should be changed to (8197, 1), which is (Array of > > Doubles, Input): > > > > [code] > > ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0),((8197,1),),Point) > > [/code] > > > > Unfortunately, this happens all over the place -- not just the AddPoint > > method. It would be very tedious to go through makepy's output and > > make the >1500 changes. (12, 1) cannot be changed globally in there. It > > also happens for more than just coordinate arguments; the Select methods > > of SelectionSet objects have filters which are also arrays wrapped in a > > variant. I haven't run across any others; the code below fixes > > everything I've found. > > > > My solution was to change build.py (does some of makepy's work; located > > in %pythoninstalldir%\lib\site-packages\win32com\client\) to apply this > > Variant -> Array change for me when processing the type library. The > > line numbers I reference are from pywin32 2.07; I tried to include > > enough context to find the right parts of build.py in case yours is > > different. > > > > My understanding of COM is not good, and these changes to build.py don't > > seem suitably robust. It does a small check to see if it's processing > > an Autocad library, but I suggest restoring build.py to its original > > state after processing your Autocad type libraries. You'll lose these > > fixes for dynamic dispatch in that case. > > > > I would be grateful if somebody could point out any red flags or suggest > > a better approach. > > > > Near the top of build.py (~line 52): > > > > [code] > > NoTranslateMap = {} > > for v in NoTranslateTypes: > > NoTranslateMap[v] = None > > > > #My addition starts here > > AutocadTranslateMap = { > > ('alignpoint','anglevertex','arccenter','arcpoint','axisdir', > > 'axispoint','basepoint','boundry','center','centerpoint', > > 'chordpoint','controlpoint','controlpoints','coordinates', > > 'definitionpoint','dimlinelocation','direction', > > 'directionvector','endpoint','endtangent','extline1point', > > 'extline1startpoint','extline2endpoint','extline2point', > > 'extline2startpoint','farchordpoint','firstendpoint','fitpoint', > > 'fitpoints','frompoint','insertionpoint','inspoint','jogpoint', > > 'knots','knotvalues','leader1point','leader2point', > > 'leaderendpoint','limits','lowerleft','lowleft','majoraxis', > > 'normal','origin','overridecenter','overridecenterpos', > > 'plotorigin','point','point1','point2','point3','point4', > > 'pointsarray','pointslist','pointsmatrix','porigin', > > 'secondendpoint','secondpoint','snapbasepoint','startpoint', > > 'starttangent','target','targetpoint','textalignmentpoint', > > 'textpoint','textpos','textposition','topoint', > > 'transformationmatrix','upperright','vertex','vertexlist', > > 'vertices','verticeslist','weights','wpt','wpt1','wpt2', > > 'xaxispoint','xline1point','xline2point','xvector', > > 'yaxispoint','yvector'): 8197, > > ('filtertype',): 8193, > > ('filterdata',): 8204 > > } > > #My addition ends here > > > > class MapEntry: > > "Simple holder for named attibutes - items in a map." > > def __init__(self, desc_or_id, names=None, doc=None, > > resultCLSID=pythoncom.IID_NULL, resultDoc = None, hidden=0): > > [/code] > > > > Then, in the _AddFunc_ method of class DispatchItem (~line 175): > > > > Note that the code below has been stripped of its indentation to > > hopefully make it more readable in email. Indentation within the posted > > code is correct, but the entire code block needs to be indented to match > > its context in build.py. > > > > [code] > > fdesc.rettype = typerepr, flag, defval, resultCLSID > > # Translate any Alias or Enums in argument list. > > argList = [] > > > > #Changes begin here; > > #for argDesc in fdesc.args: > > for index, argDesc in enumerate(fdesc.args): > > typerepr, flag, defval = argDesc > > > > #Catch only if reasonably sure this is Autocad > > if self.python_name[:5] == 'IAcad': > > #Catch (VT_VARIANT, FIN) and (VT_VARIANT, FIN|FOPT) > > #Outputs seem to translate into tuples just fine already > > if typerepr == 12 and (flag == 1 or flag == 17): > > if len(fdesc.args) == len(names): #???Properties??? > > replace = [key for key in AutocadTranslateMap.keys() \ > > if names[index].lower() in key] > > if replace: > > typerepr = AutocadTranslateMap[replace[0]] > > else: #names[0] is method name; names[1:] is arg names > > replace = [key for key in AutocadTranslateMap.keys() \ > > if names[index+1].lower() in key] > > if replace: > > typerepr = AutocadTranslateMap[replace[0]] > > #Changes end here; > > > > arg_type, arg_clsid, arg_doc = _ResolveType(typerepr, typeinfo) > > > > argDesc = arg_type, flag, defval, arg_clsid > > # sys.stderr.write("%s\n" % (argDesc[0],)) > > argList.append(argDesc) > > fdesc.args = tuple(argList) > > [/code] > > _______________________________________________ > > Python-win32 mailing list > > Python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Regards, - wcc -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060201/a8c9dc83/attachment.htm From timr at probo.com Thu Feb 2 18:52:53 2006 From: timr at probo.com (Tim Roberts) Date: Thu, 02 Feb 2006 09:52:53 -0800 Subject: [python-win32] Grumpy Curmudgeonly Complaint In-Reply-To: References: Message-ID: <43E246F5.2050404@probo.com> Please, wcc, when you reply to a message, take the time to delete the quoted parts of the original message that aren't relevent to your reply. Your last two messages have each had 8 lines of new content, plus more than 170 lines of quoted text that really didn't need to be repeated. When you're reading messages individually, you can just skip to the next one. For those of us who read the digest, however, we have to scroll through all 170 lines of quoted stuff to try to find the beginning of the next message. My one complaint about top posting is that it makes it WAY too easy to ignore excessive quoting. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From reed at intersiege.com Thu Feb 2 18:52:18 2006 From: reed at intersiege.com (Reed L. O'Brien) Date: Thu, 02 Feb 2006 12:52:18 -0500 Subject: [python-win32] Create VPN connections Message-ID: <43E246D2.6070905@intersiege.com> I know I can dial # Get the parameters to Dial a Stored VPN Connection vpn, pw = ras.GetEntryDialParams(None, 'FOO') # Dial the connection rasHandle, retCode = ras.Dial(None, None, vpn, None) And hang up ras.HangUp(rasHandle) But can I build one from scratch and save it so it shows up in Network connections? TIA, ~reed -- 4.6692916090 'cmVlZEBpbnRlcnNpZWdlLmNvbQ==\n'.decode('base64') http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1 keyID: 0x0FA09FCE From reed at intersiege.com Thu Feb 2 18:55:19 2006 From: reed at intersiege.com (Reed L. O'Brien) Date: Thu, 02 Feb 2006 12:55:19 -0500 Subject: [python-win32] Sorry re: Create VPN connections Message-ID: <43E24787.20007@intersiege.com> I think that message went out as html. My MUA usually prompts me for the format before it sends. But for some reason it didn't that time. My apologies for the extra noise if you received it that way. best, ~r -- 4.6692916090 'cmVlZEBpbnRlcnNpZWdlLmNvbQ==\n'.decode('base64') http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1 keyID: 0x0FA09FCE From rwupole at msn.com Fri Feb 3 01:47:28 2006 From: rwupole at msn.com (Roger Upole) Date: Thu, 2 Feb 2006 19:47:28 -0500 Subject: [python-win32] Re: Reading properties from office builtin dialogs? References: <7wr76olp2s.fsf@enki.strakt.com> Message-ID: Anders Quist wrote: >I have an application that wants to print a large set of documents. > Therefore, I want to have word display its print dialog so the user > can supply printer settings once, that I can read and store for use > with all following prints. > > At first glance, this would seem straight-forward; VBA like so: > > Dim dlgPrint As Dialog > Set dlgPrint = Dialogs(wdDialogFilePrint) > dlgPrint.Display > MsgBox "printer = " & dlgPrint.Printer > > However, when tried in python, the property Printer does not seem to > be available. A little trial-and-error indicates that no such > properties are available from Word builtin dialogs: > > >>> import win32com.client > >>> x = win32com.client.Dispatch("Word.Application") > >>> p = x.Dialogs(win32com.client.constants.wdDialogFilePrint) > >>> p.Display() > > >>> p.Printer > Traceback (most recent call last): > File "", line 1, in ? > File > "c:\python\env\env11\lib\site-packages\win32com\client\__init__.py", line > 451, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % > (repr(self), attr) > AttributeError: ' Library.Dialog instance at 0x21494960>' object has no attribute 'Printer' > > What am I doing wrong? > -- > Anders Qvist, AB Strakt > Using early binding (makepy), the Printer property isn't available since it's not defined in the typelib. You can force a dynamic dispatch, though: >>> dynamic_p=win32com.client.dynamic.DumbDispatch(p) >>> dynamic_p.Printer u'Lexmark 710 Series' hth Roger From info at apli-agipa.com Fri Feb 3 14:23:56 2006 From: info at apli-agipa.com (Sylvain FAUVEAU (apli-agipa)) Date: Fri, 3 Feb 2006 14:23:56 +0100 Subject: [python-win32] Range('A:A,D:D,G:G') in excel Message-ID: <000301c628c5$169cc900$0165a8c0@apliagipa51.com> Hello. I have a little problem with this instruction. If i run a macro in excel (Office 2003 SP1) to select 3 columns for exemple, the code in VB is : Range('A:A,D:D,G:G') But if I try this in python, I have a beautiful traceback : excel.ActiveSheet.Range('A:A,D:D,G:G') Traceback (most recent call last): File "", line 1, in ? File "C:\usr\Python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x5.py", line 31738, in Range , Cell2) com_error: (-2147352567, "Une exception s'est produite.", (0, None, None, None, 0, -2146827284), None) Any idea ? Sylvain FAUVEAU From info at apli-agipa.com Fri Feb 3 14:28:47 2006 From: info at apli-agipa.com (Sylvain FAUVEAU (apli-agipa)) Date: Fri, 3 Feb 2006 14:28:47 +0100 Subject: [python-win32] Range('A:A,D:D,G:G') in excel Message-ID: <000901c628c5$c35abd50$0165a8c0@apliagipa51.com> > If i run a macro in excel (Office 2003 SP1) to select 3 columns for > exemple, the code in VB is : > Range('A:A,D:D,G:G') > > But if I try this in python, I have a beautiful traceback : > excel.ActiveSheet.Range('A:A,D:D,G:G') I don't know why, but if I change the ',' by ';' it's ok ! Sylvain FAUVEAU From sumeet_sobti at yahoo.com Fri Feb 3 22:19:57 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Fri, 3 Feb 2006 13:19:57 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a method of a COM object Message-ID: <20060203211957.13922.qmail@web60711.mail.yahoo.com> Hi everyone, I am struggling with a problem related to passing a VARIANT argument to a COM object. I am getting this exception: TypeError: The VARIANT type is unknown (0000001e) Here's what I am trying to execute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import win32com.client >>> >>> obj = win32com.client.Dispatch('XTAPI.TTOrderSelector') >>> >>> obj.AddTest('IsBuy', True) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\site-packages\win32com\gen_py\98B8AE14-466F-11D6-A27B-00B0D0F3CCA6x0x1x0.py", line 609, in AddTest return self._oleobj_.InvokeTypes(4, LCID, 1, (24, 0), ((30, 1), (12, 1)),lpProperty, vValue) TypeError: The VARIANT type is unknown (0000001e) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The makepy generated code-snippet is this: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def AddTest(self, lpProperty=defaultNamedNotOptArg, vValue=defaultNamedNotOptArg): """method AddTest""" return self._oleobj_.InvokeTypes(4, LCID, 1, (24, 0), ((30, 1), (12, 1)),lpProperty, vValue) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The AddTest method is documented to accept two arguments: the first argument is a string and the second is a variant. It returns nothing. I am not able to pass anything as the second argument. I have tried string, int, float,... but nothing gets properly converted to variant, and I get the same exception as above. What does the above exception really mean? Regardless of what I pass as the second argument, I get the same exception message. It just complains about unknown type 0000001e, which probably corresponds to VT_LPSTR. But, why is it trying to convert True to a VT_LPSTR?! I'd really appreciate any ideas/help. Thanks! -Sumeet. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mark.mclarnon at gmail.com Sat Feb 4 18:45:17 2006 From: mark.mclarnon at gmail.com (mark mclarnon) Date: Sat, 4 Feb 2006 12:45:17 -0500 Subject: [python-win32] PythonService.exe and Windows Server 2003 Message-ID: <253738580602040945k4d4fdb8en40f7c256d7663c7a@mail.gmail.com> I have a class which was configured to start as a service (using an external PY file) under Windows 2000 Server. It started/stopped just fine on Win2k but when trying to start it on Windows 2003 Server I get an error that reports a message like "the stub recieved bad data". I can start this class manually from the command line but obviously I want it to start as a service. I didnt record the error code that was associated with the message but was wondering, has anyone had problems with PythonService.exe and Windows 2003 Server? I was running ActiveState Python 2.4.1 and upgraded to 2.4.2 yesterday but that did not help the issue. I even manaully upgraded the pywin32 package also to no avail. Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060204/d32129d5/attachment.html From mhammond at skippinet.com.au Sun Feb 5 08:44:19 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 5 Feb 2006 18:44:19 +1100 Subject: [python-win32] PythonService.exe and Windows Server 2003 In-Reply-To: <253738580602040945k4d4fdb8en40f7c256d7663c7a@mail.gmail.com> Message-ID: > From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of mark mclarnon > I didnt record the error code that was associated with the message but was > wondering, has anyone had problems with PythonService.exe and Windows 2003 > Server? I'm afraid I haven't heard anything similar - but I have personally had no problems with services on Windows Server 2003. Sorry I can't be more help... Mark From mhammond at skippinet.com.au Sun Feb 5 08:54:31 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 5 Feb 2006 18:54:31 +1100 Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: <20060203211957.13922.qmail@web60711.mail.yahoo.com> Message-ID: > I am struggling with a problem related to passing a > VARIANT argument to a COM object. > > I am getting this exception: > > TypeError: The VARIANT type is unknown (0000001e) Hmmm - I guess that is a bug in pywin32 - that variant type *is* valid in a TYPEDESC, so pywin32 probably should convert that during the makepy process. > The makepy generated code-snippet is this: > > - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - > def AddTest(self, lpProperty=defaultNamedNotOptArg, > vValue=defaultNamedNotOptArg): > """method AddTest""" > return self._oleobj_.InvokeTypes(4, LCID, 1, (24, > 0), ((30, 1), (12, 1)),lpProperty, vValue) Can you please try changing the 30 there to 8 (ie, changing from VT_LPSTR to VT_BSTR) and let me know if it works? Actually, better yet - if it *does* work, please open a new pywin32 bug at sourceforge. If it *doesn't* work it may point at an error in the COM object. > What does the above exception really mean? Regardless > of what I pass as the second argument, I get the same > exception message. > It just complains about unknown type 0000001e, which > probably corresponds to VT_LPSTR. But, why is it > trying to convert True to a VT_LPSTR?! It is the first string arg that is causing the problem. Thanks, Mark. From Ted.Speers at actel.com Mon Feb 6 01:18:51 2006 From: Ted.Speers at actel.com (Speers, Ted) Date: Sun, 5 Feb 2006 16:18:51 -0800 Subject: [python-win32] Visual Basic Message-ID: I'd like to redo all my Visual Basic Projects in Python ... I would have started down the Python path from the get-go but was in too much of rush. Now that I have a moment, I thought I'd get the help I need. I know how to connect to Excel: win32com.client.Dispatch("Excel.Application"). How do I connect to a VisualBasic project? I need more help than that though. I can run a *.py script from a Visual Basic application but I'm not quite sure how to keep running so I don't lose the objects and variables I populate the first time I run the program ... I need to run additional programs using that data. If I can do this I'll be golden: Imagine an Excel Macro Start that does the following: Sub Start(): Set form = MyUserForm load form form.show vbmodeless end sub Imagine userform "MyUserForm" with two CommandButtons ... "init" and "getdouble" and a TextBox "result" My VisualBasic UserFormModule would have the following (pseudo)code: sub init_click() initval=inputbox("enter the initialization value") end sub double_click() end A python module that would work for me would be: import win32com.client XLApp=win32com.client.Dispatch( "Excel.Application") VBProj =win32com.client. Dispatch( ?) class XLProj: def __init(self)__: self.val=None def init(initval): MyProj.val=initval def doubleval(): VPProj.MyUserForm.Controls("result").Value=MyProj.val*2 MyProj=XLProj() This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export. An export can include a release or disclosure to a foreign national inside or outside the United States. Include this notice with any reproduced portion of this information. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060205/c34d3266/attachment.html From f.g.- at gmx.de Mon Feb 6 11:29:27 2006 From: f.g.- at gmx.de (=?iso-8859-1?Q?Frank_G=FCnther?=) Date: Mon, 6 Feb 2006 11:29:27 +0100 Subject: [python-win32] win32pdh problems Message-ID: <005e01c62b08$38fd60a0$1901a8c0@ttddm02> Hi, I use win32pdh and EnumObjectsItems to get pids for application name. By importing win32pdh or calling win32pdh.EnumObjectItems I get several strange hard to find problems on some machines. The problems occur only on few machines (XP and NT)! 1.) the float separator is changed from . to , so there arise unpickling errors (workaround is to call locale.setlocale(locale.LC_NUMERIC, "C") posted here before) 2.) the working directory (os.getcwd()) is changed to a complete different path 3.) a connected socket (using module socket) is disconnected Are there changes in win32pdh on newer versions then Py2.3 and PyWin Built 204? I think about not using win32pdh anymore to get the pids from application names. Has anyone a suggestion for implementing this in a different way? Ciao, Frank -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060206/88516328/attachment.htm From tim.golden at viacom-outdoor.co.uk Mon Feb 6 13:04:07 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 6 Feb 2006 12:04:07 -0000 Subject: [python-win32] win32pdh problems Message-ID: <9A28C052FF32734DACB0A288A3533991044D251C@vogbs009.gb.vo.local> [Frank G?nther] | I use win32pdh and EnumObjectsItems ... to get pids for | application name. | Has anyone a suggestion for implementing this in a different way? Well, assuming that all you want is a PID (or a list of them) for a given application name, you can do it with WMI. I don't know if it will cause the same kind of problems you saw above, but I don't see why it should: (uses wmi module from http://timgolden.me.uk/python/wmi.html) import wmi c = wmi.WMI () for p in c.Win32_Process (Name="notepad.exe"): print p.ProcessId TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From timr at probo.com Mon Feb 6 18:06:45 2006 From: timr at probo.com (Tim Roberts) Date: Mon, 06 Feb 2006 09:06:45 -0800 Subject: [python-win32] Visual Basic In-Reply-To: References: Message-ID: <43E78225.70401@probo.com> On Sun, 5 Feb 2006 16:18:51 -0800, "Speers, Ted" wrote: >I'd like to redo all my Visual Basic Projects in Python ... I would >have started down the Python path from the get-go but was in too much of >rush. Now that I have a moment, I thought I'd get the help I need. > >I know how to connect to Excel: >win32com.client.Dispatch("Excel.Application"). > >How do I connect to a VisualBasic project? > > I can't tell from the rest of the message what you mean by "connect to". You can connect to a COM server; if your VB code serves COM objects, you can create and manage them, just like you do with Excel. If not, then there is no way to control them from the outside. It would be like trying to connect to a C++ "Hello, world". >If I can do this I'll be golden: > >Imagine an Excel Macro Start that does the following: > >Sub Start(): > Set form = MyUserForm > load form > form.show vbmodeless > >end sub > > Yes, but you can't really do that from Excel either, can you? If MyUserForm is a VBA form within Excel, then there are ways you can do this from Python using Excel's object model. But when you are using a VB main program of your own creation, you have probably not created enough COM objects for that level of control. If you are switching to wxPython, then what you want to do is recreate MyUserForm in wxPython code, and eliminate the VB code altogether. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Ted.Speers at actel.com Mon Feb 6 18:33:12 2006 From: Ted.Speers at actel.com (Speers, Ted) Date: Mon, 6 Feb 2006 09:33:12 -0800 Subject: [python-win32] Visual Basic Message-ID: >If I can do this I'll be golden: > >Imagine an Excel Macro Start that does the following: > >Sub Start(): > Set form = MyUserForm > load form > form.show vbmodeless > >end sub > > Yes, but you can't really do that from Excel either, can you? If MyUserForm is a VBA form within Excel, then there are ways you can do this from Python using Excel's object model. But when you are using a VB main program of your own creation, you have probably not created enough COM objects for that level of control. - -All of my VBA code is "within Excel." Sorry for the confusion. I don't know any better. - -Your next statement hints at a solution to my contortions. All I really want VB for is the damn widgets. When I first looked at Python more than a year ago, I spent quite a bit of time looking for a way to easily design and use widgets with Python and I found nothing easy to use or even comprehensible. I'm hoping your wxPython reference is the answer ... I have not heard of it before. If you are switching to wxPython, then what you want to do is recreate MyUserForm in wxPython code, and eliminate the VB code altogether. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export. An export can include a release or disclosure to a foreign national inside or outside the United States. Include this notice with any reproduced portion of this information. From timr at probo.com Mon Feb 6 18:59:26 2006 From: timr at probo.com (Tim Roberts) Date: Mon, 06 Feb 2006 09:59:26 -0800 Subject: [python-win32] Visual Basic In-Reply-To: References: Message-ID: <43E78E7E.4050003@probo.com> Speers, Ted wrote: > >- -All of my VBA code is "within Excel." Sorry for the confusion. I don't know any better. > > I wondered about that, and I probably should have clarified it before I responded. VBA forms are just Excel objects, and should be able to be manipulated using the Excel object model from Python. I thought there was a "Forms" collection in the Excel application or workbook objects, but in a few minutes of experimentation, I cannot find it, and the word "form" is so common that Google is nearly worthless. >- -Your next statement hints at a solution to my contortions. All I really want VB for is the damn widgets. When I first looked at Python more than a year ago, I spent quite a bit of time looking for a way to easily design and use widgets with Python and I found nothing easy to use or even comprehensible. I'm hoping your wxPython reference is the answer ... I have not heard of it before. > > This was my mistake, actually. I subscribe to both the "pywin32" list and the "wxPython" list, and when I saw your message, I had a moment of disorientation. I thought you were posting to the wxPython list, which is why I was so confused as to why you'd want to manipulate VB code, instead of rewriting it! It is quite possible that wxPython may solve your problem, but it really depends on what you're doing. The nice thing about VBA is that it executed entirely inside Excel. With wxPython, you would have a separate program, controlling and interacting with Excel. Quite workable, but you'll have to decide how appropriate for your situation. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Ted.Speers at actel.com Mon Feb 6 19:10:00 2006 From: Ted.Speers at actel.com (Speers, Ted) Date: Mon, 6 Feb 2006 10:10:00 -0800 Subject: [python-win32] Visual Basic Message-ID: Maybe I should have just asked how to deal with this first. xlapp=win32com.client.Dispatch("Excel.Application") book=xlapp.Workbooks("bookname") VBProj=book.VBProject ... com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Office Excel', 'Programmatic access to Visual Basic Project is not trusted\n', 'C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None) >>> It appears to me that I need to sign my Project for Python will let me see it ... is there a workaround? ________________________________ From: python-win32-bounces+ted.speers=actel.com at python.org on behalf of Tim Roberts Sent: Mon 2/6/2006 9:06 AM To: python-win32 at python.org Subject: Re: [python-win32] Visual Basic On Sun, 5 Feb 2006 16:18:51 -0800, "Speers, Ted" wrote: >I'd like to redo all my Visual Basic Projects in Python ... I would >have started down the Python path from the get-go but was in too much of >rush. Now that I have a moment, I thought I'd get the help I need. > >I know how to connect to Excel: >win32com.client.Dispatch("Excel.Application"). > >How do I connect to a VisualBasic project? > > I can't tell from the rest of the message what you mean by "connect to". You can connect to a COM server; if your VB code serves COM objects, you can create and manage them, just like you do with Excel. If not, then there is no way to control them from the outside. It would be like trying to connect to a C++ "Hello, world". >If I can do this I'll be golden: > >Imagine an Excel Macro Start that does the following: > >Sub Start(): > Set form = MyUserForm > load form > form.show vbmodeless > >end sub > > Yes, but you can't really do that from Excel either, can you? If MyUserForm is a VBA form within Excel, then there are ways you can do this from Python using Excel's object model. But when you are using a VB main program of your own creation, you have probably not created enough COM objects for that level of control. If you are switching to wxPython, then what you want to do is recreate MyUserForm in wxPython code, and eliminate the VB code altogether. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export. An export can include a release or disclosure to a foreign national inside or outside the United States. Include this notice with any reproduced portion of this information. From timr at probo.com Mon Feb 6 19:27:24 2006 From: timr at probo.com (Tim Roberts) Date: Mon, 06 Feb 2006 10:27:24 -0800 Subject: [python-win32] Visual Basic In-Reply-To: References: Message-ID: <43E7950C.3090207@probo.com> Speers, Ted wrote: >Maybe I should have just asked how to deal with this first. > >xlapp=win32com.client.Dispatch("Excel.Application") >book=xlapp.Workbooks("bookname") >VBProj=book.VBProject > >... >com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Office Excel', 'Programmatic access to Visual Basic Project is not trusted\n', 'C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None) > > >It appears to me that I need to sign my Project for Python will let me see it ... is there a workaround? > > Googling the message brought me to an MSDN page that discusses this. If you go to Tools, Macros, Security, you should be able to check a box saying to "trust access to Visual Basic project". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mathweijzen at home.nl Mon Feb 6 19:43:25 2006 From: mathweijzen at home.nl (Math) Date: Mon, 6 Feb 2006 19:43:25 +0100 Subject: [python-win32] Attributes of win32com and accessing MS Access Message-ID: <002d01c62b4d$38be0050$0402a8c0@uw403axvp2ndff> Hello, Pardon my English, my native is Dutch. Can somebody please tell me where I can find more information about win32com module and attributes. I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python. Where can I find all methods and so on from ****win32com*** when it comes to DataVase prorgramming? Anybody any ideas or examples? Thank you Math -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060206/b32ef610/attachment.html From sumeet_sobti at yahoo.com Mon Feb 6 21:01:30 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Mon, 6 Feb 2006 12:01:30 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: Message-ID: <20060206200130.9351.qmail@web60719.mail.yahoo.com> Hi, > > - - - - - - - - > > def AddTest(self, > lpProperty=defaultNamedNotOptArg, > > vValue=defaultNamedNotOptArg): > > """method AddTest""" > > return self._oleobj_.InvokeTypes(4, LCID, 1, > (24, > > 0), ((30, 1), (12, 1)),lpProperty, vValue) > > Can you please try changing the 30 there to 8 (ie, > changing from VT_LPSTR to > VT_BSTR) and let me know if it works? I tried changing the 30 to 8 in the above line. This does *not* work either, although it gives a different error this time: >>> obj.AddTest('IsBuy', True) Traceback (most recent call last): File "", line 1, in ? File "c:\Python24\lib\site-packages\win32com\gen_py\98B8AE14-466F-11D6-A27B-00B0D0F3CCA6x0x1x0.py", line 610, in AddTest return self._oleobj_.InvokeTypes(4, LCID, 1, (24, 0), ((8, 1), (12, 1)),lpProperty, vValue) pywintypes.com_error: (-2147352568, 'Bad variable type.', None, None) > Actually, better yet - if it *does* work, please > open a new pywin32 bug at > sourceforge. If it *doesn't* work it may point at > an error in the COM > object. I am not familiar with COM/pywin much.. so please bear with my ignorance.. Does the error above show with some certainty that it's a problem with the COM object? I looked at the other COM objects in the API package that this particular COM object belongs to. A few other objects have a similar method that is documented to accept a String and a Variant argument. They work fine. Their definitions in the makepy generated file look like this: def Set(self, vKey=defaultNamedNotOptArg, newVal=defaultNamedNotOptArg): """method Set""" return self._oleobj_.InvokeTypes(4, LCID, 1, (24, 0), ((12, 1), (12, 1)),vKey, newVal) And these methods seem to work just fine. Is this sufficient evidence to say that the AddTest method is incorrectly implemented? (Mark, thanks for helping!) -Sumeet. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mark.mclarnon at gmail.com Mon Feb 6 21:47:51 2006 From: mark.mclarnon at gmail.com (mark mclarnon) Date: Mon, 6 Feb 2006 15:47:51 -0500 Subject: [python-win32] PythonService.exe and Windows Server 2003 In-Reply-To: References: <253738580602040945k4d4fdb8en40f7c256d7663c7a@mail.gmail.com> Message-ID: <253738580602061247q3b512ef9u5e07738650cb5794@mail.gmail.com> Mark: I appreciate the resposne, I have the exact text of the error message in case this helps anyone else out in the future: pywintypes.error:(1783,'RegisterEventSource/ReportEvent','The stub recieved bad data') Mark On 2/5/06, Mark Hammond wrote: > > > From: python-win32-bounces at python.org > [mailto:python-win32-bounces at python.org]On Behalf Of mark mclarnon > > > I didnt record the error code that was associated with the message but > was > > wondering, has anyone had problems with PythonService.exe and Windows > 2003 > > Server? > > I'm afraid I haven't heard anything similar - but I have personally had no > problems with services on Windows Server 2003. > > Sorry I can't be more help... > > Mark > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060206/ee1b2b2d/attachment.html From timr at probo.com Mon Feb 6 22:09:36 2006 From: timr at probo.com (Tim Roberts) Date: Mon, 06 Feb 2006 13:09:36 -0800 Subject: [python-win32] Attributes of win32com and accessing MS Access In-Reply-To: References: Message-ID: <43E7BB10.4080503@probo.com> On Mon, 6 Feb 2006 19:43:25 +0100, "Math" wrote: >Pardon my English, my native is Dutch. >Can somebody please tell me where I can find more information about win32com module and attributes. >I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python. >Where can I find all methods and so on from ****win32com*** when it comes to DataVase prorgramming? >Anybody any ideas or examples? > There are actually two separate issues here. You must use the actual Access application itself to create a brand-new database. The easiest way to do that is to just fire up Access manually, create an empty database, and save it. You cannot do that through ADO. It is certainly manipulate Access from Python: db = win32com.client.Dispatch("Access.Application") However, I don't know the Access object model command for creating a new database. Once an empty database is created, you don't need to run Access any more. You can do everything you need by driving ADODB or ODBC, and there are lots of good examples on the web to show you how to do that. conn = win32com.client.Dispatch("ADODB.Connection") # Either way works: the first is the Jet OLEDB driver, the other is the # Access ODBC driver. db = r"c:\dev\54nsdc\Volunteer.mdb" DSN="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db #DSN="Driver={Microsoft Access Driver (*.mdb)};DBQ=" + db conn.Open(DSN) rs = win32com.client.Dispatch("ADODB.Recordset") rs.Open( "[Committees]", conn, 1, 3 ) print rs.Fields.Count, " fields found:" for x in range(rs.Fields.Count): print rs.Fields.Item(x).Name, That uses a table recordset, but it's just as easy to use SQL: cmd = win32com.client.Dispatch("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandText = "SELECT * FROM volunteers ORDER BY LastName;" rs = cmd.Execute()[0] rs.MoveFirst() while not rs.EOF: print rs.Fields("LastName") -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mathweijzen at home.nl Mon Feb 6 22:25:26 2006 From: mathweijzen at home.nl (Math) Date: Mon, 6 Feb 2006 22:25:26 +0100 Subject: [python-win32] Attributes of win32com and accessing MS Access References: <43E7BB10.4080503@probo.com> Message-ID: <003901c62b63$d99d7710$0402a8c0@uw403axvp2ndff> I found a solution (Should be ADOX) :-): How to create db.mdb in Pyton: cat = win32com.client.Dispatch(r'ADOX.Catalog') cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb") Thanks ----------------------------------------------------------- > On Mon, 6 Feb 2006 19:43:25 +0100, "Math" wrote: > >>Pardon my English, my native is Dutch. >>Can somebody please tell me where I can find more information about >>win32com module and attributes. >>I wanna create a empty MS Access DataBase with COM, ADO and SQL from >>Python. >>Where can I find all methods and so on from ****win32com*** when it comes >>to DataVase prorgramming? >>Anybody any ideas or examples? >> > > > There are actually two separate issues here. You must use the actual > Access application itself to create a brand-new database. The easiest > way to do that is to just fire up Access manually, create an empty > database, and save it. You cannot do that through ADO. It is certainly > manipulate Access from Python: > > db = win32com.client.Dispatch("Access.Application") > > However, I don't know the Access object model command for creating a new > database. > > Once an empty database is created, you don't need to run Access any > more. You can do everything you need by driving ADODB or ODBC, and > there are lots of good examples on the web to show you how to do that. > > conn = win32com.client.Dispatch("ADODB.Connection") > > # Either way works: the first is the Jet OLEDB driver, the other is the > # Access ODBC driver. > > db = r"c:\dev\54nsdc\Volunteer.mdb" > DSN="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db > #DSN="Driver={Microsoft Access Driver (*.mdb)};DBQ=" + db > conn.Open(DSN) > > rs = win32com.client.Dispatch("ADODB.Recordset") > rs.Open( "[Committees]", conn, 1, 3 ) > > print rs.Fields.Count, " fields found:" > for x in range(rs.Fields.Count): > print rs.Fields.Item(x).Name, > > That uses a table recordset, but it's just as easy to use SQL: > > cmd = win32com.client.Dispatch("ADODB.Command") > cmd.ActiveConnection = conn > > cmd.CommandText = "SELECT * FROM volunteers ORDER BY LastName;" > rs = cmd.Execute()[0] > > rs.MoveFirst() > while not rs.EOF: > print rs.Fields("LastName") > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > Python-win32 mailing list > Python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From mhammond at skippinet.com.au Mon Feb 6 22:33:14 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 7 Feb 2006 08:33:14 +1100 Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: <20060206200130.9351.qmail@web60719.mail.yahoo.com> Message-ID: > I tried changing the 30 to 8 in the above line. This > does *not* work either, although it gives a different > error this time: > > >>> obj.AddTest('IsBuy', True) > Traceback (most recent call last): > File "", line 1, in ? > File > "c:\Python24\lib\site-packages\win32com\gen_py\98B8AE14-466F-11D6- > A27B-00B0D0F3CCA6x0x1x0.py", > line 610, in AddTest > return self._oleobj_.InvokeTypes(4, LCID, 1, (24, > 0), ((8, 1), (12, 1)),lpProperty, vValue) > pywintypes.com_error: (-2147352568, 'Bad variable > type.', None, None) > > > > Actually, better yet - if it *does* work, please > > open a new pywin32 bug at > > sourceforge. If it *doesn't* work it may point at > > an error in the COM > > object. > > > I am not familiar with COM/pywin much.. so please bear > with my ignorance.. > > Does the error above show with some certainty that > it's a problem with the COM object? Sadly it doesn't demonstrate much with any certainty! > I looked at the other COM objects in the API package > that this particular COM object belongs to. A few > other objects have a similar method that is documented > to accept a String and a Variant argument. They work > fine. > > Their definitions in the makepy generated file look > like this: > > def Set(self, vKey=defaultNamedNotOptArg, > newVal=defaultNamedNotOptArg): > """method Set""" > return self._oleobj_.InvokeTypes(4, LCID, 1, (24, > 0), ((12, 1), (12, 1)),vKey, newVal) > > And these methods seem to work just fine. Is this > sufficient evidence to say that the AddTest method is > incorrectly implemented? That is strange - any of their methods correct use a string, but AddTest appears to spell it in a different way. Is it possible for you to contact the authors of this object? Mark From Ted.Speers at actel.com Mon Feb 6 22:48:18 2006 From: Ted.Speers at actel.com (Speers, Ted) Date: Mon, 6 Feb 2006 13:48:18 -0800 Subject: [python-win32] Visual Basic Message-ID: Thanks for your help ... That does the trick. -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Roberts Sent: Monday, February 06, 2006 10:27 AM To: python-win32 at python.org Subject: Re: [python-win32] Visual Basic Speers, Ted wrote: >Maybe I should have just asked how to deal with this first. > >xlapp=win32com.client.Dispatch("Excel.Application") >book=xlapp.Workbooks("bookname") >VBProj=book.VBProject > >... >com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Office >Excel', 'Programmatic access to Visual Basic Project is not trusted\n', >'C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm', 0, >-2146827284), None) > > >It appears to me that I need to sign my Project for Python will let me see it ... is there a workaround? > > Googling the message brought me to an MSDN page that discusses this. If you go to Tools, Macros, Security, you should be able to check a box saying to "trust access to Visual Basic project". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export. An export can include a release or disclosure to a foreign national inside or outside the United States. Include this notice with any reproduced portion of this information. From mathweijzen at home.nl Mon Feb 6 21:48:35 2006 From: mathweijzen at home.nl (Math) Date: Mon, 6 Feb 2006 21:48:35 +0100 Subject: [python-win32] Attributes of win32com and accessing MS Access References: <002d01c62b4d$38be0050$0402a8c0@uw403axvp2ndff> Message-ID: <003b01c62b5e$b5c22e80$0402a8c0@uw403axvp2ndff> I already found a solution :=). ---------------------------------------------- ----- Original Message ----- From: Math To: python-win32 at python.org Sent: Monday, February 06, 2006 7:43 PM Subject: [python-win32] Attributes of win32com and accessing MS Access Hello, Pardon my English, my native is Dutch. Can somebody please tell me where I can find more information about win32com module and attributes. I wanna create a empty MS Access DataBase with COM, ADO and SQL from Python. Where can I find all methods and so on from ****win32com*** when it comes to DataVase prorgramming? Anybody any ideas or examples? Thank you Math ------------------------------------------------------------------------------ _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060206/de757a0e/attachment.htm From mhammond at skippinet.com.au Mon Feb 6 23:09:17 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 7 Feb 2006 09:09:17 +1100 Subject: [python-win32] PythonService.exe and Windows Server 2003 In-Reply-To: <253738580602061247q3b512ef9u5e07738650cb5794@mail.gmail.com> Message-ID: Do you have the complete traceback? This is from an event-log message, so if this is a call you are making, it may be that something is wrong with the params (eg, the inserts). This will not fail in "debug" mode as debug mode makes no attempt to actually write such entries to the log - it just prints them. In general though, services should catch errors writing to the log - they are common when the log gets full. I guess I should update the samples to reflect that... Mark. -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of mark mclarnon Sent: Tuesday, 7 February 2006 7:48 AM To: Mark Hammond Cc: python-win32 at python.org Subject: Re: [python-win32] PythonService.exe and Windows Server 2003 Mark: I appreciate the resposne, I have the exact text of the error message in case this helps anyone else out in the future: pywintypes.error:(1783,'RegisterEventSource/ReportEvent','The stub recieved bad data') Mark On 2/5/06, Mark Hammond wrote: > From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org]On Behalf Of mark mclarnon > I didnt record the error code that was associated with the message but was > wondering, has anyone had problems with PythonService.exe and Windows 2003 > Server? I'm afraid I haven't heard anything similar - but I have personally had no problems with services on Windows Server 2003. Sorry I can't be more help... Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060207/15edffae/attachment.htm From dan.glassman at charter.net Mon Feb 6 23:28:50 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Mon, 06 Feb 2006 16:28:50 -0600 Subject: [python-win32] Explicit variant types for Invoke & InvokeTypes (Was Re: Autocad.*) In-Reply-To: References: Message-ID: <43E7CDA2.20107@charter.net> Mark Hammond wrote: > Your changes look reasonable for the job they are designed to do, but > doesn't provide a general solution I can try to adopt (which is fine!). Yeah -- I didn't mean that as a patch for general distribution. 'Suggested workaround' would've been better in the old subject line. > Another alternative would be for pywin32 to grow a way to easily indicate > exact types to be passed in Variant calls. > > For example, your code could say something like: > > v = Variant(VT_DOUBLE, (1.0, 2.0, 3.0)) > ms.AddPoint(v) > > This needn't be that hard. The "Variant" object could be a class defined in > a .py file. The IDispatch::Invoke method would grow support for detecting > this object and forming the correct Variant. The only query would be how > InvokeTypes should handle such an object - ignoring the explicitly passed > typeinfo seems wrong (but does seem practical!) I have this working for what *I* need in AutoCAD (yay for me), but I'm not sure about the general case that you describe (not fair for you.) I must admit I don't know how to fully test my implementation. I also have at least one bug related to strings, which the test below will demonstrate. I am soliciting any help I can get to solve the general case. Or, failing that, I'm wondering if a less-general patch would be accepted (that patch is described at the end of this sorry-so-long-again-message.) Here is an annotated interactive session using my current implementation: [code] >>> class Variant: pass #Not its final form. :) >>> point = Variant() #This arg is specified as Variant (not byref) >>> point.__VT__ = 5 >>> point.__VAR__ = (1, 1, 0) #some code removed >>> ms.AddPoint(point) #Success! Point was interpreted as VT_ARRAY | VT_R8! >>> numindex = Variant() >>> numindex.__VT__ = 2 #VT_I2 >>> numindex.__VAR__ = 1 >>> strindex = Variant() >>> strindex.__VT__ = 8 #VT_BSTR >>> strindex.__VAR__ = 'LAYERNAME' #some code removed #doc.Layers() accepts one arg; it is specified only as VARIANT in the #TYPEDESC. It can be either an integer index, or a string "map" >>> doc.Layers(1).Name u'layername' >>> doc.Layers('layername').Name u'layername' >>> doc.Layers(numindex).Name u'layername' >>> doc.Layers(strindex).Name TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer object. #Drat. Here's my 'string' bug. [/code] The implementation is in PyCom_VariantFromPyObject() in oleargs.cpp. This code gets called in all cases that use Invoke. And, in the case of InvokeTypes, it gets called if the TYPEDESC calls for VT_VARIANT or VT_VARIANT | VT_BYREF (which covers everything for autocad, and the one other case I found from a quick google for similar issues.) So -- I haven't changed too much what InvokeTypes already allows (i.e. I'm not ignoring any *more* explicitly passed info from a TYPEDESC). :) I added one IF clause to the very top of PyCom_VariantFromPyObject(): [code: forgive any of my newness that shows thru] if ( PyInstance_Check(obj) && PyObject_HasAttrString(obj, "__VT__") && PyObject_HasAttrString(obj, "__VAR__") ) { PyObject* reqdType = PyObject_GetAttrString(obj, "__VT__"); if (!reqdType) return FALSE; VARENUM rawVT = (VARENUM)PyInt_AsLong(reqdType); PyObject* obuse = PyObject_GetAttrString(obj, "__VAR__"); if (!obuse) { Py_XDECREF(reqdType); return FALSE; } BOOL ok = FALSE; if ( PySequence_Check(obuse) ) { V_ARRAY(var) = NULL; // not a valid, existing array. ok = PyCom_SAFEARRAYFromPyObject(obuse, &V_ARRAY(var), rawVT); V_VT(var) = VT_ARRAY | rawVT; } else { PythonOleArgHelper helper; helper.m_reqdType = rawVT; V_VT(var) = rawVT; ok = helper.MakeObjToVariant(obuse, var); } Py_XDECREF(reqdType); Py_XDECREF(obuse); return ok; } //the rest of PyCom_MakeObjToVariant() follows [/code] So in the case of InvokeTypes, this can seem strange. InvokeTypes will instantiate a PythonOleArgHelper. If TYPEDESC calls for VT_VARIANT (byref or not), the ArgHelper delegates to PyCom_VariantFromPyObject(). If PyCom_VariantFromPyObject() detects an instance of class Variant, it will instantiate a *different* ArgHelper (unless the argument is a sequence, in which case it delegates to PyCom_SAFEARRAYFromPyObject()). It doesn't work for strings (at the very least), and I don't know how to test the Invoke case. It will likely take me awhile to figure through the rest of this on my own. In the meantime, this code could be pared down to solve a less general case than Mark describes above: the Variant() class could be used *just* so that a user could build an array of objects typed to their choosing. I think this would still be useful, and it would likely be forward-compatible with a solution for the general case. So...if nobody else has a pressing need for this, or time to help with it, (Mark & other CVS committers) would you accept a less general patch? Thanks all! -Dan Glassman From mhammond at skippinet.com.au Tue Feb 7 00:51:23 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 7 Feb 2006 10:51:23 +1100 Subject: [python-win32] Explicit variant types for Invoke & InvokeTypes (WasRe: Autocad.*) In-Reply-To: <43E7CDA2.20107@charter.net> Message-ID: > I must admit I don't know how to fully test my implementation. I also > have at least one bug related to strings, which the test below will > demonstrate. I am soliciting any help I can get to solve the general > case. Or, failing that, I'm wondering if a less-general patch would be > accepted (that patch is described at the end of this Yeah, such a patch certainly *would* be accepted, once we bash it into shape :) > [code] > >>> class Variant: pass #Not its final form. :) > > >>> point = Variant() #This arg is specified as Variant (not byref) > >>> point.__VT__ = 5 > >>> point.__VAR__ = (1, 1, 0) I think I'd prefer the attributes named differently, but I'm not sure exactly what :). _com_variant_type_ is kinda consistent with the other attributes we support. _com_variant_value_ is probably reasonable too. Users generally won't see the names, assuming we define a sensible constructor. > The implementation is in PyCom_VariantFromPyObject() in oleargs.cpp. > This code gets called in all cases that use Invoke. And, in the case of > InvokeTypes, it gets called if the TYPEDESC calls for VT_VARIANT or > VT_VARIANT | VT_BYREF (which covers everything for autocad, and the one > other case I found from a quick google for similar issues.) Yeah, that sounds quite reasonable. > [code: forgive any of my newness that shows thru] > if ( PyInstance_Check(obj) && PyObject_HasAttrString(obj, "__VT__") && > PyObject_HasAttrString(obj, "__VAR__") ) > { > PyObject* reqdType = PyObject_GetAttrString(obj, "__VT__"); > if (!reqdType) return FALSE; > > VARENUM rawVT = (VARENUM)PyInt_AsLong(reqdType); > > PyObject* obuse = PyObject_GetAttrString(obj, "__VAR__"); As a minor nit, I'd probably avoid the HasAttrString checks above, and just handle the GetAttrString failing. Behind the scenes, HasAttrsString is just going to fetch the attribute and handle any exceptions anyway, so this means we are fetching them twice. > if ( PySequence_Check(obuse) ) > { > V_ARRAY(var) = NULL; // not a valid, existing array. > ok = PyCom_SAFEARRAYFromPyObject(obuse, &V_ARRAY(var), rawVT); > V_VT(var) = VT_ARRAY | rawVT; > } > else > { > PythonOleArgHelper helper; > helper.m_reqdType = rawVT; > V_VT(var) = rawVT; > ok = helper.MakeObjToVariant(obuse, var); The problem may well be your use of PySequence_Check() - that will succeed for a string. You are then likely to end up with a VT_UI8 array. I think you should *always* defer to MakeObjToVariant - that function will check the VT, and if an array is requested it will do the right thing - ie, the variant-type should *always* drive the conversion process in this case, rather than the object value. > So in the case of InvokeTypes, this can seem strange. InvokeTypes will > instantiate a PythonOleArgHelper. If TYPEDESC calls for VT_VARIANT > (byref or not), the ArgHelper delegates to PyCom_VariantFromPyObject(). > If PyCom_VariantFromPyObject() detects an instance of class Variant, > it will instantiate a *different* ArgHelper (unless the argument is a > sequence, in which case it delegates to PyCom_SAFEARRAYFromPyObject()). Yeah, that does seem strange, but is likely to work :) The "arg helper" objects really are just "state" for the conversion - once the variant type is set the helpers aren't used. > It will likely take me awhile to figure through the rest of this on my > own. In the meantime, this code could be pared down to solve a less > general case than Mark describes above: the Variant() class could be > used *just* so that a user could build an array of objects typed to > their choosing. I think this would still be useful, and it would likely > be forward-compatible with a solution for the general case. So...if > nobody else has a pressing need for this, or time to help with it, (Mark > & other CVS committers) would you accept a less general patch? Yep, I think this is looking quite reasonable. Regarding testing, the best thing is probably to try and use win32com\test\testvb.py. If you have VB and the pywin32 sources, you should be able to create the test DLL from the com\TestSources\PyCOMVBTest directory. testvb.py exercises *lots* of different variant types, so somehow arranging (by copy-paste if necessary) for those tests to be called with a new Variant object would be excellent. If you don't have VB, let me know and I will send you a compliled DLL. Cheers, Mark From sumeet_sobti at yahoo.com Tue Feb 7 00:57:18 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Mon, 6 Feb 2006 15:57:18 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: Message-ID: <20060206235718.49725.qmail@web60717.mail.yahoo.com> --- Mark Hammond wrote: > > > > Does the error above show with some certainty that > > it's a problem with the COM object? > > Sadly it doesn't demonstrate much with any > certainty! Humm... Is there a way to debug the python side more carefully? E.g., using a lower-level interface in the pythoncom module or something? > > > I looked at the other COM objects in the API > package > > that this particular COM object belongs to. A few > > other objects have a similar method that is > documented > > to accept a String and a Variant argument. They > work > > fine. > > > > Their definitions in the makepy generated file > look > > like this: > > > > def Set(self, vKey=defaultNamedNotOptArg, > > newVal=defaultNamedNotOptArg): > > """method Set""" > > return self._oleobj_.InvokeTypes(4, LCID, 1, > (24, > > 0), ((12, 1), (12, 1)),vKey, newVal) > > > > And these methods seem to work just fine. Is this > > sufficient evidence to say that the AddTest method > is > > incorrectly implemented? > > That is strange - any of their methods correct use a > string, but AddTest > appears to spell it in a different way. Did you mean to say that the other methods are specifying/processing their arguments in the correct way? The AddTest does surely seem to be implemented in a different way. > Is it > possible for you to contact > the authors of this object? Yes, I sent them my 3-line failing Python program, and they just sent me back a C# code fragment, which, they claim, works correctly. But I need to make it work in Python since the rest of my code is in Python. I haven't tried executing the C# code, but if that works, then that points to a potential bug in pywin-32. Is there a documented way to debug the Python side? Thanks! -Sumeet. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From sumeet_sobti at yahoo.com Tue Feb 7 01:39:57 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Mon, 6 Feb 2006 16:39:57 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: Message-ID: <20060207003958.54452.qmail@web60714.mail.yahoo.com> I tried the "late-bound" mode (by deleting all the generated files in the gen_py directory). It still gives me the same TypeError. >>> obj.AddTest('IsBuy', True) Traceback (most recent call last): File "", line 1, in ? File "", line 2, in AddTest TypeError: The VARIANT type is unknown (0000001e) Thanks! (PS: Being new to the mailing-list, I am not sure if it's proper to cc the list on follow-up questions and discussion like this. Let me know if it isn't.) --- Mark Hammond wrote: > > Does the error above show with some certainty that > > it's a problem with the COM object? > > Sadly it doesn't demonstrate much with any > certainty! > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mhammond at skippinet.com.au Tue Feb 7 02:28:50 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 7 Feb 2006 12:28:50 +1100 Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: <20060206235718.49725.qmail@web60717.mail.yahoo.com> Message-ID: > > > > > > Does the error above show with some certainty that > > > it's a problem with the COM object? > > > > Sadly it doesn't demonstrate much with any > > certainty! > > Humm... Is there a way to debug the python side more > carefully? E.g., using a lower-level interface in the > pythoncom module or something? At this stage the problem is more confusion as to exactly what is happening. My understanding is: * Their type-library defines that method as having a variant type of VT_LPSTR. * Microsoft declares in wtypes.h that VT_LPSTR is valid in a typedesc, but *not* in a VARIANT. * When Python processes the typelib, it makes no attempt to translate VT_LPSTR to a type that is valid in a Variant. * When Python is making the call to the COM object, it sees that VT_LPSTR - but as it is filling a VARIANT, it gives that error (the error could be clearer - but that is the underlying reason for that type not being supported) The last experiment I asked you to perform should have translated the VT_LPSTR from the typelib into a VT_BSTR - the "standard" string type - but that still failed. You may also like to change the 30 to 12 (VT_VARIANT) and see if that helps. But ultimately, I need to know exactly what variant type the COM object is expecting, and why it fails if a VT_BSTR variant is supplied. There is no general mechanism for debugging this variant conversion process, but that code is fairly stable, so I'm confident that Python is providing a variant that matches the "type tuple" presented to InvokeTypes. In this example it is the COM object itself that is raising the exception. Assuming that modified tuple was passed to InvokeTypes, I'm confident that a correct VT_BSTR was passed. Cheers, Mark From tea2 at cornell.edu Tue Feb 7 04:12:12 2006 From: tea2 at cornell.edu (Terry Acree) Date: Mon, 6 Feb 2006 22:12:12 -0500 Subject: [python-win32] win32ui can't be found .. some places. Message-ID: <86479B42-DB07-4222-A2A5-7EAE76E433C1@cornell.edu> I have been struggling for some time with a strange failure of py2exe. When I include the dde.py module in a freeze with py2exe and copy the dist folder to another computer (w/o python) On some computers it works and others it doesn't (all are recent XP installs) I get this message: Traceback (most recent call last): File "CharmAnalysis05.py", line 24, in ? File "ddeclient.pyc", line 6, in ? File "pywin\mfc\object.pyc", line 3, in ? File "win32ui.pyc", line 9, in ? File "win32ui.pyc", line 7, in __load ImportError: DLL load failed: The specified module could not be found. Removing win32ui.pyc from the dist folder will produce the error on systems where it things work. It is as though it can see the DLL on some installs and not others. I'm stumped! Writing scripts that print the path, prefix etc. to a file shows that the code in win32ui.py can determine paths correctly. Terry Acree From mhammond at skippinet.com.au Tue Feb 7 06:43:36 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 7 Feb 2006 16:43:36 +1100 Subject: [python-win32] win32ui can't be found .. some places. In-Reply-To: <86479B42-DB07-4222-A2A5-7EAE76E433C1@cornell.edu> Message-ID: > Traceback (most recent call last): > File "CharmAnalysis05.py", line 24, in ? > File "ddeclient.pyc", line 6, in ? > File "pywin\mfc\object.pyc", line 3, in ? > File "win32ui.pyc", line 9, in ? > File "win32ui.pyc", line 7, in __load > ImportError: DLL load failed: The specified module could not be found. > > Removing win32ui.pyc from the dist folder will produce the error on > systems where it things work. > It is as though it can see the DLL on some installs and not others. The problem will be a missing mfcxx.dll (where xx depends on the version of Python you are using). You will probably need to redistribute that DLL (which probably means you need an MSVC license...) Mark From rbell01824 at earthlink.net Tue Feb 7 18:02:08 2006 From: rbell01824 at earthlink.net (Richard Bell) Date: Tue, 7 Feb 2006 12:02:08 -0500 Subject: [python-win32] Is it possible to pump messages in thread? Message-ID: <001301c62c08$3afcbbc0$6701a8c0@homeoffice.benchmarkinternational.com> When interfacing to a COM object, is it possible to pump messages in a thread? I'm working on an application that automates IE and needs to monitor IE events (yes I know about Pamie). I'm starting IE as follows: ie = win32com.client.DispatchWithEvents( object, YamieEvents ) ie.event = win32event.CreateEvent(None,0,0,None) The class YamieEvents catches a number of events and outputs trace messages whenever an event occurs. It looks like this: class YamieEvents: def OnBeforeNavigate2(self, pDisp=defaultNamedNotOptArg, url=defaultNamedNotOptArg, Flags=defaultNamedNotOptArg, TargetFrameName=defaultNamedNotOptArg, PostData=defaultNamedNotOptArg, Headers=defaultNamedNotOptArg, Cancel=defaultNamedNotOptArg): out = 'OnBeforeNavigate2 URL [%s] \n' % url out += ' Flags [%s] \n' %`Flags` out += ' TargetFrameName [%s]' % TargetFrameName print out; # many more On event routines I'm able to navigate and wait as follows seeing the event trace: ie.Navigate(url) try: ie.Navigate(url) WaitMsg() except pythoncom.com_error, details: PrintFlush( "Warning - could not open %s"%url, details ) Where WaitMsg() looks like this: def WaitMsg(timeout=30, donetime=2000): # timeout in seconds, dontime in milliseconds! timeStart = time.time() timeTic = timeStart while True: rc = win32event.MsgWaitForMultipleObjects( (ie.event,), 0, donetime, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: pass elif rc == win32event.WAIT_OBJECT_0+1: pythoncom.PumpWaitingMessages() elif rc == win32event.WAIT_TIMEOUT: PrintFlush( ' WaitMsg: got donetime' ) return True else: PrintFlush( 'Unrecognized event' ) timeNow = time.time() if timeNow - timeStart > timeout: PrintFlush( ' ##### got timeout' ) return False if timeNow - timeTic > 1: PrintFlush( '.', ) timeTic = timeNow So far everything seems to work fine. However, I've encountered a difficulty when dealing with web pages that have script that causes events AFTER the navigation is complete! Since the message pump is not being run, these events are not processed and IE appears to be hung (the script's page changes, navigations, etc. do no occur). I'm trying to work out how to run the message pump on a thread so that messages are continually pumped and these script modified pages are properly handled. Modeling a solution after Mark Hammond's Appendix D threads example I'm creating the message pump thread as follows: ie = win32com.client.DispatchWithEvents( \ "InternetExplorer.Application", \ YamieEvents) ie.event = win32event.CreateEvent(None,0,0,None) ie.Visible = 1 WaitMsg() # now IE is up and google is displayed # there is good reason to think IE # is good and truly ready to be used #pass our ie com object to a thread to run the message loop # marshal the object object_stream = pythoncom.CoMarshalInterThreadInterfaceInStream( \ pythoncom.IID_IDispatch, ie ) args = (object_stream,) handle, id = win32process.beginthreadex( None, 0, PumpMessages, args, 0 ) The thread function looks like this: def PumpMessages(object_stream): pythoncom.CoInitialize() # initialize com for single thread # unmarshal the DispatchWithEvents object object = pythoncom.CoGetInterfaceAndReleaseStream( \ object_stream, pythoncom.IID_IDispatch) # convert to a useable DispatchWithEvents object ie = win32com.client.DispatchWithEvents( object, YamieEvents ) # without this line, MsgWaitForMultipleObjects # reports no attribute event!? ie.event2 = win32event.CreateEvent(None,0,0,None) # now we should be in a position wait for events and pump messages timeStart = time.time() while True: rc = win32event.MsgWaitForMultipleObjects( (ie.event2,), 0, 1000, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: PrintFlush( ' thread: event' ) elif rc == win32event.WAIT_OBJECT_0+1: PrintFlush( ' thread: pump' ) pythoncom.PumpWaitingMessages() elif rc == win32event.WAIT_TIMEOUT: PrintFlush( ' thread: tic' ) else: PrintFlush( ' thread: unrecognized event' ) if time.time() - timeStart > 40: PrintFlush( ' thread: got timeout' ) break # be a good citizen and cleanup self ie = None pythoncom.CoUninitialize() I've a question about this code since it was necessary to create a second event for the ie object even though the original object and it's event should (I believe) be available. Am I doing something wrong here? Second when I test this code I see that the thread runs ( trace messages thread: tic occur). But events are not being pumped since none of the event messages occur. Eventually the thread times out. Any clues as to what I'm missing? I appreciate that this is a lengthy post. I've tried to show only the critical sections of code but the issue is complex. Thanks for any help. From sumeet_sobti at yahoo.com Tue Feb 7 19:49:02 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Tue, 7 Feb 2006 10:49:02 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: Message-ID: <20060207184902.60176.qmail@web60713.mail.yahoo.com> --- Mark Hammond wrote: > At this stage the problem is more confusion as to > exactly what is happening. > My understanding is: > > * Their type-library defines that method as having a > variant type of > VT_LPSTR. > * Microsoft declares in wtypes.h that VT_LPSTR is > valid in a typedesc, but > *not* in a VARIANT. > * When Python processes the typelib, it makes no > attempt to translate > VT_LPSTR to a type that is valid in a Variant. > * When Python is making the call to the COM object, > it sees that VT_LPSTR - > but as it is filling a VARIANT, it gives that error > (the error could be > clearer - but that is the underlying reason for that > type not being > supported) Yup. The analysis above seems correct given the information we have. > > The last experiment I asked you to perform should > have translated the > VT_LPSTR from the typelib into a VT_BSTR - the > "standard" string type - but > that still failed. You may also like to change the > 30 to 12 (VT_VARIANT) > and see if that helps. But ultimately, I need to > know exactly what variant > type the COM object is expecting, and why it fails > if a VT_BSTR variant is > supplied. I tried changing 30 to 12. Didn't work. The com object gave "Bad argument type" error as with 8. It seems like a problem with the COM object. I am going to ask the object authors about the exact type the object expects as argument. That will hopefully shed some light on what's happening. Thanks! -Sumeet. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mhammond at skippinet.com.au Tue Feb 7 20:29:36 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 8 Feb 2006 06:29:36 +1100 Subject: [python-win32] Is it possible to pump messages in thread? In-Reply-To: <001301c62c08$3afcbbc0$6701a8c0@homeoffice.benchmarkinternational.com> Message-ID: > > I've a question about this code since it was necessary to create a second > event for the ie object even though the original object and it's event > should (I believe) be available. Am I doing something wrong here? By setting ie.event, you are adding a new attibute to the IDispatch wrapper provided by Python. When you marshall it to another thread, you get a new IDispatch object, as the marshal process provided a new pointer. There is no magic that associates multiple instances like that. Try just passing the event as a normal param. > Second when I test this code I see that the thread runs ( trace messages > thread: tic occur). But events are not being pumped since none > of the event > messages occur. Eventually the thread times out. By running a message pump in the thread (*and* the main thread), I expect to see all events always be delivered to the *main* thread, regardless of what thread you use it from. The reason is that IE itself is not fully free-threaded, so events etc will be delivered to the IE "main thread", not to the thread it is being currently used from - that is the point of the marshalling calls you made - to give COM the chance to marshall back to the correct thread. Mark From rbell01824 at earthlink.net Tue Feb 7 23:03:18 2006 From: rbell01824 at earthlink.net (Richard Bell) Date: Tue, 7 Feb 2006 17:03:18 -0500 Subject: [python-win32] Is it possible to pump messages in thread? In-Reply-To: Message-ID: <001e01c62c32$4d90f3d0$6701a8c0@homeoffice.benchmarkinternational.com> Thanks, that clears things up a bit (I'm new to com and my understanding is rather tenuous) and I think I understand why this does not work. The net of what I think you are saying is that as a practical matter message running the message pump in a thread has little effect since the messages proper (and events) will be delivered to the main thread. Would that it were otherwise. Unfortunately, as a general rule for my purposes it is not practicable to have the main thread spin the message loop. The underlying reason is that the application generally has no pre-knowledge of the nature of the web pages and the pages script. Absent such knowledge, the application does not know if the message loop needs to be spun from time to time. I'm a bit unclear on this comment: |The reason is that IE itself is not fully |free-threaded, so events etc will be delivered to the IE "main thread", not |to the thread it is being currently used from Isn't IE running in a separate process? If that is true aren't IE's events delivered back to my application via COM so that my threading model would be largely independent from whatever IE is doing (contingent on whatever python-com does)? On the assumption that this might be true, I modified my application per the example in appendix D by: --- begin python code --- import sys sys.coinit_flags=0 # specify free threading import pythoncom --- end python code --- A bit of experimentation suggests that it is not now necessary to run the message pump at all. Interestingly, when I modify the event debug print I find that events are being processed on one of two threads neither of which is my main thread. I'm a bit unclear as to why this is so but it is. I assume that somewhere within pythoncom messages are being pumped. >From the point of view of my test application, all appears well but since I don't really understand what is happening (within pythoncom I guess) or what your remark concerning IE free-thread really means I'm a bit concerned. Can you provide any insight concerning pythoncom's role in this matter particularly relative to DispatchWithEvents and messages in a free-thread apartment? By way of thanks for your help I'll gladly contribute my test application to the test suite. I evolved it off of TestExplorer.py which works but is somewhat misleading concerning event handling (OnVisible is one of the very few events that can be caught in the fashion used by the current test). Perhaps others would find some benefit as I now have modified tests for both an active PumpWaitingMessages off of an event and a free-thread version (appears to work but I clearly do not really understand why). Regards |-----Original Message----- |From: Mark Hammond [mailto:mhammond at skippinet.com.au] |Sent: Tuesday, February 07, 2006 2:30 PM |To: Richard Bell; python-win32 at python.org |Subject: RE: [python-win32] Is it possible to pump messages in thread? | |> |> I've a question about this code since it was necessary to create a second |> event for the ie object even though the original object and it's event |> should (I believe) be available. Am I doing something wrong here? | |By setting ie.event, you are adding a new attibute to the IDispatch wrapper |provided by Python. When you marshall it to another thread, you get a new |IDispatch object, as the marshal process provided a new pointer. There is |no magic that associates multiple instances like that. | |Try just passing the event as a normal param. | |> Second when I test this code I see that the thread runs ( trace messages |> thread: tic occur). But events are not being pumped since none |> of the event |> messages occur. Eventually the thread times out. | |By running a message pump in the thread (*and* the main thread), I expect |to |see all events always be delivered to the *main* thread, regardless of what |thread you use it from. The reason is that IE itself is not fully |free-threaded, so events etc will be delivered to the IE "main thread", not |to the thread it is being currently used from - that is the point of the |marshalling calls you made - to give COM the chance to marshall back to the |correct thread. | |Mark From mhammond at skippinet.com.au Wed Feb 8 00:22:38 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 8 Feb 2006 10:22:38 +1100 Subject: [python-win32] Is it possible to pump messages in thread? In-Reply-To: <001e01c62c32$4d90f3d0$6701a8c0@homeoffice.benchmarkinternational.com> Message-ID: > Thanks, that clears things up a bit (I'm new to com and my > understanding is > rather tenuous) and I think I understand why this does not work. > The net of > what I think you are saying is that as a practical matter message running > the message pump in a thread has little effect since the messages proper > (and events) will be delivered to the main thread. Actually, the pump in the other thread is likely to be necessary so that the marshalling between threads can occur correctly. The upshot is that you probably can not get the events to fire on the other thread, when the object was not created in the free-threaded apartment. > Unfortunately, as a general rule for my purposes it is not practicable to > have the main thread spin the message loop. The underlying reason is that > the application generally has no pre-knowledge of the nature of the web > pages and the pages script. Absent such knowledge, the > application does not > know if the message loop needs to be spun from time to time. Its not the "main" thread as we usually think of it. The issue is the "COM Object's thread". It should be fine to spin a new thread, create the object on that thread. It might not be necessary to run a message loop on that thread, as no marshalling is required in that case (ie, all operations happen on the object's "main" thread) > I'm a bit unclear on this comment: > > |The reason is that IE itself is not fully > |free-threaded, so events etc will be delivered to the IE "main > thread", not > |to the thread it is being currently used from > > Isn't IE running in a separate process? If that is true aren't > IE's events > delivered back to my application via COM so that my threading > model would be > largely independent from whatever IE is doing (contingent on whatever > python-com does)? Right - yes, that is correct. The cross-process marshalling COM uses will take care of these threading issues, so the object is not restricted in the same way it would be in-process. > On the assumption that this might be true, I > modified my > application per the example in appendix D by: > > --- begin python code --- > import sys > sys.coinit_flags=0 # specify free threading > import pythoncom > --- end python code --- > > A bit of experimentation suggests that it is not now necessary to run the > message pump at all. Interestingly, when I modify the event debug print I > find that events are being processed on one of two threads > neither of which > is my main thread. I'm a bit unclear as to why this is so but it is. I > assume that somewhere within pythoncom messages are being pumped. You have created a "free threaded" COM object - which as above, works fine as the object is in another process (and the cross-process marshaller will take care of what happens in that other process). As a result, *no* thread marshalling happens in the Python process, and you can freely pass pointers unmarshalled between free-threaded threads. The message loop is only needed for this marshalling to work - but as there is none, no message loop is necessary. > From the point of view of my test application, all appears well > but since I > don't really understand what is happening (within pythoncom I > guess) or what > your remark concerning IE free-thread really means I'm a bit > concerned. Can > you provide any insight concerning pythoncom's role in this matter > particularly relative to DispatchWithEvents and messages in a free-thread > apartment? Yes, thanks for pointing out my error - I hope the above explains things more satisfactorily. > By way of thanks for your help I'll gladly contribute my test > application to > the test suite. I evolved it off of TestExplorer.py which works but is > somewhat misleading concerning event handling (OnVisible is one > of the very > few events that can be caught in the fashion used by the current test). > Perhaps others would find some benefit as I now have modified > tests for both > an active PumpWaitingMessages off of an event and a free-thread version > (appears to work but I clearly do not really understand why). That would be great! Mark From sumeet_sobti at yahoo.com Wed Feb 8 01:37:35 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Tue, 7 Feb 2006 16:37:35 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a method of aCOM object In-Reply-To: Message-ID: <20060208003735.78644.qmail@web60713.mail.yahoo.com> Hi, The authors of the COM object say that the failing AddTest() method takes in an LPCSTR as its first argument and a Variant as the second argument. STDMETHODIMP CTTOrderSelector::AddTest(LPCSTR lpProperty, VARIANT vValue) LPCSTR is not a valid COM type, but somehow it is correctly handled in C#. The authors claim that their C# client code has been tested and is known to work correctly. Is there a hack that I can use through pywin to make this work? Maybe call Invoke() for AddTest manually or something? Thanks! -Sumeet. --- Mark Hammond wrote: > At this stage the problem is more confusion as to > exactly what is happening. > My understanding is: > > * Their type-library defines that method as having a > variant type of > VT_LPSTR. > * Microsoft declares in wtypes.h that VT_LPSTR is > valid in a typedesc, but > *not* in a VARIANT. > * When Python processes the typelib, it makes no > attempt to translate > VT_LPSTR to a type that is valid in a Variant. > * When Python is making the call to the COM object, > it sees that VT_LPSTR - > but as it is filling a VARIANT, it gives that error > (the error could be > clearer - but that is the underlying reason for that > type not being > supported) > > The last experiment I asked you to perform should > have translated the > VT_LPSTR from the typelib into a VT_BSTR - the > "standard" string type - but > that still failed. You may also like to change the > 30 to 12 (VT_VARIANT) > and see if that helps. But ultimately, I need to > know exactly what variant > type the COM object is expecting, and why it fails > if a VT_BSTR variant is > supplied. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mhammond at skippinet.com.au Wed Feb 8 01:55:32 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 8 Feb 2006 11:55:32 +1100 Subject: [python-win32] Problem passing a VARIANT argument to a methodof aCOM object In-Reply-To: <20060208003735.78644.qmail@web60713.mail.yahoo.com> Message-ID: > STDMETHODIMP CTTOrderSelector::AddTest(LPCSTR > lpProperty, VARIANT vValue) > > LPCSTR is not a valid COM type, but somehow it is > correctly handled in C#. The authors claim that their > C# client code has been tested and is known to work > correctly. I assume that the C# implementation is using the vtable interfaces and making the call directly - ie, *not* going via IDispatch. Can they show an early-bound VB example that works, or anything else that will go via IDispatch? There aren't any hacks I can think of - maybe ctypes could work. Mark. From rbell01824 at earthlink.net Wed Feb 8 00:54:01 2006 From: rbell01824 at earthlink.net (Richard Bell) Date: Tue, 7 Feb 2006 18:54:01 -0500 Subject: [python-win32] Is it possible to pump messages in thread? In-Reply-To: Message-ID: <002801c62c41$c557cd80$6701a8c0@homeoffice.benchmarkinternational.com> Mark, Thanks very much for your assistance. Based on my rather limited experience and understanding of com I'm still a bit uncertain but if I understand your comments correctly what I've done in the free-threaded test is sound and should work reliably. This is a serious concern for me as the application must run 24x365 if it is to replace the current version (the current version has had only 3 unscheduled outages in 18 months ... 2 cable cuts and 1 router fire). As to the test applications, I'll send along three to you at the mailto address below unless you prefer I post them to the mailing list. The first will have a very simple PumpWaitingMessages loop and a flag for the DocumentComplete event modeled after the existing Visible flag. It's relatively easy to understand and provides a more realistic example than the current Visible test. I'll have a bit of time tomorrow AM and will clean up the current version and send it along. The second uses MsgWaitForMultipleEvents (something you've mentioned in several of your correspondences but which I was unable to find in an example). It is useful principally as an example of how to use the MsgWait to avoid polling. The third is the free-thread routine with no message pump. I should have time between now and next week to clean these other two up and send them along. I'll model all three after the existing test routines (I assume they are run as part of builds) so hopefully they can be used with minimal effort on your part. After you've had a chance to look at them feel free to let me know of any changes that would make them more suitable for your purposes. Regards, Richard |-----Original Message----- |From: Mark Hammond [mailto:mhammond at skippinet.com.au] |Sent: Tuesday, February 07, 2006 6:23 PM |To: Richard Bell; python-win32 at python.org |Subject: RE: [python-win32] Is it possible to pump messages in thread? | |> Thanks, that clears things up a bit (I'm new to com and my |> understanding is |> rather tenuous) and I think I understand why this does not work. |> The net of |> what I think you are saying is that as a practical matter message running |> the message pump in a thread has little effect since the messages proper |> (and events) will be delivered to the main thread. | |Actually, the pump in the other thread is likely to be necessary so that |the |marshalling between threads can occur correctly. The upshot is that you |probably can not get the events to fire on the other thread, when the |object |was not created in the free-threaded apartment. | |> Unfortunately, as a general rule for my purposes it is not practicable to |> have the main thread spin the message loop. The underlying reason is |that |> the application generally has no pre-knowledge of the nature of the web |> pages and the pages script. Absent such knowledge, the |> application does not |> know if the message loop needs to be spun from time to time. | |Its not the "main" thread as we usually think of it. The issue is the "COM |Object's thread". It should be fine to spin a new thread, create the |object |on that thread. It might not be necessary to run a message loop on that |thread, as no marshalling is required in that case (ie, all operations |happen on the object's "main" thread) | |> I'm a bit unclear on this comment: |> |> |The reason is that IE itself is not fully |> |free-threaded, so events etc will be delivered to the IE "main |> thread", not |> |to the thread it is being currently used from |> |> Isn't IE running in a separate process? If that is true aren't |> IE's events |> delivered back to my application via COM so that my threading |> model would be |> largely independent from whatever IE is doing (contingent on whatever |> python-com does)? | |Right - yes, that is correct. The cross-process marshalling COM uses will |take care of these threading issues, so the object is not restricted in the |same way it would be in-process. | |> On the assumption that this might be true, I |> modified my |> application per the example in appendix D by: |> |> --- begin python code --- |> import sys |> sys.coinit_flags=0 # specify free threading |> import pythoncom |> --- end python code --- |> |> A bit of experimentation suggests that it is not now necessary to run the |> message pump at all. Interestingly, when I modify the event debug print |I |> find that events are being processed on one of two threads |> neither of which |> is my main thread. I'm a bit unclear as to why this is so but it is. I |> assume that somewhere within pythoncom messages are being pumped. | |You have created a "free threaded" COM object - which as above, works fine |as the object is in another process (and the cross-process marshaller will |take care of what happens in that other process). | |As a result, *no* thread marshalling happens in the Python process, and you |can freely pass pointers unmarshalled between free-threaded threads. The |message loop is only needed for this marshalling to work - but as there is |none, no message loop is necessary. | |> From the point of view of my test application, all appears well |> but since I |> don't really understand what is happening (within pythoncom I |> guess) or what |> your remark concerning IE free-thread really means I'm a bit |> concerned. Can |> you provide any insight concerning pythoncom's role in this matter |> particularly relative to DispatchWithEvents and messages in a free-thread |> apartment? | |Yes, thanks for pointing out my error - I hope the above explains things |more satisfactorily. | |> By way of thanks for your help I'll gladly contribute my test |> application to |> the test suite. I evolved it off of TestExplorer.py which works but is |> somewhat misleading concerning event handling (OnVisible is one |> of the very |> few events that can be caught in the fashion used by the current test). |> Perhaps others would find some benefit as I now have modified |> tests for both |> an active PumpWaitingMessages off of an event and a free-thread version |> (appears to work but I clearly do not really understand why). | |That would be great! | |Mark From George.Flaherty at sas.com Wed Feb 8 17:04:12 2006 From: George.Flaherty at sas.com (George Flaherty) Date: Wed, 8 Feb 2006 11:04:12 -0500 Subject: [python-win32] Unable to close Excel, error in dynamic.py Message-ID: <59CF9F456FAA9045B405C441EC916F3E03E8978B@MERC24.na.sas.com> I have been messing around Excel, but when I run the following example I get an error? Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from win32com.client import Dispatch >>> xlApp = Dispatch("Excel.Application") >>> xlApp.Visible = 1 >>> xlApp.Workbooks.Add() >>> xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!' >>> xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!' >>> xlApp.Close(SaveChanges=0) Traceback (most recent call last): File "", line 1, in ? File "C:\usr\python\Lib\site-packages\win32com\client\dynamic.py", line 489, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: Excel.Application.Close In genaral the excel application does not close. I am pretty sure this has worked in the past, but I can't verify the python version and pywin version? Right now I am using py 2.4.2 and pywin build 205. Thanks -george From rbell01824 at earthlink.net Wed Feb 8 17:24:52 2006 From: rbell01824 at earthlink.net (Richard Bell) Date: Wed, 8 Feb 2006 11:24:52 -0500 Subject: [python-win32] Is it possible to pump messages in thread? Message-ID: <000f01c62ccc$30ca1b60$6701a8c0@homeoffice.benchmarkinternational.com> Mark, I did some reading overnight and thought this through a bit more and on further consideration am concerned that the free-threaded example has a serious design flaw as follows: When I code --- begin python code --- import sys sys.coinit_flags=0 # specify free threading import pythoncom --- end python code --- I understand that pythoncom connects to com on my behalf with a free-thread (MTA) model. If I understand correctly this means two relevant things. First, I'm asserting to pythoncom and to com that I will invoke methods on any of my com objects from threads of my choice. And second, this is the area of concern, that COM may call any event routines I provide on threads of its choice without regard to serialization. I know from testing the free-thread model that in fact the IE event routines are called on threads other than the test's main thread and that more than one thread is used to invoke the event routines (in my testing two threads). In testing so far, I've found no issues with the free-thread test case but I'm concerned that this is just an accident of good fortune since there is nothing in the design that prevents the IE event routines from being called concurrently on two different threads (absent some intervention by pythoncom to serialize the event routine calls). So long as the IE event routines do not reference any shared application data then this is not an issue. However, if the IE event routines DO reference shared application data (as they do in my real application) then it is incumbent on the event routines to insure that those references are thread safe (serialize with a lock or mutex of some sort). Is this a correct analysis? Aren't the IE event routines in a free-thread environment responsible for being thread safe? Assuming that my concerns are real, it seems to me that I can proceed on one of two courses. I can make the IE event routines thread save by serializing access to application data where appropriate or I can revisit the STA model. In thinking about this a bit more I wondered if the following STA approach would work. Create a worker thread ThreadIE. In ThreadIE pythoncomIEObject = DispatchWithEvents( ... ) so now events are serialized on ThreadIE and we are assured that we are only processing one at a time per worker thread. ThreadIE will also need to marshal pythoncomIEObject back to the main thread so that IE methods can be accessed there. Finally, ThreadIE can pump messages. Now the IE event routines running on ThreadIE still need to be thread safe relative to the main thread but at least we're only dealing with a single event at a time. As a practical matter the design of my application is such that this may be relatively easy to accomplish. Any thoughts? I'll get the first of the STA test out to you a bit later today. Richard |-----Original Message----- |From: Richard Bell [mailto:rbell01824 at earthlink.net] |Sent: Tuesday, February 07, 2006 6:54 PM |To: 'Mark Hammond'; 'python-win32 at python.org' |Subject: RE: [python-win32] Is it possible to pump messages in thread? | |Mark, | |Thanks very much for your assistance. Based on my rather limited |experience and understanding of com I'm still a bit uncertain but if I |understand your comments correctly what I've done in the free-threaded test |is sound and should work reliably. This is a serious concern for me as the |application must run 24x365 if it is to replace the current version (the |current version has had only 3 unscheduled outages in 18 months ... 2 cable |cuts and 1 router fire). | |As to the test applications, I'll send along three to you at the mailto |address below unless you prefer I post them to the mailing list. The first |will have a very simple PumpWaitingMessages loop and a flag for the |DocumentComplete event modeled after the existing Visible flag. It's |relatively easy to understand and provides a more realistic example than |the current Visible test. I'll have a bit of time tomorrow AM and will |clean up the current version and send it along. The second uses |MsgWaitForMultipleEvents (something you've mentioned in several of your |correspondences but which I was unable to find in an example). It is |useful principally as an example of how to use the MsgWait to avoid |polling. The third is the free-thread routine with no message pump. I |should have time between now and next week to clean these other two up and |send them along. I'll model all three after the existing test routines (I |assume they are run as part of builds) so hopefully they can be used with |minimal effort on your part. After you've had a chance to look at them |feel free to let me know of any changes that would make them more suitable |for your purposes. | From dan.glassman at charter.net Wed Feb 8 17:36:34 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Wed, 08 Feb 2006 10:36:34 -0600 Subject: [python-win32] Unable to close Excel, error in dynamic.py In-Reply-To: <59CF9F456FAA9045B405C441EC916F3E03E8978B@MERC24.na.sas.com> References: <59CF9F456FAA9045B405C441EC916F3E03E8978B@MERC24.na.sas.com> Message-ID: <43EA1E12.2000903@charter.net> George Flaherty wrote: > I have been messing around Excel, but when I run the following example I get an error? > > Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from win32com.client import Dispatch >>>> xlApp = Dispatch("Excel.Application") >>>> xlApp.Visible = 1 >>>> xlApp.Workbooks.Add() > >>>> xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!' >>>> xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!' >>> xlApp.ActiveWorkbook.Close(SaveChanges=0) >>> xlApp.Quit() Workbooks have the Close method. From greg.landrum at gmail.com Wed Feb 8 17:44:16 2006 From: greg.landrum at gmail.com (Greg Landrum) Date: Wed, 8 Feb 2006 08:44:16 -0800 Subject: [python-win32] Bringing a window to the front. Message-ID: <60825b0f0602080844t782d8493td76bc6d9299ef2fb@mail.gmail.com> Hi all, >From my python program I'm working with a 3rd party application using the win32 extensions and COM. I'd like to be able to pop that application to the front (i.e. to ensure that it's visible and unobscured by other windows). Is there some way to do this? Thanks, -greg From tim.golden at viacom-outdoor.co.uk Wed Feb 8 18:03:16 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 8 Feb 2006 17:03:16 -0000 Subject: [python-win32] Bringing a window to the front. Message-ID: <9A28C052FF32734DACB0A288A3533991044D252E@vogbs009.gb.vo.local> [Greg Landrum] | >From my python program I'm working with a 3rd party application using | the win32 extensions and COM. I'd like to be able to pop that | application to the front (i.e. to ensure that it's visible and | unobscured by other windows). | | Is there some way to do this? Have a look at win32gui.BringWindowToTop TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From greg.landrum at gmail.com Wed Feb 8 18:32:59 2006 From: greg.landrum at gmail.com (Greg Landrum) Date: Wed, 8 Feb 2006 09:32:59 -0800 Subject: [python-win32] Bringing a window to the front. In-Reply-To: <60825b0f0602080844t782d8493td76bc6d9299ef2fb@mail.gmail.com> References: <60825b0f0602080844t782d8493td76bc6d9299ef2fb@mail.gmail.com> Message-ID: <60825b0f0602080932u2784387ene476b74b93818915@mail.gmail.com> Mark Mc Mahon sent me personal email with the answer that I ought to be using SetForegroundWindow. For this I needed a window handle, and for that I think I needed a window name. Since I can't be sure of the full window name (it changes based on the active document), I wrote the following function that uses a regexp to match the names of all active windows: #------------------------------------------------------------ def RaiseWindowNamed(nameRe): import win32gui # start by getting a list of all the windows: cb = lambda x,y: y.append(x) wins = [] win32gui.EnumWindows(cb,wins) # now check to see if any match our regexp: tgtWin = -1 for win in wins: txt = win32gui.GetWindowText(win) if nameRe.match(txt): tgtWin=win break if tgtWin>=0: win32gui.SetForegroundWindow(tgtWin) #------------------------------------------------------------ This seems to do what I want it to do. Thanks Mark! -greg From Ted.Speers at actel.com Wed Feb 8 20:28:16 2006 From: Ted.Speers at actel.com (Speers, Ted) Date: Wed, 8 Feb 2006 11:28:16 -0800 Subject: [python-win32] More VisualBasic Message-ID: Thanks for everyone's help with my initial volley of questions. I'm sure I'm destined to be a consumer of versus a contributor to this group's output. I'd like to get some advice from the group whether I should pursue the road I'm on ... An appeal to your experience and intuition rather than a specific question. Sorry if it is longwinded ... It's a 4 parter ('Punchline:', 'Some background:', 'Where I am:', 'Continuing on:') ... The punchline is what I'm after from this group, the rest of the stuff may help you/motivate you to form an answer. Punchline: Am I on a fools errand trying to develop an application in Python that manipulates VBUserForms? Are these errors that I'm seeing going to be the bane of my existence due to some inherent flakiness or, through experience/reading/discussiongroups/magic, will I be able to gain enough understanding of how things work so that I can consistently avoid these pitfalls? Some background: I was able to go from knowing nothing about python and win32com to creating a fairly complex application (which entailed parsing data in Excel worksheets into a web of classes and then outputting multiple scenarios back into worksheets) in a matter of a few weeks. I then decided that I wanted my worksheet to be more interactive and dynamic. I investigated various GUI options with Python and nothing seemed straightforward so I bought John Walker's book on Excel programming (BTW, I didn't need a book to accomplish my original Python goal in two weeks). For whatever reason, I was much less productive with Visual Basic ... Getting hammered with type errors and other frustrations. The whole time I was thinking how easy it would be to do what I wanted to do with Python. I ended up writing Visual Basic classes for things such as Lists and use them heavily but I'm sure they drag down the performance of my application which is an issue. It took months to get my application hammered into anything usable though fortunately, it was ready in time for me to use it and I think the work paid off. I now have a lull and know I could recreate my months of effort in a week using Python provided I had stable/predictable hooks to my VisualBasic widgets and then be able to improve and maintain my application much more productively going forward. Where I am: I used the help of this group to be able to read and manipulate my Visual Basic UserForms. However, knowing almost nothing about the man behind the curtain, my experience is that what I'm doing is somehow unstable. For example, at times my program successfully reads and sets a Userform Control property ... But bombs occasionally ... Try to follow this or skip to the punchline: VBComponents=win32com.client.Dispatch("Excel.Application").Workbooks("my Book").VBProject.VBComponents For tmp in VBComponents: VBComponentsDict[tmp.Name]=tmp MyUserForm=VBComponentsDict['MyUserForm'] For tmp in MyUserForm.Properties: MyUserFormPropertiesDict[tmp.Name]=tmp --- This appears unstable and sometimes gives me a "pythoncom.com_error" which I don't know how to except. I can then go to my VisualBasic editor and double click on the Userform in the VBAProject window and the code snippet magically works without the "com_error". I tried MyUserForm.Activate which seemed to make things better but the problem has returned. Continuing on: MyUserFormControls=MyUserFormPropertiesDict["Controls"] For tmp in MyUserFormControls.Object: MyUserFormControlsDict[tmp.Name]=tmp --- I've observed this expression to come up with nothing at times in a manner that I can't predict ... The .Object is reported as "non-iterable" MyUserFormControlsDict['MyControl'].=whatever Thanks This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export. An export can include a release or disclosure to a foreign national inside or outside the United States. Include this notice with any reproduced portion of this information. From dan.glassman at charter.net Wed Feb 8 23:01:15 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Wed, 08 Feb 2006 16:01:15 -0600 Subject: [python-win32] Explicit variant types for Invoke & InvokeTypes (WasRe: Autocad.*) In-Reply-To: References: Message-ID: <43EA6A2B.3080106@charter.net> Mark Hammond wrote: >> if ( PySequence_Check(obuse) ) >> { >> V_ARRAY(var) = NULL; // not a valid, existing array. >> ok = PyCom_SAFEARRAYFromPyObject(obuse, &V_ARRAY(var), rawVT); >> V_VT(var) = VT_ARRAY | rawVT; >> } >> else >> { >> PythonOleArgHelper helper; >> helper.m_reqdType = rawVT; >> V_VT(var) = rawVT; >> ok = helper.MakeObjToVariant(obuse, var); > > The problem may well be your use of PySequence_Check() - that will succeed > for a string. You are then likely to end up with a VT_UI8 array. I think > you should *always* defer to MakeObjToVariant - that function will check the > VT, and if an array is requested it will do the right thing - ie, the > variant-type should *always* drive the conversion process in this case, > rather than the object value. Ah -- the lightbulb above my head is now lit. Thank you! > Yep, I think this is looking quite reasonable. Regarding testing, the best > thing is probably to try and use win32com\test\testvb.py. If you have VB > and the pywin32 sources, you should be able to create the test DLL from the > com\TestSources\PyCOMVBTest directory. testvb.py exercises *lots* of > different variant types, so somehow arranging (by copy-paste if necessary) > for those tests to be called with a new Variant object would be excellent. > If you don't have VB, let me know and I will send you a compliled DLL. Got the tests, passed the tests! The original testvb.py also passes, so I can't have messed anything up *too* much! :) I don't want to post such long code, so I'm hosting it. If the links don't work for any interested party, please just email me and I'll get you a copy. I'm quite enjoying this learning experience and am open to all suggestions. Test file: http://www.originalrog.org/testvb_variantclass.py My first try at class Variant (and some helpers): http://www.originalrog.org/VariantUtils.py That is the class definition which passed the tests. I hope a new-style class is okay; I figured it would be, given the python versions for which pywin32 "binaries" are distributed. If not, I don't think there's anything that can't be rewritten in classic style. A brief interactive session showing some class behaviour: http://www.originalrog.org/variantclass_interactive.txt The C++ implementation is below. I erased some of this thread...so...context: this is in oleargs.cpp in PyCom_VariantFromPyObject(). I put this clause just before the PySequence_Check() clause instead of at the top; figure it won't be used as often as the other clauses. [code] else if (strcmp(obj->ob_type->ob_type->tp_name, "VariantBase") == 0) { PyObject* typeAttr = PyString_FromString("_com_variant_type_"); PyObject* valAttr = PyString_FromString("_com_variant_value_"); if (!(typeAttr && valAttr)) return FALSE; PyObject* reqdType = PyObject_GenericGetAttr(obj, typeAttr); if (!reqdType) return FALSE; VARENUM rawVT = (VARENUM)PyInt_AsLong(reqdType); PyObject* obuse = PyObject_GenericGetAttr(obj, valAttr); if (!obuse) { Py_XDECREF(reqdType); return FALSE; } PythonOleArgHelper helper; helper.m_reqdType = V_VT(var) = rawVT; helper.MakeObjToVariant(obuse, var); Py_XDECREF(reqdType); Py_XDECREF(obuse); } // NOTE: PySequence_Check may return true for instance objects, ... [/code] Cheers! -Dan Glassman From timr at probo.com Thu Feb 9 02:17:02 2006 From: timr at probo.com (Tim Roberts) Date: Wed, 08 Feb 2006 17:17:02 -0800 Subject: [python-win32] More VisualBasic In-Reply-To: References: Message-ID: <43EA980E.1000609@probo.com> On Wed, 8 Feb 2006 11:28:16 -0800, "Speers, Ted" wrote: >I'm sure I'm destined to be a consumer of versus a contributor to this >group's output. > > We all started out that way. >I'd like to get some advice from the group whether I should pursue the >road I'm on ... >Am I on a fools errand trying to develop an application in Python that >manipulates VBUserForms? Are these errors that I'm seeing going to be >the bane of my existence due to some inherent flakiness or, through >experience/reading/discussiongroups/magic, will I be able to gain enough >understanding of how things work so that I can consistently avoid these >pitfalls? > > Here's my personal opinion, remembering that free advice is usually worth exactly what you paid for it. If you really need to be working with VBA forms in Excel, you will just hurt yourself to try to control them with anything other than VBA. It is quite possible to control Excel from Python; you can feed information into and out of cells in worksheets, and format it to your heart's content. It is quite possible to write a Python app with a UI, using tkinter or wxPython or whatever floats your boat, and have the events in that UI tickle Excel. However, if the UI was done in VBA, and must remain in VBA, then you probably want to manipulate the UI with VBA. Getting a VBA form to fire a Python event is difficult. Don't think of VBA as part of Excel. Think of it as a separate language that happens to hook into the Excel object model. That's exactly what Python is. Both of them can manipulate Excel, but it's a lot of work to have one of them manipulate the other. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Ted.Speers at actel.com Thu Feb 9 06:30:53 2006 From: Ted.Speers at actel.com (Speers, Ted) Date: Wed, 8 Feb 2006 21:30:53 -0800 Subject: [python-win32] More VisualBasic Message-ID: Thanks ... using VB widgets is not a requirement ... I was just lost when I tried to pick a GUI tool a year ago ... what would would float my boat would be some consensus about which is best ... wxPython, tkinter, something else ... or some decent write up describing the options ________________________________ From: python-win32-bounces at python.org on behalf of Tim Roberts Sent: Wed 2/8/2006 5:17 PM To: python-win32 at python.org Subject: Re: [python-win32] More VisualBasic On Wed, 8 Feb 2006 11:28:16 -0800, "Speers, Ted" wrote: >I'm sure I'm destined to be a consumer of versus a contributor to this >group's output. > > We all started out that way. >I'd like to get some advice from the group whether I should pursue the >road I'm on ... >Am I on a fools errand trying to develop an application in Python that >manipulates VBUserForms? Are these errors that I'm seeing going to be >the bane of my existence due to some inherent flakiness or, through >experience/reading/discussiongroups/magic, will I be able to gain enough >understanding of how things work so that I can consistently avoid these >pitfalls? > > Here's my personal opinion, remembering that free advice is usually worth exactly what you paid for it. If you really need to be working with VBA forms in Excel, you will just hurt yourself to try to control them with anything other than VBA. It is quite possible to control Excel from Python; you can feed information into and out of cells in worksheets, and format it to your heart's content. It is quite possible to write a Python app with a UI, using tkinter or wxPython or whatever floats your boat, and have the events in that UI tickle Excel. However, if the UI was done in VBA, and must remain in VBA, then you probably want to manipulate the UI with VBA. Getting a VBA form to fire a Python event is difficult. Don't think of VBA as part of Excel. Think of it as a separate language that happens to hook into the Excel object model. That's exactly what Python is. Both of them can manipulate Excel, but it's a lot of work to have one of them manipulate the other. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 This information contained or attached to this e-mail may be subject to the Export Administration Regulations (EAR) or the International Traffic in Arms Regulations (ITAR) and may require an approved export license prior to its export. An export can include a release or disclosure to a foreign national inside or outside the United States. Include this notice with any reproduced portion of this information. From sumeet_sobti at yahoo.com Fri Feb 10 00:31:25 2006 From: sumeet_sobti at yahoo.com (Sumeet Sobti) Date: Thu, 9 Feb 2006 15:31:25 -0800 (PST) Subject: [python-win32] Problem passing a VARIANT argument to a methodof aCOM object In-Reply-To: Message-ID: <20060209233125.65487.qmail@web60720.mail.yahoo.com> --- Mark Hammond wrote: > > STDMETHODIMP CTTOrderSelector::AddTest(LPCSTR > > lpProperty, VARIANT vValue) > > > > LPCSTR is not a valid COM type, but somehow it is > > correctly handled in C#. The authors claim that > their > > C# client code has been tested and is known to > work > > correctly. > > I assume that the C# implementation is using the > vtable interfaces and > making the call directly - ie, *not* going via > IDispatch. > > Can they show an early-bound VB example that works, > or anything else that > will go via IDispatch? > > There aren't any hacks I can think of - maybe ctypes > could work. > I tried ctypes. AddTest *does* seem to work with ctypes. The rest of my application is written using win32com. Is it possible to use both win32com-dispatched COM objects and ctype-com-created COM objects in the same application, and have them interact with each other safely and correctly? For example, is it possible to do the following or equivalent: A = win32com.client.Dispatch(xxx) B = ctypes.com.CreateInstance(yyy) A.some_attribute = B B.some_method(A) Otherwise, I'll have to re-code all of my objects and their events using ctypes, which probably won't be pleasant since there seems to be so little documentation on ctypes.. Thanks! -Sumeet. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mhammond at skippinet.com.au Fri Feb 10 00:42:38 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 10 Feb 2006 10:42:38 +1100 Subject: [python-win32] Problem passing a VARIANT argument to a methodof aCOM object In-Reply-To: <20060209233125.65487.qmail@web60720.mail.yahoo.com> Message-ID: > I tried ctypes. AddTest *does* seem to work with > ctypes. > > The rest of my application is written using win32com. > Is it possible to use both win32com-dispatched COM > objects and ctype-com-created COM objects in the same > application, and have them interact with each other > safely and correctly? > > For example, is it possible to do the following or > equivalent: > > A = win32com.client.Dispatch(xxx) > B = ctypes.com.CreateInstance(yyy) > > A.some_attribute = B > > B.some_method(A) The above should theoretically work - although you will have 2 distinct objects. ie, if the above would work when using 2 objects created by win32com, then it should work with 1 created by win32com and the other by ctypes. OTOH, I'd be happy for a facility so that we can pass COM objects between ctypes and win32com - eg: A = win32com.client.Dispatch(xxx) B = ctypes.com.CreateInstance(A) # or something similar # or the reverse: A = ctypes.com.CreateInstance(xxx) B = win32com.client.Dispatch(A) But I'm afraid I don't have time at the moment to look at this (I've still got about 6 unread messages from just this group all of which will take some time to go through and action) Mark From dan.glassman at charter.net Fri Feb 10 01:16:44 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Thu, 09 Feb 2006 18:16:44 -0600 Subject: [python-win32] Explicit variant types for Invoke & InvokeTypes (WasRe: Autocad.*) In-Reply-To: <43EA6A2B.3080106@charter.net> References: <43EA6A2B.3080106@charter.net> Message-ID: <43EBDB6C.1090401@charter.net> Dan Glassman wrote: > I don't want to post such long code, so I'm hosting it. If the links > don't work for any interested party, please just email me and I'll get > you a copy. I'm quite enjoying this learning experience and am open to > all suggestions. > > Test file: > http://www.originalrog.org/testvb_variantclass.py > Updated the test file; wanted to be sure that my use of the variant class' Value property to check "return" values wasn't skewing the results: http://www.originarog.org/testvb_variantclass2.py. Still passed, so it's apparent that _getValue(), which is the Value properties' getter, is working just as it should. Also realized that the SAFEARRAY support in oleargs.cpp uses PyCom_VariantFromPyObject, so the variant class can get used when the TYPEDESC calls for those, too. I applied the Variant class to those portions of the test; still passes with no changes required. -drg From smk_va at yahoo.com Sat Feb 11 01:13:59 2006 From: smk_va at yahoo.com (S Murthy Kambhampaty) Date: Fri, 10 Feb 2006 16:13:59 -0800 (PST) Subject: [python-win32] writing long integer values to Excel Message-ID: <20060211001359.28333.qmail@web51002.mail.yahoo.com> I got the impression from table 12-1 of "Python Programming on Win32" that writing 3 *(10 **9) to Excel would succeed, but it seems to overflow, while writing 3.0 *(10 **9) succeeds. Is this standard behavior, or perhaps a bug? Environment: Windows 2000 Python 2.4.2 pywin32-207 Thanks for the help, Murthy Steps to replicate: from win32com.client import Dispatch xlApp=Dispatch("Excel.Application") xlApp.Visible=1 xlBook=xlApp.Workbooks.Add() xlBook.Sheets(1).Range("B2").Value=3 *10 **9 # Excel stores -1294967296 xlBook.Sheets(1).Range("B2").Value=3.0 *10 **9 # Excel stores 3000000000 __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mhammond at skippinet.com.au Mon Feb 13 01:14:21 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 13 Feb 2006 11:14:21 +1100 Subject: [python-win32] writing long integer values to Excel In-Reply-To: <20060211001359.28333.qmail@web51002.mail.yahoo.com> Message-ID: > I got the impression from table 12-1 of "Python > Programming on Win32" that writing 3 *(10 **9) to > Excel would succeed, but it seems to overflow, while > writing 3.0 *(10 **9) succeeds. Is this standard > behavior, or perhaps a bug? Yes, it is a bug. I have fixed it here. As you noticed, a work around is to use a Python float. As COM pre windows XP doesn't support 64bit ints, underneath the covers these large values are converted to a double anyway, so you don't really lose much. Let me know if you would like a new DLL to test with though. Regards, Mark From puusepp1 at hot.ee Mon Feb 13 14:01:14 2006 From: puusepp1 at hot.ee (Renee Puusepp) Date: Mon, 13 Feb 2006 15:01:14 +0200 Subject: [python-win32] py2exe and numarray problem? Message-ID: <20060213130116.04E5F4D1D6@mh3-3.hot.ee> Hey I've got a problem when compiling my python scripts with py2exe. It gives me an error: ImportError: No module named dotblas , which is a part of numarray. Could the problem lie in the fact that numarray dir doesn't ave dotblas.pyd ? Has anyone worked around this problem? I'm using python 2.4.2, numarray 1.5.1 and  vpython 3.2.3 Any hint is appreciated Thanks renee -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060213/789450b0/attachment.html From yeswanty_devi at yahoo.com Tue Feb 14 01:15:53 2006 From: yeswanty_devi at yahoo.com (yeswanty devi) Date: Mon, 13 Feb 2006 16:15:53 -0800 (PST) Subject: [python-win32] Setting of Events of Labview using python Message-ID: <20060214001553.28550.qmail@web30007.mail.mud.yahoo.com> Hello, I was trying to acces LabView using python.i have problem in accesing of events of labview using python. for example my labview program runs based on the events.if an mouse up event comes then particular part gets executed. But now if i want to automate this thing using python i am not able to create the events using python. i have to manually press the button. Is there any procedure to set the mouse events using python program without manually using the mouse. Thanks, --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060213/7404631e/attachment.htm From le.dahut at laposte.net Tue Feb 14 14:39:30 2006 From: le.dahut at laposte.net (le dahut) Date: Tue, 14 Feb 2006 14:39:30 +0100 Subject: [python-win32] NT service update Message-ID: <43F1DD92.80204@laposte.net> Hi, I'm trying to update a self-build installed NT service on win XP. What is the best way to do that. Do I have to stop the service, replace and restart it or is there a better method ? Thanks. From yeswanty_devi at yahoo.com Tue Feb 14 00:57:05 2006 From: yeswanty_devi at yahoo.com (yeswanty devi) Date: Mon, 13 Feb 2006 15:57:05 -0800 (PST) Subject: [python-win32] Setting Event of Labview using Python Message-ID: <20060213235705.71486.qmail@web30011.mail.mud.yahoo.com> Hello, I was trying to acces LabView using python.i have problem in accesing of events of labview using python. for example my labview program runs based on the events.if an mouse up event comes then particular part gets executed. But now if i want to automate this thing using python i am not able to create the events using python. i have to manually press the button. Is there any procedure to set the mouse events using python program without manually using the mouse. Thanks, --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060213/88686f4c/attachment.htm From martin.kuner at thomson.net Wed Feb 15 09:24:38 2006 From: martin.kuner at thomson.net (Kuner Martin) Date: Wed, 15 Feb 2006 09:24:38 +0100 Subject: [python-win32] Setting Event of Labview using Python Message-ID: <5FBC042194FEC54C9EFEA97D1EA8B3680222DDA6@villsmail01.eu.thmulti.com> Hi Devi. I think it?s not possible what you want. The LV 7.1 help says about events: Use Events for Direct User Interaction Only User interface events occur only when a user directly interacts with the active front panel. In general, LabVIEW does not generate events if you use the VI Server, global variables, local variables, DataSocket, and so on to change VI or front panel objects programmatically. The only exception is the Value (Signaling) property. Regards, Martin _____ From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of yeswanty devi Sent: Tuesday, 14. February 2006 00:57 To: python-win32 at python.org Subject: [python-win32] Setting Event of Labview using Python Hello, I was trying to acces LabView using python.i have problem in accesing of events of labview using python. for example my labview program runs based on the events.if an mouse up event comes then particular part gets executed. But now if i want to automate this thing using python i am not able to create the events using python. i have to manually press the button. Is there any procedure to set the mouse events using python program without manually using the mouse. Thanks, _____ Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060215/6b6e5d6f/attachment.html From rays at blue-cove.com Wed Feb 15 16:32:46 2006 From: rays at blue-cove.com (RayS) Date: Wed, 15 Feb 2006 07:32:46 -0800 Subject: [python-win32] pyHook on Win98; no events Message-ID: <6.2.3.4.2.20060215072433.0304f590@pop-server.san.rr.com> To debug pyKeyLogger, I wrote this with pyHook (and compiled with py2exe on Win2K), which prints the ascii codes as expected on Win2K: import pyHook import time import pythoncom def OnKeyboardEvent(event): print event.Ascii def main(): hm = pyHook.HookManager() hm.KeyDown = OnKeyboardEvent hm.HookKeyboard() while True: pythoncom.PumpMessages() if __name__ == '__main__': main() It silently does nothing on Win98... What is needed? py2exe on 98? I did test it on a fresh install of 98... I also just thought about trying loading ANSI.SYS at boot, but I can't test until tomorrow. Thanks, Ray From p.asselman at chello.nl Wed Feb 15 16:21:08 2006 From: p.asselman at chello.nl (p.asselman at chello.nl) Date: Wed, 15 Feb 2006 16:21:08 +0100 Subject: [python-win32] Excel advanced find Message-ID: <20060215152108.LWAH29486.amsfep18-int.chello.nl@localhost> Hello all, I'm having some trouble on the find function in Excel. A simple Find statement works fine, but as soon as I want to use an advanced option (xlByColumns) I get an error. This is my program: #!/usr/bin/python from win32com.client import Dispatch from win32com.client import constants xlApp = Dispatch("Excel.Application") xlApp.Visible = 1 xlApp.Workbooks.Open('c:\\temp\\python\\excel\\findtest.xls') xlApp.Worksheets(1).Activate() findcell = xlApp.ActiveSheet.UsedRange.Find('FXN3') print findcell.Address findcell = xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValues,constants.xlWhole,constants.xlByColumns,constants.xlNext,False,False,None) print findcell.Address xlApp.Quit() del xlApp And this is the output: C:\temp\python\excel>python findtest.py $D$5 Traceback (most recent call last): File "findtest.py", line 20, in ? findcell = xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValues,c onstants.xlWhole,constants.xlByColumns,constants.xlNext,False,False,None) File "C:\Program Files\python24\lib\site-packages\win32com\gen_py\00020813-000 0-0000-C000-000000000046x0x1x4.py", line 21407, in Find , MatchCase, MatchByte, SearchFormat) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352571), 9) As you can see, the first find statement works fine, but the second returns an error. Any help on this would be much appreciated. Thanks, Patrick Asselman From tim.golden at viacom-outdoor.co.uk Wed Feb 15 17:08:40 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Wed, 15 Feb 2006 16:08:40 -0000 Subject: [python-win32] Excel advanced find Message-ID: <9A28C052FF32734DACB0A288A3533991044D2569@vogbs009.gb.vo.local> [p.asselman at chello.nl] | Hello all, | | I'm having some trouble on the find function in Excel. A | simple Find statement works fine, but as soon as I want to | use an advanced option (xlByColumns) I get an error. | [... snip ...] | findcell = | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValue | s,constants.xlWhole,constants.xlByColumns,constants.xlNext,Fal | se,False,None) | And this is the output: | C:\temp\python\excel>python findtest.py | $D$5 | Traceback (most recent call last): | File "findtest.py", line 20, in ? | findcell = | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValues,c | onstants.xlWhole,constants.xlByColumns,constants.xlNext,False, | False,None) | File "C:\Program | Files\python24\lib\site-packages\win32com\gen_py\00020813-000 | 0-0000-C000-000000000046x0x1x4.py", line 21407, in Find | , MatchCase, MatchByte, SearchFormat) | pywintypes.com_error: (-2147352567, 'Exception occurred.', | (0, None, None, None, | 0, -2147352571), 9) *Very* quick and untested response: try using named params for the Find method. At the very least, you can then miss out the default values and it might narrow the prob. down TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From dan.glassman at charter.net Wed Feb 15 21:47:37 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Wed, 15 Feb 2006 14:47:37 -0600 Subject: [python-win32] Excel advanced find In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D2569@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D2569@vogbs009.gb.vo.local> Message-ID: <43F39369.50303@charter.net> Tim Golden wrote: > [p.asselman at chello.nl] > > | Hello all, > | > | I'm having some trouble on the find function in Excel. A > | simple Find statement works fine, but as soon as I want to > | use an advanced option (xlByColumns) I get an error. > | > > [... snip ...] > > | findcell = > | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValue > | s,constants.xlWhole,constants.xlByColumns,constants.xlNext,Fal > | se,False,None) > > | And this is the output: > | C:\temp\python\excel>python findtest.py > | $D$5 > | Traceback (most recent call last): > | File "findtest.py", line 20, in ? > | findcell = > | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValues,c > | onstants.xlWhole,constants.xlByColumns,constants.xlNext,False, > | False,None) > | File "C:\Program > | Files\python24\lib\site-packages\win32com\gen_py\00020813-000 > | 0-0000-C000-000000000046x0x1x4.py", line 21407, in Find > | , MatchCase, MatchByte, SearchFormat) > | pywintypes.com_error: (-2147352567, 'Exception occurred.', > | (0, None, None, None, > | 0, -2147352571), 9) > > *Very* quick and untested response: try using named > params for the Find method. At the very least, you > can then miss out the default values and it might > narrow the prob. down When you use None, the arguments will still be presented to the Excel interface as Null. It would appear that the Excel interface doesn't like either the [After] arg nor the [SearchFormat] arg to be Null. Named arguments will work as suggested; this will prevent those arguments from being presented to the Excel interface at all. You can also use pythoncom.Missing, which is another way to prevent arguments from being presented to the interface: [code] from pythoncom import Missing usedRange = xlApp.ActiveSheet.UsedRange usedRange.Find('FXN3', Missing, constants.xlValues, constants.xlWhole, constants,xlByColumns, constants.xlNext, False, False, Missing) [/code] -- -Dan Glassman From dan.glassman at charter.net Thu Feb 16 01:09:27 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Wed, 15 Feb 2006 18:09:27 -0600 Subject: [python-win32] [Fwd: Re: Excel advanced find] Message-ID: <43F3C2B7.6090205@charter.net> Dan Glassman wrote: > Named arguments will work as suggested; this will prevent those > arguments from being presented to the Excel interface at all. You can > also use pythoncom.Missing, which is another way to prevent arguments > from being presented to the interface: > > [code] > from pythoncom import Missing > usedRange = xlApp.ActiveSheet.UsedRange > usedRange.Find('FXN3', Missing, constants.xlValues, > constants.xlWhole, constants,xlByColumns, > constants.xlNext, False, False, Missing) > [/code] Whoa -- disregard that suggestion; that was really bad idea on my part. All the arguments after the first Missing get ignored if you do that. Named arguments, then. -- -Dan Glassman From mhammond at skippinet.com.au Thu Feb 16 03:10:28 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 16 Feb 2006 13:10:28 +1100 Subject: [python-win32] [Fwd: Re: Excel advanced find] In-Reply-To: <43F3C2B7.6090205@charter.net> Message-ID: > > [code] > > from pythoncom import Missing > > usedRange = xlApp.ActiveSheet.UsedRange > > usedRange.Find('FXN3', Missing, constants.xlValues, > > constants.xlWhole, constants,xlByColumns, > > constants.xlNext, False, False, Missing) > > [/code] > > Whoa -- disregard that suggestion; that was really bad idea on my > part. All the arguments after the first Missing get ignored if > you do that. pythoncom.Empty will behave as you desire - it will present an "empty" variant (VT_EMPTY). There is no way to truly provide NULL for an individual item as they are passed as an array (and pythoncom.Missing is where this array gets terminated) It might actually be useful to print a warning (via the warnings module) if any params are supplied after a missing, as the user probably doesn't intend for them to be ignored. As usual, patches welcome :) Mark From p.asselman at chello.nl Thu Feb 16 13:23:27 2006 From: p.asselman at chello.nl (p.asselman at chello.nl) Date: Thu, 16 Feb 2006 13:23:27 +0100 Subject: [python-win32] [Fwd: Re: Excel advanced find] Message-ID: <20060216122327.CILA29486.amsfep18-int.chello.nl@localhost> > > van: "Mark Hammond" > datum: 2006/02/16 do AM 03:10:28 CET > aan: "Dan Glassman" , > onderwerp: Re: [python-win32] [Fwd: Re: Excel advanced find] > > > > [code] > > > from pythoncom import Missing > > > usedRange = xlApp.ActiveSheet.UsedRange > > > usedRange.Find('FXN3', Missing, constants.xlValues, > > > constants.xlWhole, constants,xlByColumns, > > > constants.xlNext, False, False, Missing) > > > [/code] > > > > Whoa -- disregard that suggestion; that was really bad idea on my > > part. All the arguments after the first Missing get ignored if > > you do that. > > pythoncom.Empty will behave as you desire - it will present an "empty" > variant (VT_EMPTY). There is no way to truly provide NULL for an individual > item as they are passed as an array (and pythoncom.Missing is where this > array gets terminated) Thanks, that is exactly what I was looking for. It works like a charm! This should really be added to some readme or documentation file, or some of the example demos. The syntax of most commands can be figured out pretty easily through the msdn website or vBasic examples (which often leave out some command arguments), but this is something really Python-Win32-specific and I haven't read about it anywhere... Thanks again, Patrick Asselman From benvinger at yahoo.co.uk Thu Feb 16 17:55:38 2006 From: benvinger at yahoo.co.uk (Ben Vinger) Date: Thu, 16 Feb 2006 16:55:38 +0000 (GMT) Subject: [python-win32] bad W32 logfiles cause win32evtlog to exit without an error Message-ID: <20060216165539.69044.qmail@web25811.mail.ukl.yahoo.com> Hello I've modified John Nielsen's code (see http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/Windows_NT_Eventlog.html) to read and summarize the eventlogs of dozens of servers. When the script (running on W2K) connects to one or two of these NT servers, it exits without any traceback. (It works fine on many other NT, W2K and w2003 servers) I used to run the same script on an NT server, and it caused a Dr Watson error when accessing these "bad" eventlogs. I can get past the problem by clearing the eventlogs on the server in question, but I would like to trap the problem automatically when occurs, so something automated can happen when this occurs. Thanks Ben ___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com From mrmaple at gmail.com Fri Feb 17 15:21:07 2006 From: mrmaple at gmail.com (James Carroll) Date: Fri, 17 Feb 2006 09:21:07 -0500 Subject: [python-win32] File permissions... Message-ID: How do I grant permissions on directories with pythonwin? At the moment we use a command line utility: cacls "existing path" /E /T /P Everyone:F To give Everyone full access (:F) by modifying an existing ACL (/E) and affecting all contents of the directory (/T) I'd like to do it all with shell or com stuff if possible. Thanks, -Jim From mathweijzen at home.nl Fri Feb 17 18:52:50 2006 From: mathweijzen at home.nl (Math) Date: Fri, 17 Feb 2006 18:52:50 +0100 Subject: [python-win32] MS Access and Python Message-ID: <001d01c633eb$0dbd9fe0$0302a8c0@uw403axvp2ndff> Hello, I don't know if I ask at the right place. But..I use Python, win32com.client and ADO together with MS Access. What I don't know, what do I need when I wanna distribute my Python-program? What does the enduser need, how do I check it and what extras do I have to provide? Anybody any ideas where I can get ,ore info? Thanks Math From mark.m.mcmahon at gmail.com Fri Feb 17 19:09:53 2006 From: mark.m.mcmahon at gmail.com (Mark Mc Mahon) Date: Fri, 17 Feb 2006 13:09:53 -0500 Subject: [python-win32] MS Access and Python In-Reply-To: <001d01c633eb$0dbd9fe0$0302a8c0@uw403axvp2ndff> References: <001d01c633eb$0dbd9fe0$0302a8c0@uw403axvp2ndff> Message-ID: <71b6302c0602171009k1bad7763j36c688a189ef1d40@mail.gmail.com> Hi Math, On 2/17/06, Math wrote: > Hello, > > I don't know if I ask at the right place. > But..I use Python, win32com.client and ADO together with MS Access. > What I don't know, what do I need when I wanna distribute my Python-program? > What does the enduser need, how do I check it and what extras do I have to > provide? > Anybody any ideas where I can get ,ore info? A good place to start would be Py2exe py (http://www.py2exe.org/) I have heard of pyinstaller too - but I don't know much about that (http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi) > > Thanks > Math > Mark From dactex at swbell.net Fri Feb 17 22:57:49 2006 From: dactex at swbell.net (David Carter) Date: Fri, 17 Feb 2006 15:57:49 -0600 Subject: [python-win32] Using win32com Constants Message-ID: <000401c6340d$32b72380$2800005a@gosys2000.local> Why is it that when I want to use a win32COM constant such as acViewNormal in an MS Access COM automation session I find I have to use some convoluted thing like: ComConstants = win32com.client.constants.__dict__["__dicts__"][0] viewtype = ComConstants['acViewNormal'] Am I missing something obvious? Thanks David Carter From fumanchu at amor.org Fri Feb 17 23:11:14 2006 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 17 Feb 2006 14:11:14 -0800 Subject: [python-win32] Using win32com Constants Message-ID: <6949EC6CD39F97498A57E0FA55295B2101B3D58E@ex9.hostedexchange.local> David Carter wrote: > Why is it that when I want to use a win32COM constant such as > acViewNormal in an MS Access COM automation session I find I > have to use some convoluted thing like: > > ComConstants = > win32com.client.constants.__dict__["__dicts__"][0] > viewtype = ComConstants['acViewNormal'] > > Am I missing something obvious? Are you calling Dispatch before referencing the constants? http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/html/com/ win32com/HTML/QuickStartClientCom.html "Makepy automatically installs all generated constants from a type library in an object called win32com.clients.constants. You do not need to do anything special to make these constants work, other than create the object itself (ie, in the example above, the constants relating to Word would automatically be available after the w=win32com.client.Dispatch("Word.Application") statement." Robert Brewer System Architect Amor Ministries fumanchu at amor.org From dactex at swbell.net Fri Feb 17 23:29:06 2006 From: dactex at swbell.net (David Carter) Date: Fri, 17 Feb 2006 16:29:06 -0600 Subject: [python-win32] Using win32com Constants In-Reply-To: <6949EC6CD39F97498A57E0FA55295B2101B3D58E@ex9.hostedexchange.local> Message-ID: <000001c63411$909610c0$2800005a@gosys2000.local> Yes, -those- constants work fine. They're the application specific constants that require the convolution. David Carter > -----Original Message----- > From: Robert Brewer [mailto:fumanchu at amor.org] > Sent: Friday, February 17, 2006 4:11 PM > To: David Carter; python-win32 at python.org > Subject: RE: [python-win32] Using win32com Constants > > > David Carter wrote: > > Why is it that when I want to use a win32COM constant such as > > acViewNormal in an MS Access COM automation session I find I > > have to use some convoluted thing like: > > > > ComConstants = > > win32com.client.constants.__dict__["__dicts__"][0] > > viewtype = ComConstants['acViewNormal'] > > > > Am I missing something obvious? > > Are you calling Dispatch before referencing the constants? > > http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32 /html/com/ win32com/HTML/QuickStartClientCom.html "Makepy automatically installs all generated constants from a type library in an object called win32com.clients.constants. You do not need to do anything special to make these constants work, other than create the object itself (ie, in the example above, the constants relating to Word would automatically be available after the w=win32com.client.Dispatch("Word.Application") statement." Robert Brewer System Architect Amor Ministries fumanchu at amor.org From WilliTf at dshs.wa.gov Sat Feb 18 00:38:03 2006 From: WilliTf at dshs.wa.gov (Williams, Thomas) Date: Fri, 17 Feb 2006 15:38:03 -0800 Subject: [python-win32] PAMIE and BeautifulSoup Message-ID: <592E8923DB6EA348BE8E33FCAADEFFFC171997DB@dshs-exch2.dshs.wa.lcl> Greetings, I am using PAMIE to interact with web pages. Essentially, I am entering values then submitting the form. What I have not yet figured out is to read the source code for the resulting website. I have used BeautifulSoup to do this on other websites, but I am unable to incorporate BeautifulSoup with the resulting website powered by PAMIE. BeautifulSoup Example: >From BeautifulSoup import BeautifulSoup Import urllib url = 'http://www.cnn.com' s = urllib.urlopen(url).read() soup = BeautifulSoup(s) soup.done() PAMIE Example: Import cPAMIE url = 'http://www.cnn.com' ie = cPAMIE.PAMIE(url) Any guidance or suggestions will be most appreciative. Tom Williams -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060217/f8db5edd/attachment.htm From dan.glassman at charter.net Sat Feb 18 01:25:24 2006 From: dan.glassman at charter.net (Dan Glassman) Date: Fri, 17 Feb 2006 18:25:24 -0600 Subject: [python-win32] Using win32com Constants In-Reply-To: <000001c63411$909610c0$2800005a@gosys2000.local> References: <000001c63411$909610c0$2800005a@gosys2000.local> Message-ID: <43F66974.4060501@charter.net> David Carter wrote: >>-----Original Message----- >>From: Robert Brewer [mailto:fumanchu at amor.org] >>Sent: Friday, February 17, 2006 4:11 PM >>To: David Carter; python-win32 at python.org >>Subject: RE: [python-win32] Using win32com Constants >> >> >>David Carter wrote: >> >>>Why is it that when I want to use a win32COM constant such as >>>acViewNormal in an MS Access COM automation session I find I >>>have to use some convoluted thing like: >>> >>> ComConstants = >>>win32com.client.constants.__dict__["__dicts__"][0] >>> viewtype = ComConstants['acViewNormal'] >>> >>>Am I missing something obvious? >> >>Are you calling Dispatch before referencing the constants? >> >>http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32 > > Yes, -those- constants work fine. They're the application specific constants > that require the convolution. He wasn't suggesting that Dispatch wasn't working, but rather pointing out that the constants don't work until *after* you've called Dispatch. The way to use the constants (after calling Dispatch) is like this: >>> win32com.client.constants.acViewNormal If that's not working, then I'd say there's nothing *too* obvious that you're missing. You've obviously run makepy, otherwise even the convolution wouldn't work... -drg From sjmachin at lexicon.net Sat Feb 18 01:38:56 2006 From: sjmachin at lexicon.net (John Machin) Date: Sat, 18 Feb 2006 11:38:56 +1100 Subject: [python-win32] Using win32com Constants In-Reply-To: <43F66974.4060501@charter.net> References: <000001c63411$909610c0$2800005a@gosys2000.local> <43F66974.4060501@charter.net> Message-ID: <43F66CA0.5050503@lexicon.net> On 18/02/2006 11:25 AM, Dan Glassman wrote: > David Carter wrote: > >>>-----Original Message----- >>>From: Robert Brewer [mailto:fumanchu at amor.org] >>>Sent: Friday, February 17, 2006 4:11 PM >>>To: David Carter; python-win32 at python.org >>>Subject: RE: [python-win32] Using win32com Constants >>> >>> >>>David Carter wrote: >>> >>> >>>>Why is it that when I want to use a win32COM constant such as >>>>acViewNormal in an MS Access COM automation session I find I >>>>have to use some convoluted thing like: >>>> >>>> ComConstants = >>>>win32com.client.constants.__dict__["__dicts__"][0] >>>> viewtype = ComConstants['acViewNormal'] >>>> >>>>Am I missing something obvious? >>> >>>Are you calling Dispatch before referencing the constants? >>> >>>http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32 > > > > >>Yes, -those- constants work fine. They're the application specific constants >>that require the convolution. > > > He wasn't suggesting that Dispatch wasn't working, but rather pointing out > that the constants don't work until *after* you've called Dispatch. > > The way to use the constants (after calling Dispatch) is like this: > > >>> win32com.client.constants.acViewNormal > > If that's not working, then I'd say there's nothing *too* obvious that you're > missing. You've obviously run makepy, otherwise even the convolution wouldn't > work... > David, Forget your convolvulus; show us a small complete runnable piece of code that tries to do what you expect/want, but fails. Cheers, John From waldemar.osuch at gmail.com Sat Feb 18 03:07:43 2006 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Fri, 17 Feb 2006 19:07:43 -0700 Subject: [python-win32] PAMIE and BeautifulSoup In-Reply-To: <592E8923DB6EA348BE8E33FCAADEFFFC171997DB@dshs-exch2.dshs.wa.lcl> References: <592E8923DB6EA348BE8E33FCAADEFFFC171997DB@dshs-exch2.dshs.wa.lcl> Message-ID: <6fae95540602171807vcd67367ne15588fda95fe869@mail.gmail.com> > > From BeautifulSoup import BeautifulSoup > > Import cPAMIE > > url = 'http://www.cnn.com' > > ie = cPAMIE.PAMIE(url) > bs = BeautifulSoup(ie.pageText()) From rwupole at msn.com Sat Feb 18 15:52:57 2006 From: rwupole at msn.com (Roger Upole) Date: Sat, 18 Feb 2006 09:52:57 -0500 Subject: [python-win32] Re: File permissions... References: Message-ID: There's an example of changing a file's security in \win32\demos\security\set_file_audit.py. However, you'll need to use AddAccessAllowedAceEx instead of AddAccessAllowedAce to set the inheritance flags. hth Roger James Carroll wrote: > How do I grant permissions on directories with pythonwin? > > At the moment we use a command line utility: > cacls "existing path" /E /T /P Everyone:F > > To give Everyone full access (:F) by modifying an existing ACL (/E) > and affecting all contents of the directory (/T) > > I'd like to do it all with shell or com stuff if possible. Thanks, -Jim From rwupole at msn.com Sat Feb 18 17:07:06 2006 From: rwupole at msn.com (Roger Upole) Date: Sat, 18 Feb 2006 11:07:06 -0500 Subject: [python-win32] Re: NT service update References: <43F1DD92.80204@laposte.net> Message-ID: If the bulk of your service's functionality is kept in separate modules, you might be able to set it up so that you can send a signal to the service to reload them. hth Roger le dahut wrote: > Hi, > > I'm trying to update a self-build installed NT service on win XP. What > is the best way to do that. Do I have to stop the service, replace and > restart it or is there a better method ? > > Thanks. > > From dactex at swbell.net Sat Feb 18 20:01:01 2006 From: dactex at swbell.net (David Carter) Date: Sat, 18 Feb 2006 13:01:01 -0600 Subject: [python-win32] Using win32com Constants In-Reply-To: <43F66CA0.5050503@lexicon.net> Message-ID: <000701c634bd$ac2a6280$6401a8c0@dactex.com> Thanks to all who have sent some assistance... What I'm trying to accomplish is to understand more of the nuts and bolts. I'm at the intermediates level of learning python on my own, so there are bound to be some gaps in my understanding of python's innner workings. Anyway... The constants become available after Dispatch-ing the application whose type library you want to access. So yesterday's expression: win32com.client.constants.__dict__["__dicts__"][0].keys() is really the same as win32com.client.constants.__dicts__[0].keys() And I think this is because win32com.client.constants.__dicts__[0] is a attribute:value hash for the win32com.client.Constant object win32com.client.constants, which includes -all- the attributes of the object as well as the constant/value pairs I was after. So I can access them then as an attribute of win32com.client.constants if I know their names. David Carter From yeswanty_devi at yahoo.com Sun Feb 19 23:24:55 2006 From: yeswanty_devi at yahoo.com (yeswanty devi) Date: Sun, 19 Feb 2006 14:24:55 -0800 (PST) Subject: [python-win32] Excel using python Message-ID: <20060219222455.78463.qmail@web30314.mail.mud.yahoo.com> Hello all, if we have number of excel sheets in a workbook.can we access a selected sheet in the workbook. when i try to acces it always goes to the last sheet. thanks, --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060219/9e90cfc8/attachment.html From tim.golden at viacom-outdoor.co.uk Mon Feb 20 09:46:20 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 20 Feb 2006 08:46:20 -0000 Subject: [python-win32] Excel using python Message-ID: <9A28C052FF32734DACB0A288A3533991044D2580@vogbs009.gb.vo.local> [yeswanty devi] | Hello all, | if we have number of excel sheets in a workbook.can | we access a selected sheet in the workbook. when i try to | acces it always goes to the last sheet. I assume this is the kind of thing you want: (somewhat exaggerated example, but ...) import os import win32com.client xl = win32com.client.Dispatch ("Excel.Application") # # Create a new workbook with a default # number of sheets (probably 3) # wb = xl.Workbooks.Add () print wb.Sheets.Count sheet0 = wb.Sheets[0] sheet1 = wb.Sheets[1] sheet2 = wb.Sheets[2] sheet0.Name = "First sheet" sheet1.Name = "Second sheet" sheet2.Name = "Third sheet" wb.SaveAs (Filename="c:\\temp\\test.xls") wb.Close () xl.Quit () os.startfile ("c:\\temp\\test.xls") TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From sjmachin at lexicon.net Mon Feb 20 09:55:17 2006 From: sjmachin at lexicon.net (John Machin) Date: Mon, 20 Feb 2006 19:55:17 +1100 Subject: [python-win32] Excel using python In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D2580@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D2580@vogbs009.gb.vo.local> Message-ID: <43F983F5.5070209@lexicon.net> On 20/02/2006 7:46 PM, Tim Golden wrote: > [yeswanty devi] > > | Hello all, > | if we have number of excel sheets in a workbook.can > | we access a selected sheet in the workbook. when i try to > | acces it always goes to the last sheet. > > I assume this is the kind of thing you want: > (somewhat exaggerated example, but ...) > > > import os > import win32com.client > > xl = win32com.client.Dispatch ("Excel.Application") > # > # Create a new workbook with a default > # number of sheets (probably 3) > # > wb = xl.Workbooks.Add () > print wb.Sheets.Count > > sheet0 = wb.Sheets[0] > sheet1 = wb.Sheets[1] > sheet2 = wb.Sheets[2] > > sheet0.Name = "First sheet" > sheet1.Name = "Second sheet" > sheet2.Name = "Third sheet" > > wb.SaveAs (Filename="c:\\temp\\test.xls") > wb.Close () > xl.Quit () > > os.startfile ("c:\\temp\\test.xls") > > Errrmmm ... I got the impression that the OP wanted to access a particular sheet in an existing workbook, not to create a new workbook. The OP didn't say whether he wanted to select by name or number; perhaps some kind soul could tell him both :-) From tim.golden at viacom-outdoor.co.uk Mon Feb 20 10:02:47 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 20 Feb 2006 09:02:47 -0000 Subject: [python-win32] Excel using python Message-ID: <9A28C052FF32734DACB0A288A3533991044D2581@vogbs009.gb.vo.local> [John Machin] | | On 20/02/2006 7:46 PM, Tim Golden wrote: | > [yeswanty devi] | > | > | Hello all, | > | if we have number of excel sheets in a workbook.can | > | we access a selected sheet in the workbook. when i try to | > | acces it always goes to the last sheet. | > | > I assume this is the kind of thing you want: | > (somewhat exaggerated example, but ...) | > [... snip ...] | | Errrmmm ... I got the impression that the OP wanted to access a | particular sheet in an existing workbook, not to create a new | workbook. I guessed; but I usually try to make my examples run on their own two feet (or something!) if only so I can test the thing before posting. That's the only reason I created the book before selecting the sheets. I admit I do assume the existence of c:\temp. Good point about the names; I didn't think of that. OK, given the workbook created in my previous post... import win32com.client xl = win32com.client.Dispatch ("Excel.Application") wb = xl.Workbooks.Open ("c:\\temp\\test.xls") sheet0 = wb.Sheets ("First sheet") # or wb.Sheets[0] sheet1 = wb.Sheets ("Second sheet") # or wb.Sheets[1] # # etc. # wb.Close () xl.Quit () TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From sjmachin at lexicon.net Mon Feb 20 11:32:21 2006 From: sjmachin at lexicon.net (John Machin) Date: Mon, 20 Feb 2006 21:32:21 +1100 Subject: [python-win32] Excel using python In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D2581@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D2581@vogbs009.gb.vo.local> Message-ID: <43F99AB5.3020800@lexicon.net> On 20/02/2006 8:02 PM, Tim Golden wrote: > [John Machin] > | > | On 20/02/2006 7:46 PM, Tim Golden wrote: > | > [yeswanty devi] > | > > | > | Hello all, > | > | if we have number of excel sheets in a workbook.can > | > | we access a selected sheet in the workbook. when i try to > | > | acces it always goes to the last sheet. > | > > | > I assume this is the kind of thing you want: > | > (somewhat exaggerated example, but ...) > | > > > [... snip ...] > > | > | Errrmmm ... I got the impression that the OP wanted to access a > | particular sheet in an existing workbook, not to create a new > | workbook. > > I guessed; but I usually try to make my examples run > on their own two feet (or something!) if only so I > can test the thing before posting. That's the only > reason I created the book before selecting the sheets. > I admit I do assume the existence of c:\temp. > > Good point about the names; I didn't think of that. > > OK, given the workbook created in my previous post... > > > import win32com.client > > xl = win32com.client.Dispatch ("Excel.Application") > wb = xl.Workbooks.Open ("c:\\temp\\test.xls") > > sheet0 = wb.Sheets ("First sheet") # or wb.Sheets[0] > sheet1 = wb.Sheets ("Second sheet") # or wb.Sheets[1] > # > # etc. > # > > wb.Close () > xl.Quit () > > > > TJG > OK, great, Tim, we're almost there :-) "when i try to acces it always goes to the last sheet." ... looks like the OP wants the default sheet to point to some sheet other than the last sheet; ho wdo we do that? Cheers, John From tim.golden at viacom-outdoor.co.uk Mon Feb 20 12:15:49 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 20 Feb 2006 11:15:49 -0000 Subject: [python-win32] Excel using python Message-ID: <9A28C052FF32734DACB0A288A3533991044D2585@vogbs009.gb.vo.local> [John Machin] | > OK, given the workbook created in my previous post... [ ... snip more code ...] | OK, great, Tim, we're almost there :-) | "when i try to acces it always goes to the last sheet." ... | looks like | the OP wants the default sheet to point to some sheet other than the | last sheet; ho wdo we do that? I swear this reads like the script of an educational children's programme! ;) But you're quite right to point out how scantily I read the original question and just dived for my keyboard. It's not clear to me what the "default" sheet is. What I didn't show in my code examples is the concept of the ActiveSheet which can be changed by calling a sheet's .Select method. When the workbook is saved, that active sheet is saved with it. (ie the activeness of one sheet is saved). Maybe that's the idea? [Do you think the OP's still reading?] import win32com.client xl = win32com.client.Dispatch ("Excel.Application") wb = xl.Workbooks.Open ("c:/temp/test.xls") print wb.ActiveSheet.Name # # probably prints "First Sheet" # wb.Sheets ("Third Sheet").Select () print wb.ActiveSheet.Name # prints "Third Sheet" wb.Save () wb.Close () wb = xl.Workbooks.Open ("c:/temp/test.xls") print wb.ActiveSheet.Name # # prints "Third Sheet" # Any better? TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From sjmachin at lexicon.net Mon Feb 20 12:31:59 2006 From: sjmachin at lexicon.net (John Machin) Date: Mon, 20 Feb 2006 22:31:59 +1100 Subject: [python-win32] Excel using python In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D2585@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D2585@vogbs009.gb.vo.local> Message-ID: <43F9A8AF.80108@lexicon.net> On 20/02/2006 10:15 PM, Tim Golden wrote: > [John Machin] > > | > OK, given the workbook created in my previous post... > > [ ... snip more code ...] > > | OK, great, Tim, we're almost there :-) > | "when i try to acces it always goes to the last sheet." ... > | looks like > | the OP wants the default sheet to point to some sheet other than the > | last sheet; ho wdo we do that? > > I swear this reads like the script of an educational children's > programme! ;) But you're quite right to point out how scantily > I read the original question and just dived for my keyboard. > > It's not clear to me what the "default" sheet is. What I didn't > show in my code examples is the concept of the ActiveSheet which > can be changed by calling a sheet's .Select method. When the > workbook is saved, that active sheet is saved with it. (ie the > activeness of one sheet is saved). Maybe that's the idea? > [Do you think the OP's still reading?] > > > import win32com.client > > xl = win32com.client.Dispatch ("Excel.Application") > wb = xl.Workbooks.Open ("c:/temp/test.xls") > print wb.ActiveSheet.Name > # > # probably prints "First Sheet" > # > wb.Sheets ("Third Sheet").Select () > print wb.ActiveSheet.Name > # prints "Third Sheet" > > wb.Save () > wb.Close () > > wb = xl.Workbooks.Open ("c:/temp/test.xls") > print wb.ActiveSheet.Name > # > # prints "Third Sheet" > # > > > Any better? > > TJG > Tim, that's fantastic. Hold out your hand for the elephant stamp :-) Is the OP still reading? Yes, I often wonder that too, when threads get a bit long. But apart from moderate banter, we haven't got off his topic, so let's hope he's hung in there, time zones permitting. Cheers, John From tim.golden at viacom-outdoor.co.uk Mon Feb 20 12:37:38 2006 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Mon, 20 Feb 2006 11:37:38 -0000 Subject: [python-win32] Excel using python Message-ID: <9A28C052FF32734DACB0A288A3533991044D2586@vogbs009.gb.vo.local> | From: John Machin [mailto:sjmachin at lexicon.net] | | Tim, that's fantastic. Hold out your hand for the elephant stamp :-) Must be an American thing? (Obligatory Monty Python reference: I'm sorry, old man, I don't quite follow your banter!) | ... apart from moderate banter, we haven't got off his | topic, so let's hope he's hung in there, time zones permitting. | Cheers, | John A pleasure doing banter with you. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From sjmachin at lexicon.net Mon Feb 20 12:53:28 2006 From: sjmachin at lexicon.net (John Machin) Date: Mon, 20 Feb 2006 22:53:28 +1100 Subject: [python-win32] Excel using python In-Reply-To: <9A28C052FF32734DACB0A288A3533991044D2586@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991044D2586@vogbs009.gb.vo.local> Message-ID: <43F9ADB8.6000607@lexicon.net> On 20/02/2006 10:37 PM, Tim Golden wrote: > | From: John Machin [mailto:sjmachin at lexicon.net] > | > | Tim, that's fantastic. Hold out your hand for the elephant stamp :-) > > Must be an American thing? (Obligatory Monty Python > reference: I'm sorry, old man, I don't quite follow your > banter!) > Tim, mate, must it? It's funny how the poms think I'm a seppo, and the seppos think I'm a pom ... the reference is to children being rewarded for endeavour by having an inked rubber stamp applied to their extremities, typically a stamp depicting some nice creature like a heffalump or a bunyip. Cheers, Jophn From yeswanty_devi at yahoo.com Sun Feb 19 20:12:58 2006 From: yeswanty_devi at yahoo.com (yeswanty devi) Date: Sun, 19 Feb 2006 11:12:58 -0800 (PST) Subject: [python-win32] Excel Application Message-ID: <20060219191258.4991.qmail@web30315.mail.mud.yahoo.com> Hello all, if we have number of excel sheets in a workbook.can we access a select sheet in the workbook. when i try to acces it always goes to the last sheet. thanks, --------------------------------- Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060219/91efe189/attachment.htm From info at apli-agipa.com Mon Feb 20 10:48:44 2006 From: info at apli-agipa.com (Sylvain FAUVEAU (apli-agipa)) Date: Mon, 20 Feb 2006 10:48:44 +0100 Subject: [python-win32] Problem with excel AutoFilter function Message-ID: <000901c63602$d76d8030$0165a8c0@apliagipa51.com> Hello. I have a little problem with the function AutoFilter in Excel. The VB code for activate, desactivate AutoFilter is the same : AutoFilter But if I try this in python it doesn't work ! For activate the autofilter in python, I make this : selection.AutoFilter(Field=1) It works. But to desactivate the autofilter, if I try : selection.AutoFilter() # without arguments Python says : Traceback (most recent call last): File "", line 1, in ? File "C:\usr\Python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x5.py", line 22262, in AutoFilter , Criteria1, Operator, Criteria2, VisibleDropDown) File "C:\usr\Python24\Lib\site-packages\win32com\client\__init__.py", line 446, in _ApplyTypes_ return self._get_good_object_( com_error: (-2147352567, "Une exception s'est produite.", (0, 'Microsoft Office Excel', 'La m\xe9thode AutoFilter de la classe Range a \xe9chou\xe9.', 'C:\\usr\\Microsoft Office\\OFFICE11\\1036\\xlmain11.chm', 0, -2146827284), None) I also try with arguments Field=None with the same result. How can I desactivate this #?#?!#? autofilter ? Thanks ! Sylvain FAUVEAU From p.asselman at chello.nl Mon Feb 20 13:51:50 2006 From: p.asselman at chello.nl (p.asselman at chello.nl) Date: Mon, 20 Feb 2006 13:51:50 +0100 Subject: [python-win32] Excel using python Message-ID: <20060220125150.MIIR29873.amsfep18-int.chello.nl@localhost> Or how about xl.Worksheets(1).Activate() or xl.Worksheets("Sheet1").Activate() and then you may use sheetname = xl.ActiveSheet.Name and other such nice things... Best regards, Patrick Asselman > > van: "Tim Golden" > datum: 2006/02/20 ma PM 12:15:49 CET > aan: > onderwerp: Re: [python-win32] Excel using python > > [John Machin] > > | > OK, given the workbook created in my previous post... > > [ ... snip more code ...] > > | OK, great, Tim, we're almost there :-) > | "when i try to acces it always goes to the last sheet." ... > | looks like > | the OP wants the default sheet to point to some sheet other than the > | last sheet; ho wdo we do that? > > I swear this reads like the script of an educational children's > programme! ;) But you're quite right to point out how scantily > I read the original question and just dived for my keyboard. > > It's not clear to me what the "default" sheet is. What I didn't > show in my code examples is the concept of the ActiveSheet which > can be changed by calling a sheet's .Select method. When the > workbook is saved, that active sheet is saved with it. (ie the > activeness of one sheet is saved). Maybe that's the idea? > [Do you think the OP's still reading?] > > > import win32com.client > > xl = win32com.client.Dispatch ("Excel.Application") > wb = xl.Workbooks.Open ("c:/temp/test.xls") > print wb.ActiveSheet.Name > # > # probably prints "First Sheet" > # > wb.Sheets ("Third Sheet").Select () > print wb.ActiveSheet.Name > # prints "Third Sheet" > > wb.Save () > wb.Close () > > wb = xl.Workbooks.Open ("c:/temp/test.xls") > print wb.ActiveSheet.Name > # > # prints "Third Sheet" > # > > > Any better? > > TJG > From bertrand.mathieu at ingeniweb.com Mon Feb 20 15:52:20 2006 From: bertrand.mathieu at ingeniweb.com (Bertrand Mathieu) Date: Mon, 20 Feb 2006 15:52:20 +0100 Subject: [python-win32] saving an ole control object embedded in a powerpoint Message-ID: <1140447140.5942.42.camel@localhost.localdomain> Hi, I have made a python program that extracts some informations out of PowerPoint files, using MS-Powerpoint. It works well, but I also need to extract Shockwave Flash from certain slides. I am able to get the OLE object, but I can't figure out what to do with it so as to save its content to a SWF file: if shape.Type == constants.msoOLEControlObject: ole_format = shape.OLEFormat if ole_format.ProgID == u'ShockwaveFlash.ShockwaveFlash.1': pass # wish I could save flash content After some investigation, it seems that this object implements the IPersistStream interface. I imagine I could use the Save(IStream) method, or better pythoncom.OleSaveToStream(IPersistStream, IStream). The problem is that I don't know how to obtain something that would be accepted as an IStream (through python/com machinery) and that would write everything to a file or in a string, and that I can read later. Finally, I don't really know if I am following the good direction. Any clue? Regards, -- Bertrand Mathieu - INGENIWEB SAS 17 rue Louise Michel - 92300 Levallois Perret - France Tel / Fax : (33) 1 47 57 39 14 web : www.ingeniweb.com - ? les Services Web Ing?nieux ? From mhammond at skippinet.com.au Mon Feb 20 23:44:57 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 21 Feb 2006 09:44:57 +1100 Subject: [python-win32] saving an ole control object embedded in a powerpoint In-Reply-To: <1140447140.5942.42.camel@localhost.localdomain> Message-ID: > The problem is that I don't know how to obtain something that would be > accepted as an IStream (through python/com machinery) and that would > write everything to a file or in a string, and that I can read later. Look at the win32com.server.util FileStream class. Usage would be something like: from win32com.server.util import wrap, FileStream f = open(filename, "wb") fs = FileStream(f) # Turn it into a "real" COM object. fs = wrap(fs) # Pass it to COM pythoncom.OleSaveToStream(persist, fs) Untested, but that is the idea. Mark From durumdara at mailpont.hu Tue Feb 21 10:15:51 2006 From: durumdara at mailpont.hu (durumdara at mailpont.hu) Date: Tue, 21 Feb 2006 10:15:51 +0100 Subject: [python-win32] Little tool - but very big size... :-( Message-ID: <43FADA47.3020905@mailpont.hu> Hi ! I have a problem. I have a little tool that can get data about filesystems and I wrote it in python. The main user asked me a GUI for this software. This user is needed a portable program, so I create this kind of the software with Py2Exe. But it have very big size: 11 MB... :-( The dist directory: 2006.02.21. 10:09 . 2006.02.21. 10:09 .. 2005.09.28. 12:41 77 824 bz2.pyd 2006.02.21. 10:09 0 dirlist.txt 2006.02.20. 12:51 611 384 library.zip 2006.02.15. 16:22 23 558 main.ico 2004.12.16. 17:22 348 160 MSVCR71.dll 2005.09.28. 12:41 1 867 776 python24.dll 2006.01.11. 12:19 102 400 pywintypes24.dll 2005.09.28. 12:41 405 504 unicodedata.pyd 2005.09.28. 12:41 4 608 w9xpopen.exe 2006.01.11. 12:19 73 728 win32api.pyd 2006.01.11. 12:20 81 920 win32file.pyd 2006.01.11. 12:26 106 496 win32security.pyd 2006.01.10. 19:09 4 943 872 wxmsw26uh_vc.dll 2006.02.20. 12:51 40 960 wxPyHDDirList.exe 2005.09.28. 12:41 69 632 zlib.pyd 2006.01.10. 19:13 626 688 _controls_.pyd 2006.01.10. 19:12 696 320 _core_.pyd 2006.01.10. 19:13 364 544 _gdi_.pyd 2006.01.10. 19:13 491 520 _misc_.pyd 2006.01.10. 19:13 548 864 _windows_.pyd 20 file 11 485 758 byte I need to have more compressed result. Can I compress dll-s, pyd-s with Py2Exe ? Can I decrease the total size with something ? If not, how to I create an self-unpackager and self-starter program that use an temporary directory in the disk ? With WinRar ? Thanx for help: dd From swell at netcourrier.com Tue Feb 21 14:53:49 2006 From: swell at netcourrier.com (Julien) Date: Tue, 21 Feb 2006 13:53:49 +0000 (UTC) Subject: [python-win32] Fresh excel session Message-ID: Hi, I wrote a small app that is able to open a excel ssheet with the win32com module. My problem is that it opens the new excel in the current excel session ( if available ). Is there a way of opening a fresh new excel session with the following script and not interferate with my current working session. import win32com.client xlApp = win32com.client.Dispatch('Excel.Application') xlApp.Visible = 1 xlApp.Workbooks.Add() xlApp.Close() Thx From mathweijzen at home.nl Tue Feb 21 19:51:46 2006 From: mathweijzen at home.nl (Math) Date: Tue, 21 Feb 2006 19:51:46 +0100 Subject: [python-win32] COM ports connecting Message-ID: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> Hello, Anybody could give me an example code of how connect/comunicate through COM ports (i.e. COM1, COM2). I'm under windows XP > Thanks!!! Math -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060221/aaf97d5c/attachment.htm From rays at blue-cove.com Tue Feb 21 20:38:33 2006 From: rays at blue-cove.com (Ray Schumacher) Date: Tue, 21 Feb 2006 11:38:33 -0800 Subject: [python-win32] COM ports connecting In-Reply-To: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> References: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> Message-ID: <6.2.5.2.2.20060221113410.052e0678@blue-cove.com> At 10:51 AM 2/21/2006, Math wrote: >Hello, > >Anybody could give me an example code of how connect/comunicate through COM ports (i.e. COM1, COM2). >I'm under windows XP I'm working on a command module for telescopes over COM ports, http://rjs.org/Python/LX200.zip so look at LXSerial.py and the connect_port() method, as well as others there. Ray try: connectedPort = serial.Serial( port=port, #number of device, numbering starts at #zero. if everything fails, the user #can specify a device string, note #that this isn't portable anymore #if no port is specified an unconfigured #an closed serial port object is created baudrate=baud, #baudrate bytesize=serial.EIGHTBITS, #number of databits parity=serial.PARITY_NONE, #enable parity checking stopbits=serial.STOPBITS_ONE, #number of stopbits timeout=ptimeout, #set a timeout value, None for waiting forever xonxoff=0, #no software flow control rtscts=0, #no RTS/CTS flow control writeTimeout=3, #set a timeout for writes dsrdtr=None, #None: use rtscts setting, dsrdtr override if true or false ) except serial.SerialException, s: raise -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060221/fc7dc1c7/attachment.html From sjmachin at lexicon.net Tue Feb 21 22:07:03 2006 From: sjmachin at lexicon.net (John Machin) Date: Wed, 22 Feb 2006 08:07:03 +1100 Subject: [python-win32] COM ports connecting In-Reply-To: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> References: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> Message-ID: <43FB80F7.5080203@lexicon.net> On 22/02/2006 5:51 AM, Math wrote: > Hello, > > Anybody could give me an example code of how connect/comunicate through > COM ports (i.e. COM1, COM2). > I'm under windows XP > > Thanks!!! > Math http://pyserial.sourceforge.net/ From mhammond at skippinet.com.au Wed Feb 22 01:00:09 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 22 Feb 2006 11:00:09 +1100 Subject: [python-win32] Fresh excel session In-Reply-To: Message-ID: > Hi, > I wrote a small app that is able to open a excel ssheet with > the win32com > module. My problem is that it opens the new excel in the current > excel session > ( if available ). Is there a way of opening a fresh new excel > session with the > following script and not interferate with my current working session. > > > import win32com.client > > xlApp = win32com.client.Dispatch('Excel.Application') Try using win32com.client.DispatchEx() instead - that doesn't call GetActiveObject() first, so should start a new instance. Cheers, Mark From reed at intersiege.com Wed Feb 22 02:29:05 2006 From: reed at intersiege.com (Reed L. O'Brien) Date: Tue, 21 Feb 2006 20:29:05 -0500 Subject: [python-win32] Pywin32 way of getting to open files Message-ID: <43FBBE61.3040401@intersiege.com> Hello: I am looking to check for open files in shared folders; and close them. I would do this manually by right clicking on my computer and selecting manage then opening shared folders and open files... This appears to be part of the compmgmt.msc smapin to MMC. Any hints on where i should be looking in win32 modules to hook into this area? Google is hiding it from me and the docs I am finding aren't the right ones albeit interesting and time consuming. Thanks, ~reed P.S.- Thanks to Mark and all other contributors for such a great set of modules-er extensions. Really exemplary work. -- 4.6692916090 'cmVlZEBpbnRlcnNpZWdlLmNvbQ==\n'.decode('base64') http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1 keyID: 0x0FA09FCE From mumarathe at gmail.com Wed Feb 22 03:28:46 2006 From: mumarathe at gmail.com (Manish Marathe) Date: Tue, 21 Feb 2006 18:28:46 -0800 Subject: [python-win32] building python on Windows Message-ID: <7c8a9a970602211828m74a017fcq519fb5e8f0a777f0@mail.gmail.com> Python Experts everywhere!! I am trying to build python 2.4.1 on windows 2003 server using the MSVC files under src/PC/VC6. If I try to open the workspace pcbuild.dsw with MS Visual C++ 6.0, it tries to login into Visual SourceSafe and asks for login and password. I believe this shouldn't be the case. Any inputs on this?? -Manish -- Manish Marathe SpikeSource, Inc. http://developer.spikesource.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060221/65b31318/attachment.htm From rwupole at msn.com Wed Feb 22 04:43:48 2006 From: rwupole at msn.com (Roger Upole) Date: Tue, 21 Feb 2006 22:43:48 -0500 Subject: [python-win32] Re: Pywin32 way of getting to open files Message-ID: That functionality is in the win32net module. NetFileEnum and NetFileClose should be able to do what you want. hth Roger From mathweijzen at home.nl Wed Feb 22 10:25:18 2006 From: mathweijzen at home.nl (Math) Date: Wed, 22 Feb 2006 10:25:18 +0100 Subject: [python-win32] COM ports connecting References: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> <43FB80F7.5080203@lexicon.net> Message-ID: <001101c63791$e5b33370$0302a8c0@uw403axvp2ndff> Thank you all for your respond. However, I run into another problem I forgot to mention. My Laptop doesn't have a 9-pin Serial port, only USB-connectors, so I guess I have to buy a USB-Serial Converter to..... Does everythong else then remain the same? Do I then still have to use the 'import serial' or is there something for USB to? How do I proceed from here on? Anybody? Thanks Math ----- Original Message ----- From: "John Machin" To: "Math" Cc: Sent: Tuesday, February 21, 2006 10:07 PM Subject: Re: [python-win32] COM ports connecting > On 22/02/2006 5:51 AM, Math wrote: >> Hello, >> Anybody could give me an example code of how connect/comunicate through >> COM ports (i.e. COM1, COM2). >> I'm under windows XP >> > Thanks!!! >> Math > > http://pyserial.sourceforge.net/ > > From rschroev_nospam_ml at fastmail.fm Wed Feb 22 14:01:22 2006 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Wed, 22 Feb 2006 14:01:22 +0100 Subject: [python-win32] COM ports connecting In-Reply-To: <001101c63791$e5b33370$0302a8c0@uw403axvp2ndff> References: <000c01c63717$dda85590$0302a8c0@uw403axvp2ndff> <43FB80F7.5080203@lexicon.net> <001101c63791$e5b33370$0302a8c0@uw403axvp2ndff> Message-ID: Math schreef: > Thank you all for your respond. > However, I run into another problem I forgot to mention. > My Laptop doesn't have a 9-pin Serial port, only USB-connectors, so I guess > I have to buy a USB-Serial Converter to..... > Does everythong else then remain the same? Yes. The driver of the USB <-> Serial convertor will add a (virtual port), probably COM5 or COM6. You just use that instead of COM1 or whatever. > Do I then still have to use the 'import serial' or is there something for > USB to? You can just use import serial as with a real serial port. The module doesn't see any difference between a real port or a virtual one: the driver makes sure it looks just the same. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From reed at intersiege.com Wed Feb 22 15:47:08 2006 From: reed at intersiege.com (Reed L. O'Brien) Date: Wed, 22 Feb 2006 09:47:08 -0500 Subject: [python-win32] importing win32com.shell Message-ID: <43FC796C.3080105@intersiege.com> Hello: I wrote a quickie script to get word and charatcer counts from word documents using Tim Golden's winshell module. When I py2exe it it doesn't pull in shell from win32com.shell, since it appears, to me, to be in win32comext instead of win32com. Is there a standard way to deal with this or do I need to go name it manually in my py2exe setup file (which I tried while running out the door yesterday without sucess)? Thanks, ~reed -- 4.6692916090 'cmVlZEBpbnRlcnNpZWdlLmNvbQ==\n'.decode('base64') http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1 keyID: 0x0FA09FCE From dave at psys.org Wed Feb 22 17:49:01 2006 From: dave at psys.org (d.w. harks) Date: Wed, 22 Feb 2006 10:49:01 -0600 Subject: [python-win32] Makepy and Documentum Foundation Classes Message-ID: <20060222164900.GA3116@psys.org> Greetings, all, I'm working with the COM interface for Documentum, trying to expose it via PythonCOM. Unfortunately, the dynamic dispatch and makepy utilities don't get the correct IDs for the various methods -- which are often object factories that lead to more dispatches. However, once I got the initial Dispatch to work, if I call GetIDsFromNames on the _oleobj_ of the parent object for each method I want to call, I get a correct ID -- by updating the makepy-generated file with this, things start to work correctly. Obviously, manually going through the generated file and updating the IDs is not a great solution, so I'd like to patch build.py... But I really have no idea where to start. Any hints? Even an idea of what methods to look at would be much appreciated. Oh, I should mention that Documentum's COM objects are implemented via the COM-Java bridge, which could be related, though I'm not sure. Thanks, dave -- David W. Harks From cappy2112 at gmail.com Wed Feb 22 20:36:54 2006 From: cappy2112 at gmail.com (Tony C) Date: Wed, 22 Feb 2006 11:36:54 -0800 Subject: [python-win32] building python on Windows Message-ID: <8249c4ac0602221136n62ea188es895a8529a7b0f6dc@mail.gmail.com> Correct me if I'm wrong, I don't think you can build anything after Python 2.3 with VC6. This just might save you some grief though.Although, this has nothing to do with your Source Safe issue. I use Visual C 6 on non-python projects on XP, and don' t have this problem. Message: 7 Date: Tue, 21 Feb 2006 18:28:46 -0800 From: "Manish Marathe" Subject: [python-win32] building python on Windows To: python-win32 at python.org Message-ID: <7c8a9a970602211828m74a017fcq519fb5e8f0a777f0 at mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Python Experts everywhere!! I am trying to build python 2.4.1 on windows 2003 server using the MSVC files under src/PC/VC6. If I try to open the workspace pcbuild.dsw with MS Visual C++ 6.0, it tries to login into Visual SourceSafe and asks for login and password. I believe this shouldn't be the case. Any inputs on this?? -Manish -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060222/5aa0c25c/attachment.html From timr at probo.com Wed Feb 22 20:55:33 2006 From: timr at probo.com (Tim Roberts) Date: Wed, 22 Feb 2006 11:55:33 -0800 Subject: [python-win32] RRe: COM ports connecting In-Reply-To: References: Message-ID: <43FCC1B5.7020302@probo.com> On Wed, 22 Feb 2006 10:25:18 +0100, "Math" wrote: >Thank you all for your respond. >However, I run into another problem I forgot to mention. >My Laptop doesn't have a 9-pin Serial port, only USB-connectors, so I guess >I have to buy a USB-Serial Converter to..... >Does everythong else then remain the same? >Do I then still have to use the 'import serial' or is there something for >USB to? >How do I proceed from here on? > > Yes, if you need to talk to a serial device and you have no serial connector, then you will have to buy some kind of a converter. Any USB-to-Serial converter that you buy should include a driver which makes it look like a serial port to the operating system. Thus, pyserial should still be the right mechanism. However, it turns out that the Windows serial driver model is rather convoluted and poorly-defined. Many of the converter drivers do not do a thorough job of emulation. You will just have to try it and see. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From trentm at ActiveState.com Wed Feb 22 23:01:08 2006 From: trentm at ActiveState.com (Trent Mick) Date: Wed, 22 Feb 2006 14:01:08 -0800 Subject: [python-win32] building python on Windows In-Reply-To: <8249c4ac0602221136n62ea188es895a8529a7b0f6dc@mail.gmail.com> References: <8249c4ac0602221136n62ea188es895a8529a7b0f6dc@mail.gmail.com> Message-ID: <20060222220108.GA10240@activestate.com> [Tony C wrote] > Correct me if I'm wrong, I don't think you can build anything after Python > 2.3 with VC6. You *can*, it just isn't the default anymore... and it is possible that Python's VC6 project files will be unmaintained and hence out of date for subsequent versions. Trent -- Trent Mick TrentM at ActiveState.com From mhammond at skippinet.com.au Wed Feb 22 23:04:46 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 23 Feb 2006 09:04:46 +1100 Subject: [python-win32] Makepy and Documentum Foundation Classes In-Reply-To: <20060222164900.GA3116@psys.org> Message-ID: > Unfortunately, the dynamic dispatch and makepy utilities don't get the > correct IDs for the various methods -- which are often object factories > that lead to more dispatches. I'm not sure what you mean by "dynamic dispatch", but if you explicitly use win32com.client.dynamic.DumpDispatch(), you should find the object is only calling GetIDsFromNames() on the object (which you later said does work). However, makepy (and a normal Dispatch() in many cases) does things differently - it asks the object for its "typeinfo", and builds up a map of all the available methods and properties. As the win32com dispid mapping works for the vast majority of objects, it would appear possible that the typeinfo retrieved for the object is not accurate. > Obviously, manually going through the generated file and updating the > IDs is not a great solution, so I'd like to patch build.py... > > But I really have no idea where to start. Any hints? Even an idea of > what methods to look at would be much appreciated. I've no idea where to start as I've no idea what kind of patch you are after. Looking at the _Build_Interface() method in win32com\client\genpy.py would be a reasonable start, and is probably the place where we iterate over the typeinfo and get the (apparently wrong) dispid and param information. > Oh, I should mention that Documentum's COM objects are implemented via > the COM-Java bridge, which could be related, though I'm not sure. That certainly sounds a likely candidate - OTOH, if the bridge itself is incorrect I'd expect other languages that introspect the typeinfo to also fail in similar ways. Sadly, VBScript is probably unable to use the typeinfo in that way, and depending on how the interface is defined, VB itself may just jump directly to the vtable interface and also avoid getting IDispatch info from the typelib. Mark From reed at intersiege.com Wed Feb 22 23:12:54 2006 From: reed at intersiege.com (Reed L. O'Brien) Date: Wed, 22 Feb 2006 17:12:54 -0500 Subject: [python-win32] [OT] importing win32com.shell - RESOLVED In-Reply-To: <43FC796C.3080105@intersiege.com> References: <43FC796C.3080105@intersiege.com> Message-ID: <43FCE1E6.8070305@intersiege.com> Reed L. O'Brien wrote: > Hello: > > I wrote a quickie script to get word and charatcer counts from word > documents using Tim Golden's winshell module. > > When I py2exe it it doesn't pull in shell from win32com.shell, since it > appears, to me, to be in win32comext instead of win32com. Is there a > standard way to deal with this or do I need to go name it manually in my > py2exe setup file (which I tried while running out the door yesterday > without sucess)? > > Thanks, > ~reed > > Answering my own question for the record: Sorry for the OT post in the first place. Because of some magic that the win32 wizards cast, py2exe doesn't find win32com.shell. import sys try: import modulefinder import win32com for p in win32com.__path__[1:]: modulefinder.AddPackagePath("win32com", p) for extra in ["win32com.shell","win32com.mapi"]: __import__(extra) m = sys.modules[extra] for p in m.__path__[1:]: modulefinder.AddPackagePath(extra, p) except ImportError: # no build path setup, no worries. pass The answer was here: http://starship.python.net/crew/theller/moin.cgi/WinShell Best regards and thanks to all who make python such a great language... ~reed -- 4.6692916090 'cmVlZEBpbnRlcnNpZWdlLmNvbQ==\n'.decode('base64') http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1 keyID: 0x0FA09FCE From heang.s.lim at gmail.com Thu Feb 23 01:53:00 2006 From: heang.s.lim at gmail.com (Heang Lim) Date: Wed, 22 Feb 2006 17:53:00 -0700 Subject: [python-win32] Python Newbie Question Message-ID: I've installed Python on my c:\python23 directory and Apache on my c:\Apache2 directory. On my DOS windows, I went to c:\Apache\htdocs directory and enter 'python' to go into the interactive mode. When I tried to import some modules such as 'import os' or 'import string', I was getting 'ImportError: no module named os', etc. Am I missing some sort of environment variable setting somewhere? I have my PYTHONPATH system variable set to 'c:\python23'. Any help would be appreciated. HL From sjmachin at lexicon.net Thu Feb 23 02:12:24 2006 From: sjmachin at lexicon.net (John Machin) Date: Thu, 23 Feb 2006 12:12:24 +1100 Subject: [python-win32] Python Newbie Question In-Reply-To: References: Message-ID: <43FD0BF8.4030101@lexicon.net> On 23/02/2006 11:53 AM, Heang Lim wrote: > I've installed Python on my c:\python23 directory and Apache on my > c:\Apache2 directory. On my DOS windows, I went to c:\Apache\htdocs > directory and enter 'python' to go into the interactive mode. When I > tried to import some modules such as 'import os' or 'import string', I > was getting 'ImportError: no module named os', etc. Am I missing some > sort of environment variable setting somewhere? I have my PYTHONPATH > system variable set to 'c:\python23'. > do this: DOS-prompt>python >>> import sys >>> sys.path and show us the output (copy/paste). From dave at psys.org Thu Feb 23 03:55:17 2006 From: dave at psys.org (d.w. harks) Date: Wed, 22 Feb 2006 20:55:17 -0600 Subject: [python-win32] Makepy and Documentum Foundation Classes In-Reply-To: References: <20060222164900.GA3116@psys.org> Message-ID: <20060223025517.GB3116@psys.org> With carefully-arranged electrons, Mark Hammond wrote: > > Unfortunately, the dynamic dispatch and makepy utilities don't get the > > correct IDs for the various methods -- which are often object factories > > that lead to more dispatches. > > I'm not sure what you mean by "dynamic dispatch", but if you explicitly use > win32com.client.dynamic.DumpDispatch(), you should find the object is only > calling GetIDsFromNames() on the object (which you later said does work). By dynamic dispatch, I was referring to simply calling win32com.client.dynamic.Dispatch(). What's really interesting is that I get a third result from doing the DumbDispatch(); in that case the methods on the object return a string with the Java object name. So the COM-Java bridge (or something about the underlying Java implementation) seems to be at work here. The type library has the right types, but the wrong enumeration of dispid's. > > However, makepy (and a normal Dispatch() in many cases) does things > differently - it asks the object for its "typeinfo", and builds up a map of > all the available methods and properties. > > As the win32com dispid mapping works for the vast majority of objects, it > would appear possible that the typeinfo retrieved for the object is not > accurate. > Okay, that makes sense. At least that would let me go back to the vendor and request that they update their typelib. :-) > > Obviously, manually going through the generated file and updating the > > IDs is not a great solution, so I'd like to patch build.py... > > > > But I really have no idea where to start. Any hints? Even an idea of > > what methods to look at would be much appreciated. > > I've no idea where to start as I've no idea what kind of patch you are > after. Looking at the _Build_Interface() method in win32com\client\genpy.py > would be a reasonable start, and is probably the place where we iterate over > the typeinfo and get the (apparently wrong) dispid and param information. I was hoping for something that would allow build.py to detect this case and handle it; of course based on what we've found that might not be possible. > > Oh, I should mention that Documentum's COM objects are implemented via > > the COM-Java bridge, which could be related, though I'm not sure. > > That certainly sounds a likely candidate - OTOH, if the bridge itself is > incorrect I'd expect other languages that introspect the typeinfo to also > fail in similar ways. Sadly, VBScript is probably unable to use the > typeinfo in that way, and depending on how the interface is defined, VB > itself may just jump directly to the vtable interface and also avoid getting > IDispatch info from the typelib. Is there any way to use the vtable interface through win32com? Thanks for your prompt reply to my somewhat vague questions :-) dave -- David W. Harks From chris.schmechel at gmail.com Thu Feb 23 15:24:14 2006 From: chris.schmechel at gmail.com (Chris Schmechel) Date: Thu, 23 Feb 2006 06:24:14 -0800 Subject: [python-win32] Close Windows Dialog Box Message-ID: <7a754c960602230624w1660db09r11c71765f4f05aa@mail.gmail.com> Hi, I'm trying to cancel the File Download - Security Warning box that appears in IE on XP SP2. The button options are to run, save, or cancel. ... wnd = 0 while wnd == 0: wnd = FindWindowEx(0,0,"#32770","File Download - Security Warning") print wnd PostMessage(wnd,WM_CLOSE,0,0) Any ideas on how to accomplish this? I'm fairly new to Python as well, but it's great so far. Thanks again, Chris Schmechel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060223/8b9cfabb/attachment.htm From timr at probo.com Thu Feb 23 18:55:40 2006 From: timr at probo.com (Tim Roberts) Date: Thu, 23 Feb 2006 09:55:40 -0800 Subject: [python-win32] building python on Windows In-Reply-To: References: Message-ID: <43FDF71C.2070406@probo.com> On Tue, 21 Feb 2006 18:28:46 -0800, "Manish Marathe" wrote: >Python Experts everywhere!! > >I am trying to build python 2.4.1 on windows 2003 server using the MSVC >files under src/PC/VC6. If I try to open the workspace pcbuild.dsw with MS >Visual C++ 6.0, it tries to login into Visual SourceSafe and asks for login >and password. I believe this shouldn't be the case. > > This is perfectly normal. Visual Source Safe leaves "droppings" in the VC++ project file. Any time you take a VC++ project that used to be in Visual Source Safe and move it to another machine, the new VC++ will try to connect to VSS, just in case you happen to be on the same network. >Any inputs on this?? > All you need to do is decline. Click cancel, or whatever the "leave me alone" option is. It won't ask you again. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Feb 23 22:42:46 2006 From: timr at probo.com (Tim Roberts) Date: Thu, 23 Feb 2006 13:42:46 -0800 Subject: [python-win32] Automated FTP? In-Reply-To: References: Message-ID: <43FE2C56.4050508@probo.com> Matt Upton wrote: >Hello Tim and Mark. I have a subscription to the python win-32 help e-mail >list but I keep getting bounce backs (I have been sending to: >python-win32 at python.org). Do I have the wrong address?? I have e-mailed the >help e-mail addresses and have not gotten any responses. > > That's the right address. Have you possibly changed e-mail addresses recently? You might try logging in to the list server to see if your account is current. http://mail.python.org/mailman/listinfo/python-win32 >Hello all, I am relatively new to Python (on Windows XP). > >Is it possible using Python to automate downloading large files from a ftp >site. > >For example, to set a specific time for my code to run (say 7AM in the >morning), connect to a ftp site and download the files in a certain folder >(with some if then statements of course). > >How would I get started with doing that? > >I figure this might be a relatively straight forward program that many have >done before, so instead of re-inventing the wheel, maybe I could go directly >to the sources? > > Yes, this is easy in Python. You can use the Windows "Scheduled Tasks" tool to run your script at 7 AM every morning. There is an ftplib module in the standard library, that even includes a sample script showing you how to do a transfer. However, depending on how much conditional stuff you have, you might also be able to do the job with a batch file calling wget. Wget is a terrific command line utility for fetching arbitrary files from web and FTP servers, and it is available for Windows. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sjmachin at lexicon.net Fri Feb 24 00:48:28 2006 From: sjmachin at lexicon.net (John Machin) Date: Fri, 24 Feb 2006 10:48:28 +1100 Subject: [python-win32] Python Newbie Question In-Reply-To: References: <43FD0BF8.4030101@lexicon.net> <43FE239D.4000407@lexicon.net> Message-ID: <43FE49CC.7070709@lexicon.net> On 24/02/2006 10:23 AM, Heang Lim wrote: > I've been fiddling with the setup and it might have done more damage > than good. The reason I'm using Python 2.3.5 is because of WindPySend > DLL that I found on the net to do test automation and it does not > support Python 2.4. Not yet at least. Due to this I'm being forced > to use 2.3.5. Thanks for your feed back. I think I'm going to > re-install Python instead of trying to fix it. > > HL Re-installing sounds like a very good idea. Randomly perturbing the setup and then ignoring warning messages is not a good idea. "I'm using Python 2.3.5" is contradicted by your previous message "Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32". You may have TWO (or more!) installations of Python 2.3. Remove ALL traces of ALL installations of Python 2.3 before re-installing. Please don't top-post. > On 2/23/06, John Machin wrote: > >>On 24/02/2006 3:02 AM, Heang Lim wrote: >> >>>Hello John, >>> >>>Here is the sys.path output: >>> >>>C:\\Apache2\htdocs>python >>>'import site' failed; use -v for traceback >> >>Hmmm ... either (1) you get this all the time and you didn't think it >>was worth doing anything about or worth mentioning when you asked your >>question or (2) you have been fiddling about with your setup since >>asking :-( >> >>So do what it says: >>dos-prompt>python -v >> >>and tell us the output. >> >> >>>Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 >>>Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>>>>>import sys >>>>>>sys.path >>> >>>['', 'c:\\Python23', 'C:\\Apache\\Apache2\\htdocs\\python23.zip', >> >>The second entry above is from your PYTHONPATH environment variable. >>Note the capital P. This entry is not useful -- see the multiple >>occurrences of c:\\python23 below -- and may be causing some confusion. >>Get rid of it. >> >>The third entry is a mind-boggler. The remainder below is just weird. >>Here's what a plain vanilla Python 2.3 installation gives on my machine: >> >>C:\junk>c:\python23\python >>Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on >>win32 >>Type "help", "copyright", "credits" or "license" for more information. >> >>> import sys >> >>> sys.path >>['', 'c:\\python23\\python23.zip', 'C:\\junk', 'c:\\python23\\DLLs', >>'c:\\python23\\lib', 'c:\\python23\\lib\\plat-win', >>'c:\\python23\\lib\\lib-tk', 'c:\\python23', >>'c:\\python23\\lib\\site-packages'] >> >>Why are you using Python 2.3 at all instead of 2.4? You are not so >>constrained by Apache AFAICT. Why Python 2.3.3 and not 2.3.5?? >> >>The general impression is that your Python installation is close to FUBAR. >> >>Did you install Python 2.3 in the usual manner? What fiddling about have >>you been doing since? >> >>If you are trying to do mod_python with Apache under Windows, might it >>not be better asking on the modpython mailing list? >> >> >>>'c:\\python23', 'c:\\py >>>thon23\\Lib\\site-packages\\DLLs', 'c:\\python23', >>>'c:\\python23\\Lib\\site-packages\\lib >>>', 'c:\\python23', 'c:\\python23\\Lib\\site-packages\\lib\\plat-win', >>>'c:\\python23', 'c: >>>\\python23\\Lib\\site-packages\\lib\\lib-tk', 'C:\\Apache\\Apache2\\htdocs'] >>> >>> >>>Thanks for your response to my email. >>> >>>HL >>> >>>On 2/22/06, John Machin wrote: >>> >>> >>>>On 23/02/2006 11:53 AM, Heang Lim wrote: >>>> >>>> >>>>>I've installed Python on my c:\python23 directory and Apache on my >>>>>c:\Apache2 directory. On my DOS windows, I went to c:\Apache\htdocs >>>>>directory and enter 'python' to go into the interactive mode. When I >>>>>tried to import some modules such as 'import os' or 'import string', I >>>>>was getting 'ImportError: no module named os', etc. Am I missing some >>>>>sort of environment variable setting somewhere? I have my PYTHONPATH >>>>>system variable set to 'c:\python23'. >> >>No you don't; see above. >> >> >> >>>>do this: >>>>DOS-prompt>python >>>> >>>> >>>>>>>import sys >>>>>>>sys.path >>>> >>>>and show us the output (copy/paste). >>>> >>>> >>> >>> >>> >> > > From billburns at pennswoods.net Fri Feb 24 03:47:15 2006 From: billburns at pennswoods.net (Bill Burns) Date: Thu, 23 Feb 2006 21:47:15 -0500 Subject: [python-win32] Little tool - but very big size... :-( In-Reply-To: <43FADA47.3020905@mailpont.hu> References: <43FADA47.3020905@mailpont.hu> Message-ID: <43FE73B3.6020102@pennswoods.net> durumdara at mailpont.hu wrote: > Hi ! > > I have a problem. > I have a little tool that can get data about filesystems and I wrote it in > python. > > The main user asked me a GUI for this software. > > This user is needed a portable program, so I create this kind of the > software with Py2Exe. > > But it have very big size: 11 MB... :-( > I need to have more compressed result. Can I compress dll-s, pyd-s with > Py2Exe ? > Can I decrease the total size with something ? > > If not, how to I create an self-unpackager and self-starter program that > use an temporary directory in the disk ? With WinRar ? > > Thanx for help: > dd Hi dd, Take a look at Inno Setup. http://www.jrsoftware.org/isinfo.php I have program which has a 'dist' folder that is 19.2 MB. Using Inno Setup, I create a single file installer (setup.exe) which is compressed to 4.7 MB. You may want to take a look at NSIS as well (although, I've never used it). http://nsis.sourceforge.net/ Bill From mumarathe at gmail.com Sat Feb 25 03:40:19 2006 From: mumarathe at gmail.com (Manish Marathe) Date: Fri, 24 Feb 2006 18:40:19 -0800 Subject: [python-win32] building python on Windows In-Reply-To: <43FDF71C.2070406@probo.com> References: <43FDF71C.2070406@probo.com> Message-ID: <7c8a9a970602241840t6c022938oc4b485c72e39d65f@mail.gmail.com> On 2/23/06, Tim Roberts wrote: > > On Tue, 21 Feb 2006 18:28:46 -0800, "Manish Marathe" > wrote: > > >Python Experts everywhere!! > > > >I am trying to build python 2.4.1 on windows 2003 server using the MSVC > >files under src/PC/VC6. If I try to open the workspace pcbuild.dsw with > MS > >Visual C++ 6.0, it tries to login into Visual SourceSafe and asks for > login > >and password. I believe this shouldn't be the case. > > > > > Guys, Thanks for your inputs, althought I couldn't find mssccprj.scc files I could build Python 2.4.1 using msvc, so that got solved!! But some of my tests are failing like: test___all___ test_cookielib test_mailbox test_mimetools test_pyclbr Also this: ImportError: No module named _socket What do I have to resolve this? Appreciate your help -Manish -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20060224/e98550be/attachment.html From farzin_shakib at acusim.com Tue Feb 28 03:49:44 2006 From: farzin_shakib at acusim.com (Farzin Shakib) Date: Mon, 27 Feb 2006 18:49:44 -0800 Subject: [python-win32] list of child processes from pywin32 Message-ID: <4403BA48.2040306@acusim.com> Is there a way to get a list of all children of a process via pywin32? These would be all processes launched from calls like popen(), system() and QProcess(). Alternatively, is there a way to get the total CPU time (user and kernel) of all children of a python session? Note that os.times() does not work on Windows and on Linux it only post the children time when the children exit. From vince at weaktight.com Tue Feb 28 23:49:44 2006 From: vince at weaktight.com (vince at weaktight.com) Date: Tue, 28 Feb 2006 17:49:44 -0500 Subject: [python-win32] Windows "Browse to" message Message-ID: <20060228174944.of40lbf6ogw4okc4@webmail.weaktight.com> When you open an html file or click on a link outside of a browser, it opens it in your default browser. What I'd like to do is to catpure this message and grab the URL text string to see where the browser is going. I was looking at PyHook, but I don't think it intercepts all windows messages, and I'm not sure this is a windows message per se. Any suggestions? thanks.