From jchiang2 at ford.com Mon Oct 2 03:51:09 2006 From: jchiang2 at ford.com (Jim Chiang) Date: Sun, 1 Oct 2006 21:51:09 -0400 Subject: [python-win32] Picture.Insert, Excel issue Message-ID: <004601c6e5c5$3bc82bd0$0f1ea8c0@tc4200> I'm trying to very simply insert a picture from a file into an excel spreadsheet. I know how to do this in VBA and it works fine, however when I try this from python I get an error. Doing a search on this turned up nothing. The code I'm using is: from win32com.client.dynamic import Dispatch xl = Dispatch( 'Excel.Application' ) xl.Visible=1 xl.Workbooks.Add() xl.ActiveSheet.Pictures.Insert("C:\a.jpg") Traceback (most recent call last): File "", line 1, in xl.ActiveSheet.Pictures.Insert("C:\a.jpg") AttributeError: 'function' object has no attribute 'Insert' I'm not sure why I get this issue since 'ActiveSheet.Pictures.Insert("C:\a.jpg")' works fine from within Excel. Several internet posts from my searches also suggest to use this method. I've tried this on both Python 2.1 and 2.5 with the same results. Any idea what the problem is or how I can insert the picture?? TIA, Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061001/3e4a2549/attachment.htm From sjmachin at lexicon.net Mon Oct 2 05:14:15 2006 From: sjmachin at lexicon.net (John Machin) Date: Mon, 02 Oct 2006 13:14:15 +1000 Subject: [python-win32] Picture.Insert, Excel issue In-Reply-To: <004601c6e5c5$3bc82bd0$0f1ea8c0@tc4200> References: <004601c6e5c5$3bc82bd0$0f1ea8c0@tc4200> Message-ID: <45208407.6060504@lexicon.net> On 2/10/2006 11:51 AM, Jim Chiang wrote: > I?m trying to very simply insert a picture from a file into an excel > spreadsheet. I know how to do this in VBA and it works fine, however > when I try this from python I get an error. Doing a search on this > turned up nothing. > > The code I?m using is: > > from win32com.client.dynamic import Dispatch > > xl = Dispatch( 'Excel.Application' ) > > xl.Visible=1 > > xl.Workbooks.Add() > > xl.ActiveSheet.Pictures.Insert("C:\a.jpg") > > > > Traceback (most recent call last): > > File "", line 1, in > > xl.ActiveSheet.Pictures.Insert("C:\a.jpg") > > AttributeError: 'function' object has no attribute 'Insert' > > > > I?m not sure why I get this issue since > ?ActiveSheet.Pictures.Insert("C:\a.jpg")? works fine from within Excel. > Several internet posts from my searches also suggest to use this method. > > > > I?ve tried this on both Python 2.1 and 2.5 with the same results. > > Any idea what the problem is or how I can insert the picture?? Four problems: (1) VBA syntax instead of Python syntax (2) Not reading error message (3) Courting danger with backslashes in filenames (4) Courting danger keeping misc cruft in root directory Solution: xl.ActiveSheet.Pictures().Insert(r"C:\misc_cruft\a.jpg") HTH, John From smithbk at aecl.ca Mon Oct 2 22:23:40 2006 From: smithbk at aecl.ca (Smith, Brian (CR)) Date: Mon, 2 Oct 2006 16:23:40 -0400 Subject: [python-win32] Input-only vs. In/Out Function Parameters Message-ID: Hi, Just thought I'd bump this to see if I could get a response... Brian > > I am new to COM programming and have a question about function > parameters when implementing a COM object in Python. > > After reading "Python Programming on Win32", I have managed to create a > working COM object, where "working" is defined as "I can use it from > Excel VBA". > > I have a function like this: > > def func(self, in1, inout1, in2, inout2) > > where the in* parameters are input only and inout* are input and output. > At the end of the function I return an error code and new values for the > in/out parameters. I.e.: > > return( errorCode, new_inout1, new_inout2 ) > > This seems to work fine if it is called from VBA as > > errorCode = object.func( CONSTANT_1, var1, CONSTANT_2, var2 ) > > or > > errorCode = object.func( 42, var1, 7.4, var2 ) > > but it breaks if the VB program does this: > > c1 = CONSTANT_1 ' c1 is a previously declared variable > c2 = 7.4 ' c2 is a previously declared variable > errorCode = object.func( c1, var1, c2, var2 ) > > because c1 will then be assigned new_inout1 and var1 will be assigned > new_inout2, while c2 and var2 will not be assigned anything. > > Short of telling the VB programmer "Don't do that", how do I prevent > this problem? > > Thanks, > Brian CONFIDENTIAL AND PRIVILEGED INFORMATION NOTICE This e-mail, and any attachments, may contain information that is confidential, subject to copyright, or exempt from disclosure. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited. AVIS D'INFORMATION CONFIDENTIELLE ET PRIVIL?GI?E Le pr?sent courriel, et toute pi?ce jointe, peut contenir de l'information qui est confidentielle, r?gie par les droits d'auteur, ou interdite de divulgation. Tout examen, divulgation, retransmission, diffusion ou autres utilisations non autoris?es de l'information ou d?pendance non autoris?e envers celle-ci peut ?tre ill?gale et est strictement interdite. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061002/d224b33b/attachment.html From timr at probo.com Mon Oct 2 23:21:06 2006 From: timr at probo.com (Tim Roberts) Date: Mon, 02 Oct 2006 14:21:06 -0700 Subject: [python-win32] Input-only vs. In/Out Function Parameters In-Reply-To: References: Message-ID: <452182C2.5000205@probo.com> Smith, Brian (CR) wrote: >> > > I am new to COM programming and have a question about function > > parameters when implementing a COM object in Python. > > > > After reading "Python Programming on Win32", I have managed to create a > > working COM object, where "working" is defined as "I can use it from > > Excel VBA". > > > > I have a function like this: > > > > def func(self, in1, inout1, in2, inout2) > > ... > > but it breaks if the VB program does this: > > > > c1 = CONSTANT_1 ' c1 is a previously declared variable > > c2 = 7.4 ' c2 is a previously declared variable > > errorCode = object.func( c1, var1, c2, var2 ) > > > > because c1 will then be assigned new_inout1 and var1 will be assigned > > new_inout2, while c2 and var2 will not be assigned anything. > > > > Short of telling the VB programmer "Don't do that", how do I prevent > > this problem? Tell the VBA programmer "Don't do that". Or, rearrange the parameters so that the inout arguments are always first. This very same question came up on this list in June, and I actually spent quite a bit of time trying to chase down documentation of this restriction. Surprisingly enough, the "fault" here is not actually in Python: it's in the late binding handler in VBA. If you do this same thing from a VB app and look at the generated IL code, it is the IL that is assigning the outputs to the wrong place. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From smithbk at aecl.ca Tue Oct 3 15:44:03 2006 From: smithbk at aecl.ca (Smith, Brian (CR)) Date: Tue, 3 Oct 2006 09:44:03 -0400 Subject: [python-win32] Input-only vs. In/Out Function Parameters Message-ID: Hi Tim, Thanks for the response. > Tell the VBA programmer "Don't do that". Or, rearrange the parameters > so that the inout arguments are always first. Okay, I was afraid that would be the answer. I don't particularly like the first option because simply telling someone not to do something is no guarantee that they won't do it anyway. I was trying to avoid the second option since I am replacing an existing API and had hoped to be consistent with that. However, it seems to be the safer choice. > This very same question came up on this list in June, and I actually > spent quite a bit of time trying to chase down documentation of this > restriction. Surprisingly enough, the "fault" here is not actually in > Python: it's in the late binding handler in VBA. If you do this same > thing from a VB app and look at the generated IL code, it is > the IL that is assigning the outputs to the wrong place. After doing some searching on the web, I had (naively?) thought perhaps the answer might be creating a type library that defines the interface. I had gone as far as installing the Windows Platform SDK so I could use midl to compile the library, but ran into a problem because it was looking for a C-preprocessor (cl.exe) that I don't have. Am I going down the wrong path with this or would it actually help? Thanks, Brian CONFIDENTIAL AND PRIVILEGED INFORMATION NOTICE This e-mail, and any attachments, may contain information that is confidential, subject to copyright, or exempt from disclosure. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited. AVIS D'INFORMATION CONFIDENTIELLE ET PRIVIL?GI?E Le pr?sent courriel, et toute pi?ce jointe, peut contenir de l'information qui est confidentielle, r?gie par les droits d'auteur, ou interdite de divulgation. Tout examen, divulgation, retransmission, diffusion ou autres utilisations non autoris?es de l'information ou d?pendance non autoris?e envers celle-ci peut ?tre ill?gale et est strictement interdite. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061003/264277a5/attachment.htm From msherman77 at yahoo.com Tue Oct 3 17:33:09 2006 From: msherman77 at yahoo.com (Michael S) Date: Tue, 3 Oct 2006 11:33:09 -0400 (EDT) Subject: [python-win32] MS Word Message-ID: <20061003153309.81632.qmail@web88303.mail.re4.yahoo.com> Good day all. Does anyone have experience in appending multiple word file into one big file? I have a directory full of word files and I want to make one file out of all of them. I tried to google it, in order at least to see it how it's done in VBA, but haven't found any good examples. Michael From timr at probo.com Tue Oct 3 18:28:38 2006 From: timr at probo.com (Tim Roberts) Date: Tue, 03 Oct 2006 09:28:38 -0700 Subject: [python-win32] Input-only vs. In/Out Function Parameters In-Reply-To: References: Message-ID: <45228FB6.9010800@probo.com> Smith, Brian (CR) wrote: > > After doing some searching on the web, I had (naively?) thought perhaps > the answer might be creating a type library that defines the interface. > I had gone as far as installing the Windows Platform SDK so I could use > midl to compile the library, but ran into a problem because it was > looking for a C-preprocessor (cl.exe) that I don't have. Am I going down > the wrong path with this or would it actually help? I don't honestly know. I'm dubious that it will help, because no matter how you describe it, a Python COM server must ALWAYS be called with late binding. You can get cl.exe by downloading the Visual Studio 2005 Express Edition from Microsoft -- it's free. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gagsl-p32 at yahoo.com.ar Tue Oct 3 21:59:57 2006 From: gagsl-p32 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 03 Oct 2006 16:59:57 -0300 Subject: [python-win32] MS Word In-Reply-To: <20061003153309.81632.qmail@web88303.mail.re4.yahoo.com> References: <20061003153309.81632.qmail@web88303.mail.re4.yahoo.com> Message-ID: <7.0.1.0.0.20061003165711.00fd09f0@yahoo.com.ar> At Tuesday 3/10/2006 12:33, Michael S wrote: >Does anyone have experience in appending multiple word >file into one big file? I have a directory full of >word files and I want to make one file out of all of >them. >I tried to google it, in order at least to see it how >it's done in VBA, but haven't found any good examples. I usually create a macro for doing what I want, and then I inspect the VBA code to see how it's done. Gabriel Genellina Softlab SRL __________________________________________________ Pregunt?. Respond?. Descubr?. Todo lo que quer?as saber, y lo que ni imaginabas, est? en Yahoo! Respuestas (Beta). ?Probalo ya! http://www.yahoo.com.ar/respuestas From bwmetz at att.com Wed Oct 4 01:59:40 2006 From: bwmetz at att.com (Metz, Bobby W, WWCS) Date: Tue, 3 Oct 2006 18:59:40 -0500 Subject: [python-win32] MS Word In-Reply-To: <20061003153309.81632.qmail@web88303.mail.re4.yahoo.com> Message-ID: <01D5341D04A2E64AB9B34576904733670291DA5D@OCCLUST01EVS1.ugd.att.com> I suggest the following. It may not be the prettiest, but it's very simple. Create new doc... Documents.Add DocumentType:=wdNewBlankDocument ActiveDocument.SaveAs FileName:="Combined.doc", FileFormat:= _ wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _ True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _ False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False For each old doc (generate list of filenames however you want) Documents.Open FileName:="""Filename #1.doc""" _ , ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _ wdOpenFormatAuto Selection.WholeStory Selection.Copy Windows("Combined.doc").Activate Selection.Paste ' Insert page break between doc pages to prevent last page/first page combination if desired Selection.InsertBreak Type:=wdPageBreak Windows("Filename #1.doc").Close When done, save the combined file ActiveDocument.SaveAs FileName:="Combined.doc", FileFormat:= _ wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _ True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _ False, SaveNativePictureFormat:=False, SaveFormsData:=False, _ SaveAsAOCELetter:=False -----Original Message----- From: python-win32-bounces+bwmetz=att.com at python.org [mailto:python-win32-bounces+bwmetz=att.com at python.org]On Behalf Of Michael S Sent: Tuesday, October 03, 2006 8:33 AM To: python-win32 at python.org Subject: [python-win32] MS Word Good day all. Does anyone have experience in appending multiple word file into one big file? I have a directory full of word files and I want to make one file out of all of them. I tried to google it, in order at least to see it how it's done in VBA, but haven't found any good examples. Michael _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From mc at mclaveau.com Wed Oct 4 07:31:03 2006 From: mc at mclaveau.com (Michel Claveau) Date: Wed, 4 Oct 2006 07:31:03 +0200 Subject: [python-win32] MS Word References: <20061003153309.81632.qmail@web88303.mail.re4.yahoo.com> Message-ID: <000201c6e776$4baf88b0$0701a8c0@PORTABLES> Hi! Try: win32com.client.Dispatch('Word.Application')... ...Selection.InsertFile(fichierWord) @-salutations -- Michel Claveau From smithbk at aecl.ca Wed Oct 4 22:09:49 2006 From: smithbk at aecl.ca (Smith, Brian (CR)) Date: Wed, 4 Oct 2006 16:09:49 -0400 Subject: [python-win32] Input-only vs. In/Out Function Parameters Message-ID: > > After doing some searching on the web, I had (naively?) thought perhaps > > the answer might be creating a type library that defines the interface. > > ... > > Am I going down the wrong path with this or would it actually help? > > I don't honestly know. I'm dubious that it will help, because no matter > how you describe it, a Python COM server must ALWAYS be called with late > binding. Creating a type library for my COM server seems to have fixed the problem. After setting up VBA to use the type library (Tools->References...), I can now use either variables or constants for the input-only parameters and the input/output parameters are still set correctly. However, there are some side effects: 1) When using the COM server without the type library, I was returning a tuple with the return value of the function (in my case, an error code) as the first element. With the type library, this value must be the last element (because the [out, retval] parameter in the IDL file must be last to prevent a compile error?). Not a big deal but it does mean going through the existing code and making sure I have the returned values in the right order. 2) VBA was giving me an error like "Expecting 3 return values, got: 2" whenever a function contained an [in, out] parameter. It looks like the extra parameter it is looking for is the HRESULT signifying the success of the call itself, because if I insert a 0 at the beginning of my returned tuple the problem goes away but any other value causes an error saying the method call failed. I'm guessing this is an error in my code, because I don't think I'm supposed to be setting this value myself. Any hints as to why I would be getting this error? I've appended the code I am using for my tests. To register the type library and COM server, I use the same code found in the pippo_server.py example that is distributed with Python-win32. --------- IDL File Begin --------- // TestLib.idl : IDL source for a COM object testing the type library // import "oaidl.idl"; import "ocidl.idl"; [ object, uuid(51B3EE2D-8759-4117-BF94-ACD1AAAD8553) ] interface ITestLib : IUnknown { HRESULT Method1([in] long in1, [in, out] long *inout1, [in] long in2, [in, out] long *inout2, [out, retval] long *val); HRESULT Method2([out, retval] long *val); HRESULT Method3([in] long in1, [out, retval] long *val); HRESULT Method4([in] long in1, [in, out] long *inout1, [out, retval] long *val); [propget]HRESULT MyProp1([out, retval] long *pVal); [propput]HRESULT MyProp1([in] long pVal); [propget]HRESULT TESTLIB_CONSTANT([out, retval] long *pVal); }; [ uuid(AA8220B6-69FE-4e3d-827F-06A6A63B5887), version(1.0), helpstring("TestLibServer 1.0 Type Library") ] library LibTest { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(5A1B4C64-4C93-434c-8DC4-432667EB58FA), helpstring("TestLib Class") ] coclass Server { [default] interface ITestLib; }; }; --------- IDL File End --------- --------- Python Code Begin --------- class CTestLib: # # COM declarations # _reg_clsid_ = "{05AC1CCE-3F9B-4d9a-B0B5-DFE8BE45AFA8}" _reg_desc_ = "Type Library Test Server" _reg_progid_ = "LibTest.Server" ### Link to typelib _typelib_guid_ = '{AA8220B6-69FE-4e3d-827F-06A6A63B5887}' _typelib_version_ = 1, 0 _com_interfaces_ = ['ITestLib'] TESTLIB_CONSTANT = 13 def __init__(self): self.MyProp1 = 10 def Method1(self, in1, inout1, in2, inout2 ): retVal = 0 if( in1 != 0 ): new_inout1 = in1 * 10 new_inout2 = in2 * 10 else: retVal = -1 new_inout1 = inout1 new_inout2 = inout2 return( 0, new_inout1, new_inout2, retVal ) def Method2(self): retVal = -11 return( retVal ) def Method3(self, in1): retVal = -21 return( retVal ) def Method4(self, in1, inout1): new_inout1 = -31 retVal = -41 return( 0, new_inout1, retVal ) --------- Python Code End --------- CONFIDENTIAL AND PRIVILEGED INFORMATION NOTICE This e-mail, and any attachments, may contain information that is confidential, subject to copyright, or exempt from disclosure. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited. AVIS D'INFORMATION CONFIDENTIELLE ET PRIVIL?GI?E Le pr?sent courriel, et toute pi?ce jointe, peut contenir de l'information qui est confidentielle, r?gie par les droits d'auteur, ou interdite de divulgation. Tout examen, divulgation, retransmission, diffusion ou autres utilisations non autoris?es de l'information ou d?pendance non autoris?e envers celle-ci peut ?tre ill?gale et est strictement interdite. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061004/60244585/attachment.htm From mhammond at skippinet.com.au Thu Oct 5 01:24:53 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 5 Oct 2006 09:24:53 +1000 Subject: [python-win32] Input-only vs. In/Out Function Parameters In-Reply-To: Message-ID: <441401c6e80c$4e7bddf0$050a0a0a@enfoldsystems.local> > 2) VBA was giving me an error like "Expecting 3 return values, got: 2" > whenever a function contained an [in, out] parameter. It looks like the > extra parameter it is looking for is the HRESULT signifying the success of There should be no need to return a HRESULT - but note that the nominated return value must be the *first* value returned, with [out] params following in the order they were declared. As a result, method4 really should only need 2 return values - I'm not sure why it seems to want more. If you can provide a patch to the pippo sample that demonstrates your problem I can dig deeper. Mark From smithbk at aecl.ca Thu Oct 5 15:45:49 2006 From: smithbk at aecl.ca (Smith, Brian (CR)) Date: Thu, 5 Oct 2006 09:45:49 -0400 Subject: [python-win32] Input-only vs. In/Out Function Parameters Message-ID: Hi Mark, > > 2) VBA was giving me an error like "Expecting 3 return values, got: 2" > > whenever a function contained an [in, out] parameter. It looks like the > > extra parameter it is looking for is the HRESULT signifying the success of > > There should be no need to return a HRESULT - but note that the nominated > return value must be the *first* value returned, with [out] params following > in the order they were declared. That's what I would have expected. In fact, this is the case if I don't use a type library. However, when using a type library I have to return it *last* for the object to work from VBA. > As a result, method4 really should only need 2 return values - I'm not sure > why it seems to want more. If you can provide a patch to the pippo sample > that demonstrates your problem I can dig deeper. The patches are below. I added two methods with the same signature. The difference is that Method2() returns two values (as the IDL signature would suggest) and Method3() returns 3 values, with a 0 as the first value. My VBA test code (also attached) calls Method3() first and correctly sets inout1 to -31 and the return value to -41. Note that this occurs even though the nominated return value is the *last* return value. The call to Method2() fails with the "Expecting 3 return values, got: 2" error. My platform is Win XP Pro (SP2), Python 2.3.4, pywin Build 210. I'm testing using VBA in MS Excel 2000. Thanks, Brian ---- pippo.idl patch begin ---- 32a33,36 > [id(3), helpstring("method Method2")] HRESULT Method2([in] long in1, [in, out] long *inout1, > [out, retval] long *val); > [id(4), helpstring("method Method3")] HRESULT Method3([in] long in1, [in, out] long *inout1, > [out, retval] long *val); ---- pippo.idl patch end ---- ---- pippo_server.py patch begin ---- 35a36,45 > def Method2(self, in1, inout1): > new_inout1 = -31 > retVal = -41 > return( new_inout1, retVal ) > > def Method3(self, in1, inout1): > new_inout1 = -31 > retVal = -41 > return( 0, new_inout1, retVal ) > ---- pippo_server.py patch end ---- ---- VBA test code begin ---- Sub TestPippo() Dim obj As Pippo Dim in1 As Long Dim inout1 As Long Dim before As String Dim after As String Set obj = CreateObject("Python.Test.Pippo") in1 = 3 inout1 = 5 before = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1) retVal = obj.Method3(in1, inout1) after = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1) + ", retVal = " + CStr(retVal) MsgBox before + vbCrLf + after, , "Testing Method3" in1 = 3 inout1 = 5 before = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1) retVal = obj.Method2(in1, inout1) after = "in1 = " + CStr(in1) + ", inout1 = " + CStr(inout1) + ", retVal = " + CStr(retVal) MsgBox before + vbCrLf + after, , "Testing Method2" Set obj = Nothing End Sub ---- VBA test code end ---- CONFIDENTIAL AND PRIVILEGED INFORMATION NOTICE This e-mail, and any attachments, may contain information that is confidential, subject to copyright, or exempt from disclosure. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited. AVIS D'INFORMATION CONFIDENTIELLE ET PRIVIL?GI?E Le pr?sent courriel, et toute pi?ce jointe, peut contenir de l'information qui est confidentielle, r?gie par les droits d'auteur, ou interdite de divulgation. Tout examen, divulgation, retransmission, diffusion ou autres utilisations non autoris?es de l'information ou d?pendance non autoris?e envers celle-ci peut ?tre ill?gale et est strictement interdite. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061005/39191d78/attachment.html From jim at qlf.com Thu Oct 5 23:16:15 2006 From: jim at qlf.com (Jim Steil) Date: Thu, 5 Oct 2006 16:16:15 -0500 Subject: [python-win32] Excel win32com newbie question Message-ID: <006f01c6e8c3$7e390290$800101df@qlf.local> I've been working this week building some Excel spreadsheets using Python and win32com. I am not having any trouble getting my sheets built with the proper data in the proper cells, but I'm having a heck of a time trying to find out how I can format my cells to make it look nicer. I want to set it so most of the columns will resize themselves to the proper width and I would like to adjust the alignment of some columns. I've browsed through the last years worth of archives on this mailing list and searched the web extensively but can't seem to find how to get it to work. I've come across numerous examples of how to do some things, but they don't seem to work on my machine. Possibly my biggest problem is that I can't get my machine to give me the Excel constants. Here is the code I'm doing to try to test the constants and the error I'm getting back. from win32com.client import constants, Dispatch x = constants.xlHAlignRight Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 168, in __getattr__ raise AttributeError, a AttributeError: xlHAlignRight I'm hoping there is something obvious that I'm missing. I think I can find my way through the rest of my issues if I can just get by this constants problem. Thanks for any help you can provide. -Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061005/f2baca12/attachment.html From sjmachin at lexicon.net Fri Oct 6 01:03:31 2006 From: sjmachin at lexicon.net (John Machin) Date: Fri, 06 Oct 2006 09:03:31 +1000 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <006f01c6e8c3$7e390290$800101df@qlf.local> References: <006f01c6e8c3$7e390290$800101df@qlf.local> Message-ID: <45258F43.1070905@lexicon.net> On 6/10/2006 7:16 AM, Jim Steil wrote: > I?ve been working this week building some Excel spreadsheets using > Python and win32com. I am not having any trouble getting my sheets > built with the proper data in the proper cells, but I?m having a heck of > a time trying to find out how I can format my cells to make it look > nicer. I want to set it so most of the columns will resize themselves > to the proper width and I would like to adjust the alignment of some > columns. I?ve browsed through the last years worth of archives on this > mailing list and searched the web extensively but can?t seem to find how > to get it to work. I?ve come across numerous examples of how to do some > things, but they don?t seem to work on my machine. > > > > Possibly my biggest problem is that I can?t get my machine to give me > the Excel constants. Here is the code I?m doing to try to test the > constants and the error I?m getting back. > > > > from win32com.client import constants, Dispatch > > > > x = constants.xlHAlignRight > > Traceback (most recent call last): > > File "", line 1, in ? > > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line > 168, in __getattr__ > > raise AttributeError, a > > AttributeError: xlHAlignRight > > > > I?m hoping there is something obvious that I?m missing. I think I can > find my way through the rest of my issues if I can just get by this > constants problem. Thanks for any help you can provide. > The constants module is a little bit more dynamic than one would normally expect: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from win32com.client import Dispatch, constants >>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') Bzzzzt! >>> app = Dispatch('Excel.Application') >>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') -4152 >>> HTH, John From timr at probo.com Fri Oct 6 01:05:57 2006 From: timr at probo.com (Tim Roberts) Date: Thu, 05 Oct 2006 16:05:57 -0700 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <006f01c6e8c3$7e390290$800101df@qlf.local> References: <006f01c6e8c3$7e390290$800101df@qlf.local> Message-ID: <45258FD5.9050307@probo.com> Jim Steil wrote: > I?ve been working this week building some Excel spreadsheets using > Python and win32com. ... > > Possibly my biggest problem is that I can?t get my machine to give me > the Excel constants. Here is the code I?m doing to try to test the > constants and the error I?m getting back. > > from win32com.client import constants, Dispatch > > x = constants.xlHAlignRight > > Traceback (most recent call last): > > File "", line 1, in ? > > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line > 168, in __getattr__ > > raise AttributeError, a > > AttributeError: xlHAlignRight > > I?m hoping there is something obvious that I?m missing. I think I can > find my way through the rest of my issues if I can just get by this > constants problem. Thanks for any help you can provide. > Did you run "makepy.py" on the Microsoft Excel Object Library? "makepy" is the one that extracts the constants. Alternatively, you can replace x = win32com.client.Dispatch("Excel.Application") with x = win32com.client.gencache.EnsureDispatch("Excel.Application") That runs the "makepy" process, which makes the constants available: 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. >>> import win32com.client >>> x = win32com.client.Dispatch("Excel.Application") >>> from win32com.client import constants >>> constants.xlHAlignRight Traceback (most recent call last): File "", line 1, in ? File "c:\apps\python24\lib\site-packages\win32com\client\__init__.py", line 18, in __getattr__ raise AttributeError, a AttributeError: xlHAlignRight 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. >>> import win32com.client >>> x = win32com.client.gencache.EnsureDispatch("Excel.Application") >>> from win32com.client import constants >>> constants.xlHAlignRight -4152 >>> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cyril.giraudon at free.fr Fri Oct 6 14:55:43 2006 From: cyril.giraudon at free.fr (cyril giraudon) Date: Fri, 06 Oct 2006 14:55:43 +0200 Subject: [python-win32] Flicker and OnEraseBkgnd Message-ID: <4526524F.5010001@free.fr> Hi, I currently try to add a matplotlib backend based on the Gecko engine (XPCOM, plugin), PIL and pywin. I simply build a new window and place it in the plugin area as a child. All works fine, bur when I change the size of the window, there is a flicker . I 've read some pages on the web, but I don't see how to adapt the solutions with python. Precisely, i can't overwrite the OnResizeBkgnd often spotted in articles. Is there any solutions ? Thanks a lot, Cyril. Below some lines of my code. window_id is the HWND of the plugin window. from PIL import Image from PIL import ImageWin import matplotlib from matplotlib.backends.backend_agg import FigureCanvasAgg from matplotlib.backends.backend_agg import RendererAgg from matplotlib.axes import Subplot from matplotlib.figure import Figure from matplotlib.numerix import arange, sin, pi import win32ui import win32api import win32con import win32gui import winxpgui wc = win32gui.WNDCLASS() wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.lpfnWndProc = wndProc wc.cbWndExtra = 0; hinst = wc.hInstance = win32api.GetModuleHandle(None) wc.hIcon = 0 wc.hbrBackground = win32con.NULL wc.lpszMenuName = "" wc.lpszClassName = "cmgui_embed_wndclass" classAtom = win32gui.RegisterClass(wc) self.hwnd = win32gui.CreateWindow(classAtom, "",\ win32con.WS_CHILD | win32con.WS_VISIBLE, 0, 0, \ width, height, window_id, 0, hinst, None) fig = Figure(figsize=(5,4), dpi=100) a = fig.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) a.plot(t,s) dpival = fig.dpi.get() winch = width/dpival hinch = height/dpival fig.set_figsize_inches(winch, hinch) self.canvas = FigureCanvasAgg(fig) self.canvas.renderer = RendererAgg(width, height, fig.dpi) self.canvas.draw() image = Image.frombuffer('RGBA', self.canvas.get_width_height(), self.canvas.buffer_rgba(0,0)) self.dib = ImageWin.Dib(image) z = ImageWin.HWND(hwnd) self.dib.expose(z) def wndProc(self, hwnd, message, wParam, lParam): if message == win32con.WM_PAINT: hdc, paintStruct = win32gui.BeginPaint(hwnd) self.canvas.draw() image = Image.frombuffer('RGBA', self.canvas.get_width_height(), self.canvas.buffer_rgba(0,0)) image = image.transpose(Image.FLIP_TOP_BOTTOM) dib = ImageWin.Dib(image) z = ImageWin.HWND(self.hwnd) dib.expose(z) win32gui.EndPaint(hwnd, paintStruct) return 0 elif message == win32con.WM_NCPAINT: return 1 elif message == win32con.WM_ERASEBKGND: return 1 elif message == win32con.WM_SIZE: pass def resize_canvas( self, width, height): return win32gui.SetWindowPos(self.hwnd, win32con.HWND_TOP, 0, 0, width, height,\ win32con.SWP_SHOWWINDOW) fig = self.canvas.figure dpival = fig.dpi.get() winch = width/dpival hinch = height/dpival fig.set_figsize_inches(winch, hinch) self.canvas.draw() image = Image.frombuffer('RGBA', self.canvas.get_width_height(), self.canvas.buffer_rgba(0,0)) image = image.transpose(Image.FLIP_TOP_BOTTOM) dib = ImageWin.Dib(image) z = ImageWin.HWND(self.hwnd) dib.expose(z) From jim at qlf.com Fri Oct 6 15:30:48 2006 From: jim at qlf.com (Jim Steil) Date: Fri, 6 Oct 2006 08:30:48 -0500 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <45258FD5.9050307@probo.com> Message-ID: <00a701c6e94b$a2c905a0$800101df@qlf.local> Thanks for the response! I tried your suggestion with the following results.... >>> import win32com.client >>> x = win32com.client.gencache.EnsureDispatch("Excel.Application") Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line 536, in EnsureDispatch mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand) File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line 393, in EnsureModule module = GetModuleForTypelib(typelibCLSID, lcid, major, minor) File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line 258, in GetModuleForTypelib mod = _GetModule(modName) File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line 629, in _GetModule mod = __import__(mod_name) File "C:\Python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00000 0000046x0x1x5\__init__.py", line 1748 '{000208C8-0001-0000-C000-000000000046}' : 'IWalls', '{000208C9-0001-0000-C000-000000000046}' : 'ITickLabels', ^ SyntaxError: invalid syntax >>> Any ideas from here? -Jim -----Original Message----- From: python-win32-bounces+jim=qlf.com at python.org [mailto:python-win32-bounces+jim=qlf.com at python.org] On Behalf Of Tim Roberts Sent: Thursday, October 05, 2006 6:06 PM To: Python-Win32 List Subject: Re: [python-win32] Excel win32com newbie question Jim Steil wrote: > I've been working this week building some Excel spreadsheets using > Python and win32com. ... > > Possibly my biggest problem is that I can't get my machine to give me > the Excel constants. Here is the code I'm doing to try to test the > constants and the error I'm getting back. > > from win32com.client import constants, Dispatch > > x = constants.xlHAlignRight > > Traceback (most recent call last): > > File "", line 1, in ? > > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line > 168, in __getattr__ > > raise AttributeError, a > > AttributeError: xlHAlignRight > > I'm hoping there is something obvious that I'm missing. I think I can > find my way through the rest of my issues if I can just get by this > constants problem. Thanks for any help you can provide. > Did you run "makepy.py" on the Microsoft Excel Object Library? "makepy" is the one that extracts the constants. Alternatively, you can replace x = win32com.client.Dispatch("Excel.Application") with x = win32com.client.gencache.EnsureDispatch("Excel.Application") That runs the "makepy" process, which makes the constants available: 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. >>> import win32com.client >>> x = win32com.client.Dispatch("Excel.Application") >>> from win32com.client import constants >>> constants.xlHAlignRight Traceback (most recent call last): File "", line 1, in ? File "c:\apps\python24\lib\site-packages\win32com\client\__init__.py", line 18, in __getattr__ raise AttributeError, a AttributeError: xlHAlignRight 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. >>> import win32com.client >>> x = win32com.client.gencache.EnsureDispatch("Excel.Application") >>> from win32com.client import constants >>> constants.xlHAlignRight -4152 >>> -- 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 jim at qlf.com Fri Oct 6 15:34:07 2006 From: jim at qlf.com (Jim Steil) Date: Fri, 6 Oct 2006 08:34:07 -0500 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <45258F43.1070905@lexicon.net> Message-ID: <00a801c6e94c$19330c40$800101df@qlf.local> Thanks for your response too! Unfortunately, I must have something messed up here because this didn't work either. >>> from win32com.client import Dispatch, constants >>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') Bzzzzt! >>> app = Dispatch('Excel.Application') >>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') Bzzzzt! I tried running the makepy.py on the Excell 11.0 Object library and that fails on me as well. Any suggestions? -Jim -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Thursday, October 05, 2006 6:04 PM To: Jim Steil Cc: python-win32 at python.org Subject: Re: [python-win32] Excel win32com newbie question On 6/10/2006 7:16 AM, Jim Steil wrote: > I've been working this week building some Excel spreadsheets using > Python and win32com. I am not having any trouble getting my sheets > built with the proper data in the proper cells, but I'm having a heck of > a time trying to find out how I can format my cells to make it look > nicer. I want to set it so most of the columns will resize themselves > to the proper width and I would like to adjust the alignment of some > columns. I've browsed through the last years worth of archives on this > mailing list and searched the web extensively but can't seem to find how > to get it to work. I've come across numerous examples of how to do some > things, but they don't seem to work on my machine. > > > > Possibly my biggest problem is that I can't get my machine to give me > the Excel constants. Here is the code I'm doing to try to test the > constants and the error I'm getting back. > > > > from win32com.client import constants, Dispatch > > > > x = constants.xlHAlignRight > > Traceback (most recent call last): > > File "", line 1, in ? > > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line > 168, in __getattr__ > > raise AttributeError, a > > AttributeError: xlHAlignRight > > > > I'm hoping there is something obvious that I'm missing. I think I can > find my way through the rest of my issues if I can just get by this > constants problem. Thanks for any help you can provide. > The constants module is a little bit more dynamic than one would normally expect: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from win32com.client import Dispatch, constants >>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') Bzzzzt! >>> app = Dispatch('Excel.Application') >>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') -4152 >>> HTH, John From sjmachin at lexicon.net Fri Oct 6 17:51:55 2006 From: sjmachin at lexicon.net (John Machin) Date: Sat, 07 Oct 2006 01:51:55 +1000 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <00a801c6e94c$19330c40$800101df@qlf.local> References: <00a801c6e94c$19330c40$800101df@qlf.local> Message-ID: <45267B9B.8090201@lexicon.net> On 6/10/2006 11:34 PM, Jim Steil wrote: > Thanks for your response too! Unfortunately, I must have something messed > up here because this didn't work either. > >>>> from win32com.client import Dispatch, constants >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! >>>> app = Dispatch('Excel.Application') >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! Yeah well silly me for presuming you had run makepy :-) > > I tried running the makepy.py on the Excell 11.0 Object library and that > fails on me as well. Any suggestions? Tell us a few things you should have supplied w/o being asked: (1) what version of Python (2.4.what??) (2) what pywin32 build number (3) copy/paste of result when you ran makepy If the makepy gives you a weird syntax error (like the syntax error you showed in the response to Tim Roberts), that could be an old bug (in Python, I believe). Ensure that you have Python 2.4.3, and the latest build of pywin32, and try it again. IIRC, the workaround involved editing the file with the syntax error, adding a few spaces to the end of the allegedly offending line, and one or two lines before that. HTH, John From jim at qlf.com Fri Oct 6 18:58:49 2006 From: jim at qlf.com (Jim Steil) Date: Fri, 6 Oct 2006 11:58:49 -0500 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <45267B9B.8090201@lexicon.net> Message-ID: <002601c6e968$b1ba1230$800101df@qlf.local> Python 2.4.1 Pywin23 2.10 I'm in the process of upgrading my python to 2.4.3, will send a follow-up after I'm done testing. Thanks! -Jim Jim Steil IT Manager Quality Liquid Feeds (608) 935-2345 (608) 341-9896 cell -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Friday, October 06, 2006 10:52 AM To: Jim Steil Cc: python-win32 at python.org Subject: Re: [python-win32] Excel win32com newbie question On 6/10/2006 11:34 PM, Jim Steil wrote: > Thanks for your response too! Unfortunately, I must have something messed > up here because this didn't work either. > >>>> from win32com.client import Dispatch, constants >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! >>>> app = Dispatch('Excel.Application') >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! Yeah well silly me for presuming you had run makepy :-) > > I tried running the makepy.py on the Excell 11.0 Object library and that > fails on me as well. Any suggestions? Tell us a few things you should have supplied w/o being asked: (1) what version of Python (2.4.what??) (2) what pywin32 build number (3) copy/paste of result when you ran makepy If the makepy gives you a weird syntax error (like the syntax error you showed in the response to Tim Roberts), that could be an old bug (in Python, I believe). Ensure that you have Python 2.4.3, and the latest build of pywin32, and try it again. IIRC, the workaround involved editing the file with the syntax error, adding a few spaces to the end of the allegedly offending line, and one or two lines before that. HTH, John From jim at qlf.com Fri Oct 6 19:08:21 2006 From: jim at qlf.com (Jim Steil) Date: Fri, 6 Oct 2006 12:08:21 -0500 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <002601c6e968$b1ba1230$800101df@qlf.local> Message-ID: <000801c6e96a$06ab1b80$800101df@qlf.local> Oops, obvious typo on the pywin23 below. Should be pywin32. -Jim -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Jim Steil Sent: Friday, October 06, 2006 11:59 AM To: 'John Machin' Cc: python-win32 at python.org Subject: Re: [python-win32] Excel win32com newbie question Python 2.4.1 Pywin23 2.10 I'm in the process of upgrading my python to 2.4.3, will send a follow-up after I'm done testing. Thanks! -Jim Jim Steil IT Manager Quality Liquid Feeds (608) 935-2345 (608) 341-9896 cell -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Friday, October 06, 2006 10:52 AM To: Jim Steil Cc: python-win32 at python.org Subject: Re: [python-win32] Excel win32com newbie question On 6/10/2006 11:34 PM, Jim Steil wrote: > Thanks for your response too! Unfortunately, I must have something messed > up here because this didn't work either. > >>>> from win32com.client import Dispatch, constants >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! >>>> app = Dispatch('Excel.Application') >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! Yeah well silly me for presuming you had run makepy :-) > > I tried running the makepy.py on the Excell 11.0 Object library and that > fails on me as well. Any suggestions? Tell us a few things you should have supplied w/o being asked: (1) what version of Python (2.4.what??) (2) what pywin32 build number (3) copy/paste of result when you ran makepy If the makepy gives you a weird syntax error (like the syntax error you showed in the response to Tim Roberts), that could be an old bug (in Python, I believe). Ensure that you have Python 2.4.3, and the latest build of pywin32, and try it again. IIRC, the workaround involved editing the file with the syntax error, adding a few spaces to the end of the allegedly offending line, and one or two lines before that. HTH, John _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From jim at qlf.com Fri Oct 6 19:18:02 2006 From: jim at qlf.com (Jim Steil) Date: Fri, 6 Oct 2006 12:18:02 -0500 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <002601c6e968$b1ba1230$800101df@qlf.local> Message-ID: <001e01c6e96b$60c89b50$800101df@qlf.local> Wow, what a difference all the correct versions make. That fixed my problem. Thanks for all the help! -Jim -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Jim Steil Sent: Friday, October 06, 2006 11:59 AM To: 'John Machin' Cc: python-win32 at python.org Subject: Re: [python-win32] Excel win32com newbie question Python 2.4.1 Pywin23 2.10 I'm in the process of upgrading my python to 2.4.3, will send a follow-up after I'm done testing. Thanks! -Jim -----Original Message----- From: John Machin [mailto:sjmachin at lexicon.net] Sent: Friday, October 06, 2006 10:52 AM To: Jim Steil Cc: python-win32 at python.org Subject: Re: [python-win32] Excel win32com newbie question On 6/10/2006 11:34 PM, Jim Steil wrote: > Thanks for your response too! Unfortunately, I must have something messed > up here because this didn't work either. > >>>> from win32com.client import Dispatch, constants >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! >>>> app = Dispatch('Excel.Application') >>>> print getattr(constants, 'xlHAlignRight', 'Bzzzzt!') > Bzzzzt! Yeah well silly me for presuming you had run makepy :-) > > I tried running the makepy.py on the Excell 11.0 Object library and that > fails on me as well. Any suggestions? Tell us a few things you should have supplied w/o being asked: (1) what version of Python (2.4.what??) (2) what pywin32 build number (3) copy/paste of result when you ran makepy If the makepy gives you a weird syntax error (like the syntax error you showed in the response to Tim Roberts), that could be an old bug (in Python, I believe). Ensure that you have Python 2.4.3, and the latest build of pywin32, and try it again. IIRC, the workaround involved editing the file with the syntax error, adding a few spaces to the end of the allegedly offending line, and one or two lines before that. HTH, John _______________________________________________ Python-win32 mailing list Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From timr at probo.com Fri Oct 6 19:27:00 2006 From: timr at probo.com (Tim Roberts) Date: Fri, 06 Oct 2006 10:27:00 -0700 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <00a701c6e94b$a2c905a0$800101df@qlf.local> References: <00a701c6e94b$a2c905a0$800101df@qlf.local> Message-ID: <452691E4.10003@probo.com> Jim Steil wrote: >Thanks for the response! I tried your suggestion with the following >results.... > > > >>>>import win32com.client >>>>x = win32com.client.gencache.EnsureDispatch("Excel.Application") >>>> >>>> >Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >536, in EnsureDispatch > mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], >bForDemand=bForDemand) > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >393, in EnsureModule > module = GetModuleForTypelib(typelibCLSID, lcid, major, minor) > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >258, in GetModuleForTypelib > mod = _GetModule(modName) > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >629, in _GetModule > mod = __import__(mod_name) > File >"C:\Python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00000 >0000046x0x1x5\__init__.py", line 1748 > '{000208C8-0001-0000-C000-000000000046}' : 'IWalls', > '{000208C9-0001-0000-C000-000000000046}' : 'ITickLabels', > ^ >SyntaxError: invalid syntax > > I'm beginning to think you may have some fundamental problem. I'm running Python24, and I have that exact same file in my gen_py cache, but IWalls is at line 2,063, not line 1,748. What version of Excel is this? I'm running Excel 2003. Hmmm, I'm still at Python-Win32 build 204, so there is a difference there. Still, there is no syntax error there that I can see. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jim at qlf.com Fri Oct 6 19:31:05 2006 From: jim at qlf.com (Jim Steil) Date: Fri, 6 Oct 2006 12:31:05 -0500 Subject: [python-win32] Excel win32com newbie question In-Reply-To: <452691E4.10003@probo.com> Message-ID: <001f01c6e96d$339a11c0$800101df@qlf.local> Tim: I upgraded my Python install from 2.4.1 to 2.4.3 and now it is all working as I originally expected it should. Thanks for your help in trying to find the problem. -Jim Jim Steil IT Manager Quality Liquid Feeds (608) 935-2345 (608) 341-9896 cell -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Roberts Sent: Friday, October 06, 2006 12:27 PM To: 'Python-Win32 List' Subject: Re: [python-win32] Excel win32com newbie question Jim Steil wrote: >Thanks for the response! I tried your suggestion with the following >results.... > > > >>>>import win32com.client >>>>x = win32com.client.gencache.EnsureDispatch("Excel.Application") >>>> >>>> >Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >536, in EnsureDispatch > mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], >bForDemand=bForDemand) > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >393, in EnsureModule > module = GetModuleForTypelib(typelibCLSID, lcid, major, minor) > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >258, in GetModuleForTypelib > mod = _GetModule(modName) > File "C:\Python24\Lib\site-packages\win32com\client\gencache.py", line >629, in _GetModule > mod = __import__(mod_name) > File >"C:\Python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-0000 0 >0000046x0x1x5\__init__.py", line 1748 > '{000208C8-0001-0000-C000-000000000046}' : 'IWalls', > '{000208C9-0001-0000-C000-000000000046}' : 'ITickLabels', > ^ >SyntaxError: invalid syntax > > I'm beginning to think you may have some fundamental problem. I'm running Python24, and I have that exact same file in my gen_py cache, but IWalls is at line 2,063, not line 1,748. What version of Excel is this? I'm running Excel 2003. Hmmm, I'm still at Python-Win32 build 204, so there is a difference there. Still, there is no syntax error there that I can see. -- 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 Oct 9 11:13:16 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 9 Oct 2006 19:13:16 +1000 Subject: [python-win32] Flicker and OnEraseBkgnd In-Reply-To: <4526524F.5010001@free.fr> Message-ID: <013f01c6eb83$29bd9010$0200a8c0@enfoldsystems.local> > Hi, > > I currently try to add a matplotlib backend based on the Gecko engine > (XPCOM, plugin), PIL and pywin. > > I simply build a new window and place it in the plugin area > as a child. > > All works fine, bur when I change the size of the window, there is a > flicker . > I 've read some pages on the web, but I don't see how to adapt the > solutions with python. > Precisely, i can't overwrite the OnResizeBkgnd often spotted > in articles. Do a google for "flicker free drawing" - you will find ton's of advice you can adapt to these tools. Cheers, Mark From scotthogsten at yahoo.com Wed Oct 11 03:11:27 2006 From: scotthogsten at yahoo.com (Scott Hogsten) Date: Tue, 10 Oct 2006 18:11:27 -0700 (PDT) Subject: [python-win32] How to get PID from a Proces Handle ? Message-ID: <20061011011127.90699.qmail@web31806.mail.mud.yahoo.com> I have some code that spawns processes using the "spawnv" command this returns a process handle. Can I use the process handle to retrieve the actual PID of the process ? This is part of a test harness and I need to be able have the actual PID to use against some output. Thanks Scott Hogsten From testdrive6 at gmail.com Wed Oct 11 13:09:05 2006 From: testdrive6 at gmail.com (Test Drive) Date: Wed, 11 Oct 2006 16:39:05 +0530 Subject: [python-win32] Python win32com and iTunes Message-ID: Hi All, I am trying to use win32com with iTunes (version 7.0.1.8). However it seems like I am missing something and I am clueless about that. import win32com.client as wc import pythoncom,sys app=wc.Dispatch('iTunes.Application') mainPl=app.LibraryPlaylist print ">>>>>>>>>>>>>> Dir <<<<<<<<<<<<<<<<<<" print dir(mainPl) print ">>>>>>>>>>>>> Help On PlayFirstTrack <<<<<<<<<<<<<" print help(mainPl.PlayFirstTrack) mainPl.PlayFirstTrack() sys.exit(-1) C:\Python24\MyScripts>python iTunesmin.py >>>>>>>>>>>>>> Dir <<<<<<<<<<<<<<<<<< ['AddFile', 'AddFiles', 'AddTrack', 'AddURL', 'CLSID', 'Delete', 'GetITObjectIDs ', 'PlayFirstTrack', 'Print', 'Search', '_ApplyTypes_', '__cmp__', '__doc__', '_ _getattr__', '__init__', '__module__', '__repr__', '__setattr__', '_get_good_obj ect_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put_ ', 'coclass_clsid'] >>>>>>>>>>>>> Help On PlayFirstTrack <<<<<<<<<<<<< Help on method PlayFirstTrack in module win32com.gen_py.9E93C96F-CF0D-43F6-8BA8- B807A3370712x0x1x8.IITLibraryPlaylist: PlayFirstTrack(self) method of win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370 712x0x1x8.IITLibraryPlaylist.IITLibraryPlaylist instance Start playing the first track in this playlist. None Traceback (most recent call last): File "iTunesmin.py", line 13, in ? mainPl.PlayFirstTrack() File "c:\python24\lib\site-packages\win32com\gen_py\9E93C96F-CF0D-43F6-8BA8-B8 07A3370712x0x1x8\IITLibraryPlaylist.py", line 80, in PlayFirstTrack return self._oleobj_.InvokeTypes(1610809345, LCID, 1, (24, 0), (),) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147418113), None) C:\Python24\MyScripts> I am clueless about the error. Same thing happens when I use the code posted here (http://www.brunningonline.net/simon/blog/archives/001627.html) under the title "Driving iTunes from Python on Windows". C:\Python24\MyScripts>python Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import win32com.client >>> iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application") >>> iTunes.LibrarySource.Playlists.ItemByName('Party Shuffle').PlayFirstTrack() Traceback (most recent call last): File "", line 1, in ? File "c:\python24\lib\site-packages\win32com\gen_py\9E93C96F-CF0D-43F6-8BA8-B8 07A3370712x0x1x8\IITPlaylist.py", line 44, in PlayFirstTrack return self._oleobj_.InvokeTypes(1610809345, LCID, 1, (24, 0), (),) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147418113), None) >>> Any help is appriciated. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061011/16a9e838/attachment.html From simon at brunningonline.net Wed Oct 11 13:57:42 2006 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 11 Oct 2006 12:57:42 +0100 Subject: [python-win32] Python win32com and iTunes In-Reply-To: References: Message-ID: <8c7f10c60610110457h58e51ee5o8418f3a6f58757a1@mail.gmail.com> On 10/11/06, Test Drive wrote: > Hi All, > > I am trying to use win32com with iTunes (version 7.0.1.8). However it seems > like I am missing something and I am clueless about that. I gather that the COM object model changed somewhat at iTunes version 7, which might well be responsible for your problems. I'm a happy Mac user now, so I'm afraid that I can't help you. -- Cheers, Simon B simon at brunningonline.net http://www.brunningonline.net/simon/blog/ From timr at probo.com Wed Oct 11 19:01:15 2006 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Oct 2006 10:01:15 -0700 Subject: [python-win32] Python win32com and iTunes In-Reply-To: References: Message-ID: <452D235B.4010607@probo.com> Test Drive wrote: > Hi All, > > I am trying to use win32com with iTunes (version 7.0.1.8 > ). However it seems like I am missing something and I > am clueless about that. > > > import win32com.client as wc > import pythoncom,sys > > app=wc.Dispatch('iTunes.Application') > mainPl=app.LibraryPlaylist > > print ">>>>>>>>>>>>>> Dir <<<<<<<<<<<<<<<<<<" > print dir(mainPl) > > print ">>>>>>>>>>>>> Help On PlayFirstTrack <<<<<<<<<<<<<" > print help(mainPl.PlayFirstTrack) > > mainPl.PlayFirstTrack () > sys.exit(-1) > > > > ... Start playing the first track in this playlist. > > None > Traceback (most recent call last): > File "iTunesmin.py", line 13, in ? > mainPl.PlayFirstTrack() > File > "c:\python24\lib\site-packages\win32com\gen_py\9E93C96F-CF0D-43F6-8BA8-B8 > 07A3370712x0x1x8\IITLibraryPlaylist.py", line 80, in PlayFirstTrack > return self._oleobj_.InvokeTypes(1610809345, LCID, 1, (24, 0), (),) > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, > None, None, > 0, -2147418113), None) Hmmm, -2147418113 is 0x8000FFFF, which is the rather catchall error E_UNEXPECTED. It generally means you did things out of order. Is it possible that it needs more initialization before launching the first track? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From smithbk at aecl.ca Wed Oct 11 19:55:45 2006 From: smithbk at aecl.ca (Smith, Brian (CR)) Date: Wed, 11 Oct 2006 13:55:45 -0400 Subject: [python-win32] Input-only vs. In/Out Function Parameters Message-ID: > My platform is Win XP Pro (SP2), Python 2.3.4, pywin Build 210. I'm testing > using VBA in MS Excel 2000. A bit more info... I wanted to eliminate the older version of VBA as a possible source of the problem so I downloaded Visual Basic 2005 Express Edition and tried the same VB code. Unfortunately, I still have the same problem: the Python COM object must return the function return value last instead of first and it must also return an extra initial parameter which VB seems to be interpreting as the HRESULT of the COM call itself. If I use the object browser in the VB IDE, the object's methods appear to have the correct signatures. To gain access to the object, I am simply adding a reference to it for the project. Thanks, Brian CONFIDENTIAL AND PRIVILEGED INFORMATION NOTICE This e-mail, and any attachments, may contain information that is confidential, subject to copyright, or exempt from disclosure. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited. AVIS D'INFORMATION CONFIDENTIELLE ET PRIVIL?GI?E Le pr?sent courriel, et toute pi?ce jointe, peut contenir de l'information qui est confidentielle, r?gie par les droits d'auteur, ou interdite de divulgation. Tout examen, divulgation, retransmission, diffusion ou autres utilisations non autoris?es de l'information ou d?pendance non autoris?e envers celle-ci peut ?tre ill?gale et est strictement interdite. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061011/44b65bc8/attachment.html From testdrive6 at gmail.com Wed Oct 11 23:00:27 2006 From: testdrive6 at gmail.com (Test Drive) Date: Thu, 12 Oct 2006 02:30:27 +0530 Subject: [python-win32] Python win32com and iTunes In-Reply-To: <452D235B.4010607@probo.com> References: <452D235B.4010607@probo.com> Message-ID: Hi Tim, Which version of iTunes you are using? Thanks On 10/11/06, Tim Roberts wrote: > > Test Drive wrote: > > > Hi All, > > > > I am trying to use win32com with iTunes (version 7.0.1.8 > > ). However it seems like I am missing something and I > > am clueless about that. > > > > > > import win32com.client as wc > > import pythoncom,sys > > > > app=wc.Dispatch('iTunes.Application') > > mainPl=app.LibraryPlaylist > > > > print ">>>>>>>>>>>>>> Dir <<<<<<<<<<<<<<<<<<" > > print dir(mainPl) > > > > print ">>>>>>>>>>>>> Help On PlayFirstTrack <<<<<<<<<<<<<" > > print help(mainPl.PlayFirstTrack) > > > > mainPl.PlayFirstTrack () > > sys.exit(-1) > > > > > > > > ... Start playing the first track in this playlist. > > > > None > > Traceback (most recent call last): > > File "iTunesmin.py", line 13, in ? > > mainPl.PlayFirstTrack() > > File > > > "c:\python24\lib\site-packages\win32com\gen_py\9E93C96F-CF0D-43F6-8BA8-B8 > > 07A3370712x0x1x8\IITLibraryPlaylist.py", line 80, in PlayFirstTrack > > return self._oleobj_.InvokeTypes(1610809345, LCID, 1, (24, 0), (),) > > pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, > > None, None, > > 0, -2147418113), None) > > > Hmmm, -2147418113 is 0x8000FFFF, which is the rather catchall error > E_UNEXPECTED. It generally means you did things out of order. Is it > possible that it needs more initialization before launching the first > track? > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20061012/fcfedb78/attachment.html From timr at probo.com Wed Oct 11 23:38:13 2006 From: timr at probo.com (Tim Roberts) Date: Wed, 11 Oct 2006 14:38:13 -0700 Subject: [python-win32] Python win32com and iTunes In-Reply-To: References: <452D235B.4010607@probo.com> Message-ID: <452D6445.9080601@probo.com> Test Drive wrote: > > Which version of iTunes you are using? I don't using iTunes. I'm too old for their "target demographic" ;). I'm just offering advice based on general experience with COM objects. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skynare at gmail.com Thu Oct 12 06:20:54 2006 From: skynare at gmail.com (sam lee) Date: Thu, 12 Oct 2006 00:20:54 -0400 Subject: [python-win32] Python.AXScript (win32com) in Netstumbler Message-ID: <4e7aa0f80610112120wf8d99bdr3f9a52c03ef004de@mail.gmail.com> I am trying to write a Python.AXScript script work with Netstumbler. http://www.stumbler.net/scripting.html According to that page, Netstumbler calls functions like, OnScanResult. I wrote JScript and PerlScript version of OnScanResult and they are called automatically by Netstumbler. JScript: function OnScanResult(SSID,BSSID,CapFlags,Signal,Noise,LastSeen) { PlaySound("ns-signal-1.wav"); } PerlScript: #!C:/Perl/bin/perl.exe -w sub OnScanResult { my($sid,$mac,$flags,$signal,$noise,$ls) = @_; PlaySound('ns-signal-1.wav'); } PlaySound is what Netstumbler provides for script writers to call. Above simple scripts work (They play sound whenever Netstumbler scans for Wifi stuff). Now, I do the same in Python.AXScript: def OnScanResult(SSID,BSSID,CapFlags,Signal,Noise,LastSeen): PlaySound("ns-signal-1.wav") And it says PlaySound not defined. Of course there is winsound.PlaySound. I can use winsound module and it works. But, the problem is Netstumbler does not provide PlaySound in Python.AXScript environment as it does to JScript and PerlScript environment. Why Python.AXScript so special?? http://starship.python.net/crew/mhammond/win32/PrivacyProblem.html According to the above link, win32com now comes with two versions of ActiveScripting environment. And only the one that works with trusted code. I think Netstumbler is 'untrusted'. So, win32com.axscript or something won't work with Netstumbler. >From the same link: "If a user desires, they may manually register the version that supports untrusted environments. " So, I want to register the version that supports untrusted environments, presumably like Netstumbler. I did run win32comext\axscript\client\pyscript_rexec.py and win32comext\axscript\client\pyscript.py . But, still no luck. Question is summed up as: How do I register ActiveScripting engine that supports untrusted environments? Or, How do I make Python scripts work with Netstumbler? Thank you. Sam. From mhammond at skippinet.com.au Thu Oct 12 08:22:21 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 12 Oct 2006 16:22:21 +1000 Subject: [python-win32] Python.AXScript (win32com) in Netstumbler In-Reply-To: <4e7aa0f80610112120wf8d99bdr3f9a52c03ef004de@mail.gmail.com> Message-ID: <0a3d01c6edc6$c8e5d1d0$0200a8c0@enfoldsystems.local> > Now, I do the same in Python.AXScript: > def OnScanResult(SSID,BSSID,CapFlags,Signal,Noise,LastSeen): > PlaySound("ns-signal-1.wav") > > And it says PlaySound not defined. Of course there is > winsound.PlaySound. PlaySound will be a method on a "global" object. Due to the way Python works, it is difficult to always make these methods truly global - hence in ASP, you need, eg, 'Response.Write' rather than the plain 'Write' other languages offer. You need to find the name of the equivilent global variable in Netstumbler. Cheers, Mark From mhammond at skippinet.com.au Thu Oct 12 13:18:34 2006 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 12 Oct 2006 21:18:34 +1000 Subject: [python-win32] How to get PID from a Proces Handle ? In-Reply-To: <20061011011127.90699.qmail@web31806.mail.mud.yahoo.com> Message-ID: <0b1401c6edf0$28707370$0200a8c0@enfoldsystems.local> > I have some code that spawns processes using the "spawnv" > command this returns a process handle. > Can I use the process handle to retrieve the actual PID of > the process ? This is part of a test harness > and I need to be able have the actual PID to use against some output. Good question! It's not immediately obvious how to do this simply, but at a pinch, maybe win32pdh or WMI could be used? Other (more painful) option is to use CreateProcess to spawn your process. The best Python implemented example of how to do this I know of is at http://svn.zope.org/*checkout*/Zope/trunk/lib/python/nt_svcutils/service.py? content-type=text%2Fplain - the main advantage is that you can redirect the output any place you like. Hope that helps. Mark From skynare at gmail.com Thu Oct 12 14:18:41 2006 From: skynare at gmail.com (sam lee) Date: Thu, 12 Oct 2006 08:18:41 -0400 Subject: [python-win32] Python.AXScript (win32com) in Netstumbler In-Reply-To: <0a3d01c6edc6$c8e5d1d0$0200a8c0@enfoldsystems.local> References: <4e7aa0f80610112120wf8d99bdr3f9a52c03ef004de@mail.gmail.com> <0a3d01c6edc6$c8e5d1d0$0200a8c0@enfoldsystems.local> Message-ID: <4e7aa0f80610120518k3e91ad2as3bbdef23f7de7532@mail.gmail.com> On 10/12/06, Mark Hammond wrote: > PlaySound will be a method on a "global" object. Due to the way Python > works, it is difficult to always make these methods truly global - hence in > ASP, you need, eg, 'Response.Write' rather than the plain 'Write' other > languages offer. You need to find the name of the equivilent global > variable in Netstumbler. > > Cheers, > > Mark > > Thank you very much! Now, I figured the name of the global object is NetStumbler. NetStumbler.PlaySound("ns-signal-1.wav") works beautifully. So, NetStumbler will call NetStumbler.OnScanResult on some events. I want to override that: 1st try: NetStumbler.OnScanResult = lambda SSID,BSSID,CapFlags,Signal,Noise,LastSeen: NetStumbler.PlaySound("ns-signal-1.wav") I get: Python ActiveX Scripting Engine Traceback (most recent call last): File "