From alan.gauld at btinternet.com Mon Aug 1 19:01:50 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 01 Aug 2011 18:01:50 +0100 Subject: [python-win32] Good Book In-Reply-To: References: Message-ID: <4E36DBFE.8030703@btinternet.com> sefa y?ld?z wrote: > and also a few sources: > http://www.freenetpages.co.uk/hp/alan.gauld/ Thanks for the plug but that site has been closed (bt freenet) for several years now! The latest version of the site, including the almost completed V3 tutor, is at http://www.alan-g.me.uk/ Regards, Alan G. From abhi.forall at gmail.com Wed Aug 3 05:24:32 2011 From: abhi.forall at gmail.com (abhijeet mahagaonkar) Date: Wed, 3 Aug 2011 08:54:32 +0530 Subject: [python-win32] Append data to an already saved XL File Message-ID: Dear Pythonistas, I'm writing an attendance tracking application where i pull data daily from a webpage. I have to collate it daily and generate a report at the end of the month. I have a predefined XL template for the report. I wanted to know if i can add (append) the data everyday to this file and mail it at the end of the month. Hence I was thinking on the lines of XL_Handle=win32com.client.Dispatch('Excel.Application') WorkSpace=XL_Handle.Workbooks.Open('C:somepath\template.xls') Fill=WorkSpace.Worksheets(1) i=2 while(i<31): Fill.Cells(i,1).Value=(attendance[i]) ## assuming 30 people, This array has P for present and A for Absent i=i+1 WorkSpace.Save() XL_Handle.Workbooks.Close() This would give me a data for one day. My question is there a way i can put data for the 2nd, 3rd, 4th..... etc.. till 31st on already saved xls file? In other words in Fill.Cells(i,1) can i make it Fill.Cells(i,2) tommorrow :):) Thanks in advance Warm Regards, Abhijeet My question here is -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Aug 3 18:46:17 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 3 Aug 2011 09:46:17 -0700 Subject: [python-win32] Append data to an already saved XL File In-Reply-To: References: Message-ID: <4E397B59.7080507@probo.com> abhijeet mahagaonkar wrote: > > I'm writing an attendance tracking application where i pull data daily > from a webpage. > I have to collate it daily and generate a report at the end of the month. > > I have a predefined XL template for the report. > I wanted to know if i can add (append) the data everyday to this file > and mail it at the end of the month. I'm not sure this is the way I would solve this problem. If I were doing it, I'd tuck the data into a simple database, or a comma-separate text file, both of which are more easily manipulated in Python. Then, at the end of the month, I could have a Python script generate the report as an HTML file or a PDF. In my opinion, it's much easier to generate reports in HTML using Python than it is to manipulate an Excel spreadsheet. > This would give me a data for one day. > My question is there a way i can put data for the 2nd, 3rd, 4th..... > etc.. till 31st on already saved xls file? > In other words in Fill.Cells(i,1) can i make it Fill.Cells(i,2) > tommorrow :):) And what's the problem? This seems perfectly workable to me. The row number would be the day of the month, right? So, you just fetch the current day of the month from the datetime module. You'd need a way to remember when you start a new month, so you don't overwrite old data, but perhaps you should base the name of the XLS file on the current month. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From wsadkin at ParlanceCorp.com Wed Aug 3 23:24:00 2011 From: wsadkin at ParlanceCorp.com (Will Sadkin) Date: Wed, 3 Aug 2011 17:24:00 -0400 Subject: [python-win32] How do I build manifest-less extension modules? Message-ID: Hi all (and especially Mark), My company is in the process of updating all its code and tools to their latest (or at least most up-to-date and still compatible) versions, and has therefore switched to using VS2010 for building all its code, and updated its python codebase for Python2.7.x. However, I recently discovered that Python 2.7.x is only compiled with VS2008, and as such, python interpreters embedded in my VS2010-compiled executables won't work unless I build them with an explicit /MANIFESTDEPENDENCY line of the form: /MANIFESTDEPENDENCY:"type='Win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='X86' publicKeyToken='1fc8b3b9a1e18e3b' " With this trick, discovered in another search result (http://bugs.python.org/issue7833), I can then import python modules and extension modules without incident into my embedded interpreter inside my VS2010-built executable without complaint. However, we also build an extension module (.pyd) that allows our Python code can access some of our C++ library functions. Unfortunately, this won't import into the Python 2.7 interpreter, presumably because it contains a manifest that references the VS2010 runtime libs. I read that most of the extension modules are stripped of their manifests, but I have not found any recipe or set of instructions for achieving this. I have done some experiments to try to eliminate it using the UI, but none of these have been effective. So... Can someone tell me how to build our .pyd in VS2010 such that it doesn't have a manifest, and thus can be loaded by the Python2.7 interpreter? (Also, note that, up to now, we have never used distutils to build or distribute the .pyd, as it is only bundled with our application to allow its python to access some C++ functions we didn't want to have 2 codebases for; if it's required, I will need some pretty "face the stove" instructions!) Thanks in advance, /Will Sadkin Parlance Corporation PS: Is there any growing pressure to make Python compatible with the latest compiler from Microsoft, now almost 2 years old?!? From abhi.forall at gmail.com Thu Aug 4 05:36:48 2011 From: abhi.forall at gmail.com (abhijeet mahagaonkar) Date: Thu, 4 Aug 2011 09:06:48 +0530 Subject: [python-win32] Append data to an already saved XL File In-Reply-To: <4E397B59.7080507@probo.com> References: <4E397B59.7080507@probo.com> Message-ID: Thanks Tim, I guess i explored a bit on csv. It turns out that works far too well for me. Thanks, -Abhijeet On Wed, Aug 3, 2011 at 10:16 PM, Tim Roberts wrote: > abhijeet mahagaonkar wrote: > > > > I'm writing an attendance tracking application where i pull data daily > > from a webpage. > > I have to collate it daily and generate a report at the end of the month. > > > > I have a predefined XL template for the report. > > I wanted to know if i can add (append) the data everyday to this file > > and mail it at the end of the month. > > I'm not sure this is the way I would solve this problem. If I were > doing it, I'd tuck the data into a simple database, or a comma-separate > text file, both of which are more easily manipulated in Python. Then, > at the end of the month, I could have a Python script generate the > report as an HTML file or a PDF. In my opinion, it's much easier to > generate reports in HTML using Python than it is to manipulate an Excel > spreadsheet. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mitch.oliver at gmail.com Thu Aug 4 22:21:41 2011 From: mitch.oliver at gmail.com (Mitch Oliver) Date: Thu, 4 Aug 2011 16:21:41 -0400 Subject: [python-win32] Calling GetText_(1) Message-ID: I am attempting to work through WMI to control some Hyper-V VMs. I am unable to call GetText_. Given the following code: import wmi c = wmi.WMI(computer='remoteserver', namespace='virtualization') mgtSvcs = c.Msvm_VirtualSystemManagementService()[0] mgtSvcs.GetText_(1) Returns an AttributeError: AttributeError: '' object has no attribute 'GetText_' What am I missing? I'm using Python 2.7.2 with pywin32 build 216 installed and WMI 1.4.9. I have tried both 64-bit python and 32-bit python with no change. From skippy.hammond at gmail.com Fri Aug 5 03:03:08 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 05 Aug 2011 11:03:08 +1000 Subject: [python-win32] How do I build manifest-less extension modules? In-Reply-To: References: Message-ID: <4E3B414C.20107@gmail.com> On 4/08/2011 7:24 AM, Will Sadkin wrote: > So... > Can someone tell me how to build our .pyd in VS2010 such that it doesn't > have a manifest, and thus can be loaded by the Python2.7 interpreter? You should be able to use the cmdline option MANIFEST:NO to the linker - that is what pywin32 does. > PS: Is there any growing pressure to make Python compatible with the > latest compiler from Microsoft, now almost 2 years old?!? Not really - there is a bit of a history of skipping every second release. The main problem is friction for extension authors targetting multiple Python versions and thereby forcing them to update their tool chain. This is slightly less of a problem if the free tools are used but still a PITA for people who need to use features not available in the free version. As I understand it though, some of the manifest pain should go away with VS2010, so this could be a compelling reason for Python 3.3 - it's almost certainly not an option for anything already released using VC2008 (ie, I expect we will never see a VS2010 version of 2.7) Cheers, Mark From saunders.m3 at we-learn.com Fri Aug 5 10:16:11 2011 From: saunders.m3 at we-learn.com (M Saunders TAS) Date: Fri, 5 Aug 2011 09:16:11 +0100 Subject: [python-win32] Calling GetText_(1) In-Reply-To: References: Message-ID: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> Hi, The code works fine for me. I'm equally using python 2.7.2, pywin32 216 and WMI 1.4.9 (have also tested against 1.4.6). Does c.Msvm_VirtualSystemManagementService()[0] actually return anything? Matt -----Original Message----- From: python-win32-bounces+saunders.m3=we-learn.com at python.org [mailto:python-win32-bounces+saunders.m3=we-learn.com at python.org] On Behalf Of Mitch Oliver Sent: 04 August 2011 21:22 To: python-win32 at python.org Subject: [python-win32] Calling GetText_(1) I am attempting to work through WMI to control some Hyper-V VMs. I am unable to call GetText_. Given the following code: import wmi c = wmi.WMI(computer='remoteserver', namespace='virtualization') mgtSvcs = c.Msvm_VirtualSystemManagementService()[0] mgtSvcs.GetText_(1) Returns an AttributeError: AttributeError: '' object has no attribute 'GetText_' What am I missing? I'm using Python 2.7.2 with pywin32 build 216 installed and WMI 1.4.9. I have tried both 64-bit python and 32-bit python with no change. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 Warwickshire Schools Email System This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please forward to: postmaster at we-learn.com. If the content of this email is considered to be inappropriate or offensive please report by forwarding to: reportabuse at we-learn.com From mail at timgolden.me.uk Fri Aug 5 13:10:43 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 05 Aug 2011 12:10:43 +0100 Subject: [python-win32] Calling GetText_(1) In-Reply-To: References: Message-ID: <4E3BCFB3.7030004@timgolden.me.uk> On 04/08/2011 21:21, Mitch Oliver wrote: > I am attempting to work through WMI to control some Hyper-V VMs. I am > unable to call GetText_. > > Given the following code: > import wmi > > c = wmi.WMI(computer='remoteserver', namespace='virtualization') > mgtSvcs = c.Msvm_VirtualSystemManagementService()[0] > mgtSvcs.GetText_(1) > > Returns an AttributeError: > AttributeError: ' Library.ISWbemObject instance at 0x63756808>' object has no attribute > 'GetText_' Well I'm glad that Matt has chipped in with the results from his installation, because I was going to ask if could piggyback onto his rig to test this out... I've got no clear answer, but I'd like to see the full traceback, not just the last line (just to ensure where the error's really happening. Also, try mgsSvcs.methods and/or mgsSvcs.properties to see what wmi has picked up for this object. Also, print mgsSvcs to make sure it's what you think it is... TJG From andrea.gavana at gmail.com Fri Aug 5 13:51:18 2011 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Fri, 5 Aug 2011 13:51:18 +0200 Subject: [python-win32] Excel "NumberFormat" to Python? (!) Message-ID: Hi All, I was wondering if someone had already tackled the problem of converting Excel cell NumberFormat to something Python can parse and actually use. In more detail, what I mean is: once you right-click on a cell and select "Format Cells" you get a huge list of possible formatting options, divided into categories. I don't think I will have any particular problem in interpreting and coding in Python what the following NumberFormats mean: - "0.00" - "%0.0" - "General" - "Text" But some of them are a bit obscure and problematic to me (in the "Custom" section): - "_($* #,##0_);_($* (#,##0);_($* "-"_);" - "[$?-2] #,##0.00_);[Red]([$?-2] #,##0.00)" And many others. Not to say anything about all the impossible date formats (how do I get time.strptime to do the right thing with them?) or the "Special" and "Fraction" categories. Basically, I know what is the value of a cell, but I would like to have a string representation of that value as close as possible as what Excel is showing me on screen, i.e.: value = 0.154 ==> on-screen: 15.4% (percentage format); value = 40234.0 ==> on-screen: 2/25/10 12:00 AM (custom date format) And so on. I would like to get the "on-screen" thing in a Python string. I know it sounds close to impossible, but maybe someone has an idea or something similar has already been implemented... I googled back and forth for this but it seems my google-fu is very weak. Thank you in advance for your suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From wsadkin at ParlanceCorp.com Fri Aug 5 18:07:31 2011 From: wsadkin at ParlanceCorp.com (Will Sadkin) Date: Fri, 5 Aug 2011 12:07:31 -0400 Subject: [python-win32] How do I build manifest-less extension modules? In-Reply-To: <4E3B414C.20107@gmail.com> References: <4E3B414C.20107@gmail.com> Message-ID: Thanks, Mark; Unfortunately, that did not work for me. I still get: C:\Program Files (x86)\Python2.7>python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', 'C:\\Windows\\system32\\python27.zip', 'C:\\Program Files (x86)\\Python2.7\\DLLs', 'C:\\Program Files (x86)\\Python2.7\\lib', 'C:\\Program Files (x86)\\Python2.7\\lib\\plat-win', 'C:\\Program Files (x86)\\Python2.7\\lib\\lib-tk', 'C:\\Program Files (x86)\\Python2.7', 'C:\\Program Files (x86)\\Python2.7\\lib\\site-packages', 'C:\\Program Files (x86)\\Python2.7\\lib\\site-packages\\win32', 'C:\\Program Files (x86)\\Python2.7\\lib\\site-packages\\win32\\lib', 'C:\\Program Files (x86)\\Python2.7\\lib\\site-packages\\Pythonwin', 'C:\\Program Files (x86)\\Python2.7\\lib\\site-packages\\wx-2.8-msw-unicode'] >>> import pyodbc >>> pyodbc >>> import PyNCSWrappers Traceback (most recent call last): File "", line 1, in ImportError: DLL load failed: The specified module could not be found. >>> My linker command line is now: /OUT:"Release/PyNCSWrappers.pyd" /INCREMENTAL:NO /NOLOGO /LIBPATH:"..\..\..\lib\i86nt\Python" /DLL "..\common\Release\TRoutLib.lib" "C:\p4clients\wss\main\ncs\src\lib\butils\Release\builderutils.lib" "C:\p4clients\wss\main\ncs\src\lib\common\Release\TRoutLib.lib" "C:\p4clients\wss\main\ncs\src\lib\PhoneNum\Release\PhoneNumLib.lib" "C:\p4clients\wss\main\ncs\src\lib\Py2CLib\Release\Py2CLib.lib" "C:\p4clients\wss\main\ncs\src\lib\Registry\Release\RegLib.lib" /MANIFEST:NO /ALLOWISOLATION /MANIFESTUAC:NO /DEBUG /PDB:".\Release/PyNCSWrappers.pdb" /PGD:"C:\p4clients\wss\main\ncs\src\lib\PyNCSWrappers\Release\PyNCSWrapp ers.pgd" /TLBID:1 /DYNAMICBASE:NO /IMPLIB:".\Release/PyNCSWrappers.lib" /MACHINE:X86 /ERRORREPORT:QUEUE When this alone didn't work, I also set and linked the dependent dlls to also not use manifests using the same /MANIFEST:NO option, and copied these into the same location as the .pyd (lib/site-packages), but this did nothing to change the behavior. Is there any way I can get a more detailed explanation of why/which dll load failed? As it is, I'm somewhat at a loss for a "next step"... Thanks in advance, /Will -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: Thursday, August 04, 2011 9:03 PM To: Will Sadkin Cc: python-win32 at python.org Subject: Re: [python-win32] How do I build manifest-less extension modules? On 4/08/2011 7:24 AM, Will Sadkin wrote: > So... > Can someone tell me how to build our .pyd in VS2010 such that it > doesn't have a manifest, and thus can be loaded by the Python2.7 interpreter? You should be able to use the cmdline option MANIFEST:NO to the linker - that is what pywin32 does. > PS: Is there any growing pressure to make Python compatible with the > latest compiler from Microsoft, now almost 2 years old?!? Not really - there is a bit of a history of skipping every second release. The main problem is friction for extension authors targetting multiple Python versions and thereby forcing them to update their tool chain. This is slightly less of a problem if the free tools are used but still a PITA for people who need to use features not available in the free version. As I understand it though, some of the manifest pain should go away with VS2010, so this could be a compelling reason for Python 3.3 - it's almost certainly not an option for anything already released using VC2008 (ie, I expect we will never see a VS2010 version of 2.7) Cheers, Mark From timr at probo.com Fri Aug 5 21:55:06 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 5 Aug 2011 12:55:06 -0700 Subject: [python-win32] Excel "NumberFormat" to Python? (!) In-Reply-To: References: Message-ID: <4E3C4A9A.4030702@probo.com> Andrea Gavana wrote: > > I was wondering if someone had already tackled the problem of > converting Excel cell NumberFormat to something Python can parse and > actually use. In more detail, what I mean is: once you right-click on > a cell and select "Format Cells" you get a huge list of possible > formatting options, divided into categories. I don't think I will have > any particular problem in interpreting and coding in Python what the > following NumberFormats mean: > > - "0.00" > - "%0.0" > - "General" > - "Text" > > But some of them are a bit obscure and problematic to me (in the > "Custom" section): > > - "_($* #,##0_);_($* (#,##0);_($* "-"_);" > - "[$?-2] #,##0.00_);[Red]([$?-2] #,##0.00)" Yes, those are challenging. I can tell you what they mean, but that won't make them easier to parse. When there are two parts separated by a semi-colon ";", the left part is used for numbers >= 0, the right part for < 0. When there are three parts separated by a semi-colon, part one is > 0, part two is < 0, part three is == 0. [$?-2] is a variation of $. $ by itself says "always put a dollar sign". [$?-2] says "the currency symbol is euro code #2", which is the stock euro on the left. There are a bunch of euro variations. Definitely a non-trivial chore to translate this. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mitch.oliver at gmail.com Mon Aug 8 16:34:53 2011 From: mitch.oliver at gmail.com (Mitch Oliver) Date: Mon, 8 Aug 2011 10:34:53 -0400 Subject: [python-win32] Calling GetText_(1) In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> Message-ID: On Fri, Aug 5, 2011 at 4:16 AM, M Saunders TAS wrote: > Does c.Msvm_VirtualSystemManagementService()[0] actually return anything? Yes. This returns a wmi_object: <_wmi_object: \\server_name\root\virtualization:Msvm_VirtualSystemManagementService.CreationClassName="Msvm_VirtualSystemManagementService",Name="vmms",SystemCreationClassName="Msvm_ComputerSystem",SystemName="server_name"> Per your other response, I have run makepy on two of those libraries. WMI ADSI Extension Library is not available in Windows 7. What version of Windows are you using? From saunders.m3 at we-learn.com Mon Aug 8 17:17:17 2011 From: saunders.m3 at we-learn.com (M Saunders TAS) Date: Mon, 8 Aug 2011 16:17:17 +0100 Subject: [python-win32] Calling GetText_(1) In-Reply-To: References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> Message-ID: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> Hi Mitch, I've just gone to rerun this on my machine and it failed with the exact same error message that you reported initially. The only thing that has changed since it worked is I compiled the typelibs. I have just tested this on another box, and compiling the Microsoft WMI Scripting Library typelib definitely breaks it. Anybody else got any thoughts on this? Matt -----Original Message----- From: python-win32-bounces+saunders.m3=we-learn.com at python.org [mailto:python-win32-bounces+saunders.m3=we-learn.com at python.org] On Behalf Of Mitch Oliver Sent: 08 August 2011 15:35 To: python-win32 at python.org Subject: Re: [python-win32] Calling GetText_(1) On Fri, Aug 5, 2011 at 4:16 AM, M Saunders TAS wrote: > Does c.Msvm_VirtualSystemManagementService()[0] actually return anything? Yes. This returns a wmi_object: <_wmi_object: \\server_name\root\virtualization:Msvm_VirtualSystemManagementService.CreationClassName="Msvm_VirtualSystemManagementService",Name="vmms",SystemCreationClassName="Msvm_ComputerSystem",SystemName="server_name"> Per your other response, I have run makepy on two of those libraries. WMI ADSI Extension Library is not available in Windows 7. What version of Windows are you using? _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 Warwickshire Schools Email System This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please forward to: postmaster at we-learn.com. If the content of this email is considered to be inappropriate or offensive please report by forwarding to: reportabuse at we-learn.com From mitch.oliver at gmail.com Mon Aug 8 17:35:59 2011 From: mitch.oliver at gmail.com (Mitch Oliver) Date: Mon, 8 Aug 2011 11:35:59 -0400 Subject: [python-win32] Calling GetText_(1) In-Reply-To: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> Message-ID: > I have just tested this on another box, and compiling the Microsoft WMI Scripting Library typelib definitely breaks it. Where does makepy write its generated files? Is it possible to unmake this typelib? From mail at timgolden.me.uk Mon Aug 8 17:50:10 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Aug 2011 16:50:10 +0100 Subject: [python-win32] Calling GetText_(1) In-Reply-To: References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> Message-ID: <4E4005B2.1030708@timgolden.me.uk> On 08/08/2011 16:35, Mitch Oliver wrote: >> I have just tested this on another box, and compiling the Microsoft WMI Scripting Library typelib definitely breaks it. > > Where does makepy write its generated files? Is it possible to unmake > this typelib? Try: %TEMP%\gen_py\<2.x>\... (PS Mitch, can you subscribe to the list, please? Otherwise someone has to approve each of your posts as they come in...) TJG From mitch.oliver at gmail.com Mon Aug 8 18:09:24 2011 From: mitch.oliver at gmail.com (Mitch Oliver) Date: Mon, 8 Aug 2011 12:09:24 -0400 Subject: [python-win32] Calling GetText_(1) In-Reply-To: <4E4005B2.1030708@timgolden.me.uk> References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> <4E4005B2.1030708@timgolden.me.uk> Message-ID: > Try: > > %TEMP%\gen_py\<2.x>\... That seemed to contain some dummies, but I was able to locate files that had content in site-packages\win32com\gen_py. After deleting the contents of this directory and regenerating only WMI Scripting and WMICntl the code works. > (PS Mitch, can you subscribe to the list, please? Otherwise someone > has to approve each of your posts as they come in...) Sorry about that. I had subscribed earlier, and wondered why I wasn't getting any messages. My subscription appears to have taken this time so hopefully this will not be a problem in the future. From mail at timgolden.me.uk Mon Aug 8 21:43:02 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Aug 2011 20:43:02 +0100 Subject: [python-win32] Calling GetText_(1) In-Reply-To: References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> <4E4005B2.1030708@timgolden.me.uk> Message-ID: <4E403C46.7060000@timgolden.me.uk> On 08/08/2011 17:09, Mitch Oliver wrote: >> Try: >> >> %TEMP%\gen_py\<2.x>\... > > That seemed to contain some dummies, but I was able to locate files > that had content in site-packages\win32com\gen_py. After deleting the > contents of this directory and regenerating only WMI Scripting and > WMICntl the code works. Well, thanks for the update. To be honest, I've used the wmi module on dozens of machines, and I never compile those typelibs; it's only that someone early on said he couldn't get things to work until he did. Who knows? TJG From andrew.george.hammond at gmail.com Tue Aug 9 04:06:19 2011 From: andrew.george.hammond at gmail.com (Andrew Hammond) Date: Mon, 8 Aug 2011 19:06:19 -0700 Subject: [python-win32] manipulating service action restart behavior? Message-ID: I am trying to control the behavior of a service with regards to failure handling as described here: http://blogs.msdn.com/b/jcalev/archive/2008/01/10/some-tricks-with-service-restart-logic.aspx I have done some reading and have the following snippet of code that I think is going in the right direction. However I don't know how to create the action list. I suspect that it should be an array of unsigned long ints, but... ??? hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) try: hs = SmartOpenService(hscm, cls._svc_name_, win32service.SERVICE_ALL_ACCESS) try: # What's the pythonic way to create these??? action1 = Action() action1.Type = win32service.SC_ACTION_RESTART action1.Delay = 600 # 10 minutes? action2 = Action() action2.Type = win32service.SC_ACTION_RESTART action2.Delay = 600 action3 = Action() action3.Type = win32service.SC_ACTION_RESTART action3.Delay = 600 win32service.ChangeServiceConfig2( hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, [action1,action2,action3] # again, this isn't probably right, but... ? ) finally: win32service.CloseServiceHandle(hs) finally: win32service.CloseServiceHandle(hscm) Can anyone help please? Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From saunders.m3 at we-learn.com Tue Aug 9 10:16:17 2011 From: saunders.m3 at we-learn.com (M Saunders TAS) Date: Tue, 9 Aug 2011 09:16:17 +0100 Subject: [python-win32] Calling GetText_(1) In-Reply-To: <4E403C46.7060000@timgolden.me.uk> References: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07A6@EXVS-1.WARWICK.welearn.internal> <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C0@EXVS-1.WARWICK.welearn.internal> <4E4005B2.1030708@timgolden.me.uk> <4E403C46.7060000@timgolden.me.uk> Message-ID: <3A8573B667AAE24D810B12B0ECDEB0B1013F586E07C4@EXVS-1.WARWICK.welearn.internal> >On 08/08/2011 17:09, Mitch Oliver wrote: >>> Try: >>> >>> %TEMP%\gen_py\<2.x>\... >> >> That seemed to contain some dummies, but I was able to locate files >> that had content in site-packages\win32com\gen_py. After deleting the >> contents of this directory and regenerating only WMI Scripting and >> WMICntl the code works. >Well, thanks for the update. To be honest, I've used the wmi module >on dozens of machines, and I never compile those typelibs; it's only >that someone early on said he couldn't get things to work until >he did. Who knows? Just for completeness I'll chime in that deleting all files in site-packages\win32com\gen_py on both my machines (Win 7 32bit and Server 2008 64bit) does indeed cause the script to work again. Recompiling the typelibs causes the previously noted error again. Matt Warwickshire Schools Email System This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please forward to: postmaster at we-learn.com. If the content of this email is considered to be inappropriate or offensive please report by forwarding to: reportabuse at we-learn.com From andrea.gavana at gmail.com Tue Aug 9 11:42:36 2011 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Tue, 9 Aug 2011 11:42:36 +0200 Subject: [python-win32] Excel worksheet range, Text property Message-ID: Hi All, I am trying to speed up a bit a new widget I created for wxPython, which uses heavily the COM interface between Python and Excel (it only reads Excel data, no writing). One of the main issues I have found is related to the extraction of the "Text" property from a range of cells. Let's suppose I have a very simple Excel file (I attach a dummy sample of it). This file contains cells with some value in them, other cells are empty. When I run the following script: import os from win32com.client import Dispatch xlApp = Dispatch('Excel.Application') filename, sheetname = os.path.join(os.getcwd(), "Book1.xls"), "Book1" xlBook = xlApp.Workbooks.Open(filename) xlSheet = xlBook.Worksheets(sheetname) print "Values:" print xlSheet.Range("A1:K11").Value print "\n\n" print "Texts:" print xlSheet.Range("A1:K11").Text I get a 2D nested tuple of values for the "Value" property, but I only get a single "None" for the "Text" property (i.e., no tuple, just "None"). The solution I came up with is to iterate on every cell in the spreadsheet and get its "Text" property if it is not "None", but this is expensive compared to the "vectorized" approach you can get with Range(). Does anyone have a suggestion on how to improve my current approach (or how to fix my flawed code above)? Thank you in advance for your help. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Book1.xls Type: application/vnd.ms-excel Size: 14336 bytes Desc: not available URL: From andrew.george.hammond at gmail.com Wed Aug 10 02:56:48 2011 From: andrew.george.hammond at gmail.com (Andrew Hammond) Date: Tue, 9 Aug 2011 17:56:48 -0700 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: References: Message-ID: I did some more hunting around and now have the following: hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) try: hs = win32serviceutil.SmartOpenService(hscm, cls._svc_name_, win32service.SERVICE_ALL_ACCESS) try: service_failure_actions = { 'ResetPeriod': 6000000, # Time in seconds after which to reset the failure count to zero. 'RebootMsg': '', 'lpCommand': '', 'Actions': [(win32service.SC_ACTION_RESTART, 60000), (win32service.SC_ACTION_RESTART, 60000)] } win32service.ChangeServiceConfig2(hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) finally: win32service.CloseServiceHandle(hs) finally: win32service.CloseServiceHandle(hscm) However, I'm getting the following error message: TypeError: SERVICE_FAILURE_ACTIONS must be a dictionary containing {'ResetPeriod':int,'RebootMsg':unicode,'lpCommand':unicode,'Actions':sequence of 2 tuples(int,int) Which I think is what I'm feeding it. Can someone please tell me what I'm doing wrong? A On Mon, Aug 8, 2011 at 7:06 PM, Andrew Hammond < andrew.george.hammond at gmail.com> wrote: > I am trying to control the behavior of a service with regards to failure > handling as described here: > http://blogs.msdn.com/b/jcalev/archive/2008/01/10/some-tricks-with-service-restart-logic.aspx > > I have done some reading and have the following snippet of code that I > think is going in the right direction. However I don't know how to create > the action list. I suspect that it should be an array of unsigned long ints, > but... ??? > > > hscm = > win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) > > try: > hs = SmartOpenService(hscm, cls._svc_name_, > win32service.SERVICE_ALL_ACCESS) > try: > # What's the pythonic way to create these??? > action1 = Action() > action1.Type = win32service.SC_ACTION_RESTART > action1.Delay = 600 # 10 minutes? > > action2 = Action() > action2.Type = win32service.SC_ACTION_RESTART > action2.Delay = 600 > > action3 = Action() > action3.Type = win32service.SC_ACTION_RESTART > action3.Delay = 600 > > win32service.ChangeServiceConfig2( > hs, > win32service.SERVICE_CONFIG_FAILURE_ACTIONS, > [action1,action2,action3] # again, this isn't probably > right, but... ? > ) > finally: > win32service.CloseServiceHandle(hs) > finally: > win32service.CloseServiceHandle(hscm) > > Can anyone help please? > > Andrew > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rsyring at gmail.com Wed Aug 10 04:27:04 2011 From: rsyring at gmail.com (Randy Syring) Date: Tue, 09 Aug 2011 22:27:04 -0400 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: References: Message-ID: <4E41EC78.3060002@gmail.com> This is a shot in the dark, but if you are on python 2, then: 'RebootMsg': '', 'lpCommand': '', Is two strings, not unicode. Maybe: 'RebootMsg': u'', 'lpCommand': u'', -------------------------------------- Randy Syring Intelicom Direct: 502-276-0459 Office: 502-212-9913 For the wages of sin is death, but the free gift of God is eternal life in Christ Jesus our Lord (Rom 6:23) On 08/09/2011 08:56 PM, Andrew Hammond wrote: > I did some more hunting around and now have the following: > > hscm = > win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) > try: > hs = win32serviceutil.SmartOpenService(hscm, cls._svc_name_, > win32service.SERVICE_ALL_ACCESS) > try: > service_failure_actions = { > 'ResetPeriod': 6000000, # Time in seconds after which to > reset the failure count to zero. > 'RebootMsg': '', > 'lpCommand': '', > 'Actions': [(win32service.SC_ACTION_RESTART, 60000), > (win32service.SC_ACTION_RESTART, 60000)] > } > win32service.ChangeServiceConfig2(hs, > win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) > finally: > win32service.CloseServiceHandle(hs) > finally: > win32service.CloseServiceHandle(hscm) > > However, I'm getting the following error message: > > TypeError: SERVICE_FAILURE_ACTIONS must be a dictionary containing > {'ResetPeriod':int,'RebootMsg':unicode,'lpCommand':unicode,'Actions':sequence > of 2 tuples(int,int) > > Which I think is what I'm feeding it. Can someone please tell me what > I'm doing wrong? > > A > > On Mon, Aug 8, 2011 at 7:06 PM, Andrew Hammond > > wrote: > > I am trying to control the behavior of a service with regards to > failure handling as described here: > http://blogs.msdn.com/b/jcalev/archive/2008/01/10/some-tricks-with-service-restart-logic.aspx > > I have done some reading and have the following snippet of code > that I think is going in the right direction. However I don't know > how to create the action list. I suspect that it should be an > array of unsigned long ints, but... ??? > > > hscm = > win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) > > try: > hs = SmartOpenService(hscm, cls._svc_name_, > win32service.SERVICE_ALL_ACCESS) > try: > # What's the pythonic way to create these??? > action1 = Action() > action1.Type = win32service.SC_ACTION_RESTART > action1.Delay = 600 # 10 minutes? > > action2 = Action() > action2.Type = win32service.SC_ACTION_RESTART > action2.Delay = 600 > > action3 = Action() > action3.Type = win32service.SC_ACTION_RESTART > action3.Delay = 600 > > win32service.ChangeServiceConfig2( > hs, > win32service.SERVICE_CONFIG_FAILURE_ACTIONS, > [action1,action2,action3] # again, this isn't > probably right, but... ? > ) > finally: > win32service.CloseServiceHandle(hs) > finally: > win32service.CloseServiceHandle(hscm) > > Can anyone help please? > > Andrew > > > > > _______________________________________________ > 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: From the.gerenuk at googlemail.com Wed Aug 10 12:15:28 2011 From: the.gerenuk at googlemail.com (A. S.) Date: Wed, 10 Aug 2011 12:15:28 +0200 Subject: [python-win32] Named parameters; Adding Excel sheet Message-ID: Hello! I've worked with pywin32 and up to now inspecting the Excel macro editor and translating commands worked fine, but now I cannot manage to add a sheet at the correct position in Excel. My test program is from win32com.client import Dispatch app=Dispatch("Excel.Application") app.Workbooks.Add() app.ActiveWorkbook.Sheets.Add(After=app.ActiveWorkbook.Sheets(3)) Which adds the sheet at the incorrect position. Is there a trick? How come Excel gets confused? Bernd -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Wed Aug 10 12:56:40 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Aug 2011 11:56:40 +0100 Subject: [python-win32] Named parameters; Adding Excel sheet In-Reply-To: References: Message-ID: <4E4263E8.3020300@timgolden.me.uk> On 10/08/2011 11:15, A. S. wrote: > I've worked with pywin32 and up to now inspecting the Excel macro editor > and translating commands worked fine, but now I cannot manage to add a > sheet at the correct position in Excel. > > My test program is > > from win32com.client import Dispatch > > app=Dispatch("Excel.Application") > app.Workbooks.Add() > app.ActiveWorkbook.Sheets.Add(After=app.ActiveWorkbook.Sheets(3)) > > Which adds the sheet at the incorrect position. Is there a trick? How > come Excel gets confused? Well, you don't say what "at the incorrect position" means for you, but it appears to work for me. One small hint is that Workbooks.Add returns the new workbook so you don't have to do app.ActiveWorkbook all over the place. In summary, this works for me: from win32com.client import Dispatch app = Dispatch ("Excel.Application") app.Visible = 1 # Watch what's going on wb = app.Workbooks.Add () # [Sheet1], [Sheet2], [Sheet3] wb.Sheets.Add (After=wb.Sheets (3)) # [Sheet1], [Sheet2], [Sheet3], [Sheet4] Do you see the same? And is that what you expected? TJG From drobinow at gmail.com Wed Aug 10 14:46:58 2011 From: drobinow at gmail.com (David Robinow) Date: Wed, 10 Aug 2011 08:46:58 -0400 Subject: [python-win32] Named parameters; Adding Excel sheet In-Reply-To: <4E4263E8.3020300@timgolden.me.uk> References: <4E4263E8.3020300@timgolden.me.uk> Message-ID: On Wed, Aug 10, 2011 at 6:56 AM, Tim Golden wrote: > On 10/08/2011 11:15, A. S. wrote: >> >> I've worked with pywin32 and up to now inspecting the Excel macro editor >> and translating commands worked fine, but now I cannot manage to add a >> sheet at the correct position in Excel. >> >> My test program is >> >> from win32com.client import Dispatch >> >> app=Dispatch("Excel.Application") >> app.Workbooks.Add() >> app.ActiveWorkbook.Sheets.Add(After=app.ActiveWorkbook.Sheets(3)) >> >> Which adds the sheet at the incorrect position. Is there a trick? How >> come Excel gets confused? > > Well, you don't say what "at the incorrect position" means for you, but > it appears to work for me. One small hint is that Workbooks.Add returns > the new workbook so you don't have to do app.ActiveWorkbook all over > the place. In summary, this works for me: > > > from win32com.client import Dispatch > > app = Dispatch ("Excel.Application") > app.Visible = 1 # Watch what's going on > wb = app.Workbooks.Add () > # [Sheet1], [Sheet2], [Sheet3] > wb.Sheets.Add (After=wb.Sheets (3)) > # [Sheet1], [Sheet2], [Sheet3], [Sheet4] > > > > Do you see the same? And is that what you expected? I see [Sheet4], [Sheet1], [Sheet2], [Sheet3] Python2.7.2, Excel 2007 From mail at timgolden.me.uk Wed Aug 10 15:05:00 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Aug 2011 14:05:00 +0100 Subject: [python-win32] Named parameters; Adding Excel sheet In-Reply-To: References: <4E4263E8.3020300@timgolden.me.uk> Message-ID: <4E4281FC.8060702@timgolden.me.uk> On 10/08/2011 13:46, David Robinow wrote: >> >> from win32com.client import Dispatch >> >> app = Dispatch ("Excel.Application") >> app.Visible = 1 # Watch what's going on >> wb = app.Workbooks.Add () >> # [Sheet1], [Sheet2], [Sheet3] >> wb.Sheets.Add (After=wb.Sheets (3)) >> # [Sheet1], [Sheet2], [Sheet3], [Sheet4] >> >> >> >> Do you see the same? And is that what you expected? > I see [Sheet4], [Sheet1], [Sheet2], [Sheet3] > > Python2.7.2, Excel 2007 Interesting. I'm running Excel 2003; might make a difference. Hold on... Nope; my colleague's 2007 install does the same as mine. Another theory; could it be (oddly) to do with static vs dynamic dispatch... Aha! And it is. If I force the use of dynamic dispatch, one of the several differences is that the new sheet appears first as you described. Frankly, I'm not even going to try to determine why that is. My advice is that you change your dispatch line to: app = win32com.client.gencache.EnsureDispatch ("Excel.Application") and go from there. I suspect it will work. TJG From mitch.oliver at gmail.com Wed Aug 10 16:19:09 2011 From: mitch.oliver at gmail.com (Mitch Oliver) Date: Wed, 10 Aug 2011 10:19:09 -0400 Subject: [python-win32] Unhelpful error when adding synthetic NIC Message-ID: I'm using WMI to (attempt to) add a sythetic ethernet port to a Hyper-V VM. I'm getting the following error when I do so: 'testvm' failed to add device 'Microsoft Synthetic Ethernet Port'. (Virtual machine ID B4A091C9-D1AD-4AA9-960D-64E64F620959) The job has an error code of 32785, but I can find no mention of that error in the docs. I'm using the following code to add the NIC: # open the connection to the hyper-v server wmiConn = wmi.WMI('hyperv_server', namespace='virtualization') # get the switch objects switchSvcs = wmiConn.Msvm_VirtualSwitchManagementService()[0] externalSwitch = wmiConn.query("SELECT * from Msvm_VirtualSwitch WHERE ElementName like 'my_switch'")[0] # create a new switch port nicUUID = str(uuid.uuid4()) (newPort, retVal) = switchSvcs.CreateSwitchPort(nicUUID, nicUUID, "", externalSwitch.path_()) # find the default switch syntheticNICs = wmiConn.Msvm_SyntheticEthernetPortSettingData() defaultNIC = [n for n in syntheticNICs if n.InstanceID.rfind('Default') > 0] # clone the default switch into a new object clazz = wmiConn.__getattr__('Msvm_SyntheticEthernetPortSettingData') newNIC = class.new() for prop in defaultNIC._properties: newNIC.Properties_.Item(prop).Value = defaultNIC.Properties_.Item(prop).Value # set data on the new NIC newNIC.Connection = [newPort] newNIC.ElementName = 'Fancy New VM NIC' newNIC.VirtualSystemIdentifiers = [str(uuid.uuid4())] # get the VM to which to add the NIC vm = wmiConn.Msvm_ComputerSystem(ElementName='My Cool VM')[0] # add the nic to the VM mgtSvcs = wmiConn.Msvm_VirtualSystemManagementService()[0] (jobPath, newResources, retVal) = mgtSvcs.AddVirtualSystemResources([newNIC.GetText_(1)], vm.path_()) # check to see if we've started the job... if retVal == 4096: # check the job status instanceID = jobPath.split('=')[1].strip('"') job = wmiConn.Msvm_ConcreteJob(InstanceID=instanceID)[0] while job.JobState == 4: time.sleep(0.1) job = wmiConn.Msvm_ConcreteJob(InstanceID=instanceID)[0] if job.JobState == 10: print '%d, %s', (job.ErrorCode, mgtSvcs.FormatError([job.GetError()[0]])) From andrew.george.hammond at gmail.com Wed Aug 10 21:08:06 2011 From: andrew.george.hammond at gmail.com (Andrew Hammond) Date: Wed, 10 Aug 2011 12:08:06 -0700 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: <4E41EC78.3060002@gmail.com> References: <4E41EC78.3060002@gmail.com> Message-ID: I tried that change and get the exact same error message. I found the code sending the error message in pywin32/win32/src/win32service.i I've extracted what I think are the relevant snippets: 1675 // @flag SERVICE_CONFIG_FAILURE_ACTIONS|Dict representing a SERVICE_FAILURE_ACTIONS struct 1676 case SERVICE_CONFIG_FAILURE_ACTIONS:{ 1677 SERVICE_FAILURE_ACTIONSW buf; 1678 if (!PyWinObject_AsSERVICE_FAILURE_ACTIONS(obinfo, &buf)) 1679 return NULL; 1680 bsuccess=(*fpChangeServiceConfig2)(hService, level, (LPVOID)&buf); 1681 PyWinObject_FreeSERVICE_FAILURE_ACTIONS(&buf); 1682 break; 1683 } Which calls into this: 1584 BOOL PyWinObject_AsSERVICE_FAILURE_ACTIONS(PyObject *obinfo, LPSERVICE_FAILURE_ACTIONSW psfa) 1585 { 1586 static char *sfa_keys[]={"ResetPeriod","RebootMsg","Command","Actions",0}; 1587 static char *err="SERVICE_FAILURE_ACTIONS must be a dictionary containing {'ResetPeriod':int,'RebootMsg':unicode,'lpCommand':unicode,'Actions':sequence of 2 tuples(int,int)"; 1588 PyObject *dummy_tuple, *obActions, *obRebootMsg, *obCommand; 1589 BOOL ret; 1590 ZeroMemory(psfa, sizeof(SERVICE_FAILURE_ACTIONSW)); 1591 if (!PyDict_Check(obinfo)){ 1592 PyErr_SetString(PyExc_TypeError,err); 1593 return FALSE; 1594 } 1595 dummy_tuple=PyTuple_New(0); 1596 if (dummy_tuple==NULL) 1597 return FALSE; 1598 ret=PyArg_ParseTupleAndKeywords(dummy_tuple, obinfo, "lOOO:SERVICE_FAILURE_ACTIONS", sfa_keys, 1599 &psfa->dwResetPeriod, &obRebootMsg, &obCommand, &obActions); 1600 Py_DECREF(dummy_tuple); 1601 if (!ret){ 1602 PyErr_Clear(); 1603 PyErr_SetString(PyExc_TypeError,err); 1604 return FALSE; 1605 } 1606 if (PyWinObject_AsWCHAR(obRebootMsg, &psfa->lpRebootMsg, TRUE) 1607 &&PyWinObject_AsWCHAR(obCommand, &psfa->lpCommand, TRUE) 1608 &&PyWinObject_AsSC_ACTIONS(obActions,&psfa->lpsaActions, &psfa->cActions)) 1609 return TRUE; 1610 PyWinObject_FreeSERVICE_FAILURE_ACTIONS(psfa); 1611 return FALSE; 1612 } So, I'm confused because I think I'm correctly passing it a dict object, yet it appears that PyDict_Check is disagreeing and saying that it is not a dict object. What am I missing? A On Tue, Aug 9, 2011 at 7:27 PM, Randy Syring wrote: > This is a shot in the dark, but if you are on python 2, then: > > 'RebootMsg': '', > 'lpCommand': '', > > Is two strings, not unicode. Maybe: > > 'RebootMsg': u'', > 'lpCommand': u'', > > > -------------------------------------- > Randy Syring > Intelicom > Direct: 502-276-0459 > Office: 502-212-9913 > > For the wages of sin is death, but the > free gift of God is eternal life in > Christ Jesus our Lord (Rom 6:23) > > > On 08/09/2011 08:56 PM, Andrew Hammond wrote: > > I did some more hunting around and now have the following: > > hscm = > win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) > try: > hs = win32serviceutil.SmartOpenService(hscm, cls._svc_name_, > win32service.SERVICE_ALL_ACCESS) > try: > service_failure_actions = { > 'ResetPeriod': 6000000, # Time in seconds after which to > reset the failure count to zero. > 'RebootMsg': '', > 'lpCommand': '', > 'Actions': [(win32service.SC_ACTION_RESTART, 60000), > (win32service.SC_ACTION_RESTART, 60000)] > } > win32service.ChangeServiceConfig2(hs, > win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) > finally: > win32service.CloseServiceHandle(hs) > finally: > win32service.CloseServiceHandle(hscm) > > However, I'm getting the following error message: > > TypeError: SERVICE_FAILURE_ACTIONS must be a dictionary containing > {'ResetPeriod':int,'RebootMsg':unicode,'lpCommand':unicode,'Actions':sequence > of 2 tuples(int,int) > > Which I think is what I'm feeding it. Can someone please tell me what I'm > doing wrong? > > A > > On Mon, Aug 8, 2011 at 7:06 PM, Andrew Hammond < > andrew.george.hammond at gmail.com> wrote: > >> I am trying to control the behavior of a service with regards to failure >> handling as described here: >> http://blogs.msdn.com/b/jcalev/archive/2008/01/10/some-tricks-with-service-restart-logic.aspx >> >> I have done some reading and have the following snippet of code that I >> think is going in the right direction. However I don't know how to create >> the action list. I suspect that it should be an array of unsigned long ints, >> but... ??? >> >> >> hscm = >> win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) >> >> try: >> hs = SmartOpenService(hscm, cls._svc_name_, >> win32service.SERVICE_ALL_ACCESS) >> try: >> # What's the pythonic way to create these??? >> action1 = Action() >> action1.Type = win32service.SC_ACTION_RESTART >> action1.Delay = 600 # 10 minutes? >> >> action2 = Action() >> action2.Type = win32service.SC_ACTION_RESTART >> action2.Delay = 600 >> >> action3 = Action() >> action3.Type = win32service.SC_ACTION_RESTART >> action3.Delay = 600 >> >> win32service.ChangeServiceConfig2( >> hs, >> win32service.SERVICE_CONFIG_FAILURE_ACTIONS, >> [action1,action2,action3] # again, this isn't >> probably right, but... ? >> ) >> finally: >> win32service.CloseServiceHandle(hs) >> finally: >> win32service.CloseServiceHandle(hscm) >> >> Can anyone help please? >> >> Andrew >> > > > > _______________________________________________ > python-win32 mailing listpython-win32 at python.orghttp://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From howard at eegsoftware.com Wed Aug 10 23:17:10 2011 From: howard at eegsoftware.com (Howard Lightstone) Date: Wed, 10 Aug 2011 14:17:10 -0700 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: References: <4E41EC78.3060002@gmail.com> Message-ID: On Wed, Aug 10, 2011 at 1:54 PM, Andrew Hammond < andrew.george.hammond at gmail.com> wrote: > Bingo! Thanks very much!!! > > A > > > On Wed, Aug 10, 2011 at 12:54 PM, Howard Lightstone < > howard at eegsoftware.com> wrote: > >> Maybe because sfa_keys thinks the correct key is "Command" and not >> "lpCommand"? >> >> Sorry, in haste, I forgot to post this to the list for future searches. -- Howard Lightstone howard at eegsoftware.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrew.george.hammond at gmail.com Wed Aug 10 23:31:23 2011 From: andrew.george.hammond at gmail.com (Andrew Hammond) Date: Wed, 10 Aug 2011 14:31:23 -0700 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: References: <4E41EC78.3060002@gmail.com> Message-ID: Howard Lightstone pointed out that sfa_keys thinks that the correct key is "Command" not "lpCommand" as the error message says. Working code follows: hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) try: hs = win32serviceutil.SmartOpenService(hscm, svc_name, win32service.SERVICE_ALL_ACCESS) try: service_failure_actions = { 'ResetPeriod': 6000000, # Time in ms after which to reset the failure count to zero. 'RebootMsg': u'', # Not using reboot option 'Command': u'', # Not using run-command option 'Actions': [ (win32service.SC_ACTION_RESTART, 60000), # action, delay in ms (win32service.SC_ACTION_RESTART, 60000) ] } win32service.ChangeServiceConfig2(hs, win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) finally: win32service.CloseServiceHandle(hs) finally: win32service.CloseServiceHandle(hscm) I suggest the attached patch to correct the error message. Andrew On Wed, Aug 10, 2011 at 12:08 PM, Andrew Hammond < andrew.george.hammond at gmail.com> wrote: > I tried that change and get the exact same error message. I found the code > sending the error message in pywin32/win32/src/win32service.i > I've extracted what I think are the relevant snippets: > > 1675 // @flag SERVICE_CONFIG_FAILURE_ACTIONS|Dict representing a > SERVICE_FAILURE_ACTIONS struct > 1676 case SERVICE_CONFIG_FAILURE_ACTIONS:{ > 1677 SERVICE_FAILURE_ACTIONSW buf; > 1678 if (!PyWinObject_AsSERVICE_FAILURE_ACTIONS(obinfo, &buf)) > 1679 return NULL; > 1680 bsuccess=(*fpChangeServiceConfig2)(hService, level, > (LPVOID)&buf); > 1681 PyWinObject_FreeSERVICE_FAILURE_ACTIONS(&buf); > 1682 break; > 1683 } > > Which calls into this: > > 1584 BOOL PyWinObject_AsSERVICE_FAILURE_ACTIONS(PyObject *obinfo, > LPSERVICE_FAILURE_ACTIONSW psfa) > 1585 { > 1586 static char > *sfa_keys[]={"ResetPeriod","RebootMsg","Command","Actions",0}; > 1587 static char *err="SERVICE_FAILURE_ACTIONS must be a dictionary > containing > {'ResetPeriod':int,'RebootMsg':unicode,'lpCommand':unicode,'Actions':sequence > of 2 tuples(int,int)"; > 1588 PyObject *dummy_tuple, *obActions, *obRebootMsg, *obCommand; > 1589 BOOL ret; > 1590 ZeroMemory(psfa, sizeof(SERVICE_FAILURE_ACTIONSW)); > 1591 if (!PyDict_Check(obinfo)){ > 1592 PyErr_SetString(PyExc_TypeError,err); > 1593 return FALSE; > 1594 } > 1595 dummy_tuple=PyTuple_New(0); > 1596 if (dummy_tuple==NULL) > 1597 return FALSE; > 1598 ret=PyArg_ParseTupleAndKeywords(dummy_tuple, obinfo, > "lOOO:SERVICE_FAILURE_ACTIONS", sfa_keys, > 1599 &psfa->dwResetPeriod, &obRebootMsg, &obCommand, &obActions); > 1600 Py_DECREF(dummy_tuple); > 1601 if (!ret){ > 1602 PyErr_Clear(); > 1603 PyErr_SetString(PyExc_TypeError,err); > 1604 return FALSE; > 1605 } > 1606 if (PyWinObject_AsWCHAR(obRebootMsg, &psfa->lpRebootMsg, TRUE) > 1607 &&PyWinObject_AsWCHAR(obCommand, &psfa->lpCommand, TRUE) > 1608 &&PyWinObject_AsSC_ACTIONS(obActions,&psfa->lpsaActions, > &psfa->cActions)) > 1609 return TRUE; > 1610 PyWinObject_FreeSERVICE_FAILURE_ACTIONS(psfa); > 1611 return FALSE; > 1612 } > > So, I'm confused because I think I'm correctly passing it a dict object, > yet it appears that PyDict_Check is disagreeing and saying that it is not a > dict object. What am I missing? > > A > > > > > On Tue, Aug 9, 2011 at 7:27 PM, Randy Syring wrote: > >> This is a shot in the dark, but if you are on python 2, then: >> >> 'RebootMsg': '', >> 'lpCommand': '', >> >> Is two strings, not unicode. Maybe: >> >> 'RebootMsg': u'', >> 'lpCommand': u'', >> >> >> -------------------------------------- >> Randy Syring >> Intelicom >> Direct: 502-276-0459 >> Office: 502-212-9913 >> >> For the wages of sin is death, but the >> free gift of God is eternal life in >> Christ Jesus our Lord (Rom 6:23) >> >> >> On 08/09/2011 08:56 PM, Andrew Hammond wrote: >> >> I did some more hunting around and now have the following: >> >> hscm = >> win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) >> try: >> hs = win32serviceutil.SmartOpenService(hscm, cls._svc_name_, >> win32service.SERVICE_ALL_ACCESS) >> try: >> service_failure_actions = { >> 'ResetPeriod': 6000000, # Time in seconds after which to >> reset the failure count to zero. >> 'RebootMsg': '', >> 'lpCommand': '', >> 'Actions': [(win32service.SC_ACTION_RESTART, 60000), >> (win32service.SC_ACTION_RESTART, 60000)] >> } >> win32service.ChangeServiceConfig2(hs, >> win32service.SERVICE_CONFIG_FAILURE_ACTIONS, service_failure_actions) >> finally: >> win32service.CloseServiceHandle(hs) >> finally: >> win32service.CloseServiceHandle(hscm) >> >> However, I'm getting the following error message: >> >> TypeError: SERVICE_FAILURE_ACTIONS must be a dictionary containing >> {'ResetPeriod':int,'RebootMsg':unicode,'lpCommand':unicode,'Actions':sequence >> of 2 tuples(int,int) >> >> Which I think is what I'm feeding it. Can someone please tell me what >> I'm doing wrong? >> >> A >> >> On Mon, Aug 8, 2011 at 7:06 PM, Andrew Hammond < >> andrew.george.hammond at gmail.com> wrote: >> >>> I am trying to control the behavior of a service with regards to failure >>> handling as described here: >>> http://blogs.msdn.com/b/jcalev/archive/2008/01/10/some-tricks-with-service-restart-logic.aspx >>> >>> I have done some reading and have the following snippet of code that I >>> think is going in the right direction. However I don't know how to create >>> the action list. I suspect that it should be an array of unsigned long ints, >>> but... ??? >>> >>> >>> hscm = >>> win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS) >>> >>> try: >>> hs = SmartOpenService(hscm, cls._svc_name_, >>> win32service.SERVICE_ALL_ACCESS) >>> try: >>> # What's the pythonic way to create these??? >>> action1 = Action() >>> action1.Type = win32service.SC_ACTION_RESTART >>> action1.Delay = 600 # 10 minutes? >>> >>> action2 = Action() >>> action2.Type = win32service.SC_ACTION_RESTART >>> action2.Delay = 600 >>> >>> action3 = Action() >>> action3.Type = win32service.SC_ACTION_RESTART >>> action3.Delay = 600 >>> >>> win32service.ChangeServiceConfig2( >>> hs, >>> win32service.SERVICE_CONFIG_FAILURE_ACTIONS, >>> [action1,action2,action3] # again, this isn't >>> probably right, but... ? >>> ) >>> finally: >>> win32service.CloseServiceHandle(hs) >>> finally: >>> win32service.CloseServiceHandle(hscm) >>> >>> Can anyone help please? >>> >>> Andrew >>> >> >> >> >> _______________________________________________ >> python-win32 mailing listpython-win32 at python.orghttp://mail.python.org/mailman/listinfo/python-win32 >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: correct_ChangeServiceConfig2_error_message.patch Type: application/octet-stream Size: 847 bytes Desc: not available URL: From python at bdurham.com Wed Aug 10 23:46:56 2011 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Aug 2011 17:46:56 -0400 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: References: <4E41EC78.3060002@gmail.com> Message-ID: <1313012816.11368.140258128284181@webmail.messagingengine.com> Andrew, Thanks for sharing the solution! Regards, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Sat Aug 13 03:05:37 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 13 Aug 2011 11:05:37 +1000 Subject: [python-win32] manipulating service action restart behavior? In-Reply-To: References: <4E41EC78.3060002@gmail.com> Message-ID: <4E45CDE1.50800@gmail.com> On 11/08/2011 7:31 AM, Andrew Hammond wrote: ... > I suggest the attached patch to correct the error message. Excellent, thanks! I checked it in. Cheers, Mark From banditza at gmail.com Tue Aug 16 15:57:35 2011 From: banditza at gmail.com (Jacob Kruger) Date: Tue, 16 Aug 2011 15:57:35 +0200 Subject: [python-win32] Trying to make use of pyAudiere Message-ID: http://www.pyaudiere.org/ >From within either the interpreter, or from within my own .py files, it always seems to complain about importing (internally) numpy.core.multiarray module, but on the second import call to audiere itsself, it's fine, and works well enough. However, when I then try to build the code into a sort of redistributable .exe file, I get notified that: MSVCP90.dll no such file or directory That is however one of the files under the MS VCRT subfolder in the dist subdirectory that none of the other, copied setup.py files used for py2exe complain about, so sort of assuming it has something to do with a referral to a version from within audiere or something. Anyway, just wondering if anyone else has made real use of pyAudiere, or something else similar enough/simple enough, without similar issues? Basically I just would like to get hold of a relatively platform independent module to let me preferably play, pan and manipulate the playback of a couple of different audio file types, but even if limited to only clean .wav files that would still be better than nothing, but anyway...? Have also looked into pygame, but it's got a lot more in it than I really need/want, and it's also given me some minor issues relating to trying to then build redistributable executables, etc., and this one really/honestly seems more suitable/more like what I actually want it for. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From cappy2112 at gmail.com Wed Aug 17 15:36:16 2011 From: cappy2112 at gmail.com (Tony Cappellini) Date: Wed, 17 Aug 2011 06:36:16 -0700 Subject: [python-win32] Trying to make use of pyAudiere Message-ID: > From: Jacob Kruger > To: python-win32 at python.org > Subject: [python-win32] Trying to make use of pyAudiere > Message-ID: > Content-Type: text/plain; charset=iso-8859-1 > > http://www.pyaudiere.org/ > > >From within either the interpreter, or from within my own .py files, it always seems to complain about importing (internally) numpy.core.multiarray module, but on the second import call to audiere itsself, it's fine, and works well enough. > Sadly to say, there doesn't seem to be much development for packages which support audio processing for Python. I hadn't heard of pyAudiere until your message was posted. PySonic was the only other package I was aware of, but that hasn't been updated since 2005 and only has installers for windows. From blindza at gmail.com Wed Aug 17 15:49:54 2011 From: blindza at gmail.com (Jacob Kruger) Date: Wed, 17 Aug 2011 15:49:54 +0200 Subject: [python-win32] Trying to make use of pyAudiere In-Reply-To: Message-ID: Maybe I'll check it out (pySonic) in any case. Once audiere is imported it seems to work nicely/well enough, but would be nice if could get it to import/load easily enough, but anyway. Thanks Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message --------------- Subject: Re: [python-win32] Trying to make use of pyAudiere From: Tony Cappellini Date: Wed, 17 Aug 2011 06:36:16 -0700 To: python-win32 at python.org Cc: banditza at gmail.com >> From: Jacob Kruger >> To: python-win32 at python.org >> Subject: [python-win32] Trying to make use of pyAudiere >> Message-ID: >> Content-Type: text/plain; charset=iso-8859-1 >> >> http://www.pyaudiere.org/ >> >> >From within either the interpreter, or from within my own .py files, it always seems to complain about importing (internally) numpy.core.multiarray module, but on the second import call to audiere itsself, it's fine, and works well enough. >> >Sadly to say, there doesn't seem to be much development for packages >which support audio processing for Python. >I hadn't heard of pyAudiere until your message was posted. PySonic was >the only other package I was aware of, but that hasn't been updated >since 2005 and only has installers for windows. >_______________________________________________ >python-win32 mailing list >python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From ruidc at yahoo.com Wed Aug 17 17:02:32 2011 From: ruidc at yahoo.com (RuiDC) Date: Wed, 17 Aug 2011 08:02:32 -0700 (PDT) Subject: [python-win32] CF_ENHMETAFILE SetClipboardData 'The handle is invalid' Message-ID: <32280484.post@talk.nabble.com> import win32clipboard filename = r"C:\tmp\test.emf" with open(filename, "rb") as f: data = f.read() win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(win32clipboard.CF_ENHMETAFILE, data) win32clipboard.CloseClipboard() why do I get the below message? pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.') -- View this message in context: http://old.nabble.com/CF_ENHMETAFILE-SetClipboardData-%27The-handle-is-invalid%27-tp32280484p32280484.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From ruidc at yahoo.com Wed Aug 17 17:16:02 2011 From: ruidc at yahoo.com (RuiDC) Date: Wed, 17 Aug 2011 08:16:02 -0700 (PDT) Subject: [python-win32] CF_ENHMETAFILE SetClipboardData 'The handle is invalid' In-Reply-To: <32280484.post@talk.nabble.com> References: <32280484.post@talk.nabble.com> Message-ID: <32280577.post@talk.nabble.com> import win32clipboard print(win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_ENHMETAFILE)) print(win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_DIB)) retruns 0 for both... how can i make these available? RuiDC wrote: > > import win32clipboard > > filename = r"C:\tmp\test.emf" > with open(filename, "rb") as f: > data = f.read() > win32clipboard.OpenClipboard() > win32clipboard.EmptyClipboard() > win32clipboard.SetClipboardData(win32clipboard.CF_ENHMETAFILE, data) > win32clipboard.CloseClipboard() > > why do I get the below message? > > pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.') > -- View this message in context: http://old.nabble.com/CF_ENHMETAFILE-SetClipboardData-%27The-handle-is-invalid%27-tp32280484p32280577.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From matteo.boscolo at boscolini.eu Thu Aug 18 10:25:26 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Thu, 18 Aug 2011 10:25:26 +0200 Subject: [python-win32] Com Add In error : _QueryInterface_ with unsupported IID In-Reply-To: <32280577.post@talk.nabble.com> References: <32280484.post@talk.nabble.com> <32280577.post@talk.nabble.com> Message-ID: <4E4CCC76.2070304@boscolini.eu> Hi all, I have done an addin fro a cad application I get this error from win32Traceutils : Object with win32trace dispatcher created (object=None) in ._QueryInterface_ with unsupported IID ISwAddin ({DA306A0D-EAC5-4406-8610-B1DA805D9270}) in ._QueryInterface_ with unsupported IID ISwPointInferenceBroker ({043ABA21-BC20-4C46-A8D4-C8C0B67707A9}) in ._QueryInterface_ with unsupported IID ISwAddinBroker ({F8D48077-9710-4661-81AF-5AFB30000E99}) in ._QueryInterface_ with unsupported IID ISwAddinLicenseManager ({1C0CCD98-368B-4CD3-B168-901395224693}) in ._QueryInterface_ with unsupported IID ISwAddinAdvanced can anyone help me on this ? This is the com class implemented: class swAddin(object): _reg_clsid_ = "{4D6515EF-33AD-4019-A416-A4D5310C907F}" _reg_desc_ = "OpenERPPLM Com Server" _reg_progid_ = "OpenERPPLM.pyComServer" _public_methods_=[ 'ConnectToSW', 'DisconnectFromSW' ] def __init__(self): self._swApplication=None self._cookie=None def ConnectToSW(self,swInstance, cookie): try: print "here" #self._swApplication = swInstance #self._cookie = cookie return True except Exception,ex: return False def DisconnectFromSW(self): print "there" return True if __name__=='__main__': print "Start register com class" import sys import win32com.server.register sys.argv.append('--debug') win32com.server.register.UseCommandLine(swAddin) print "End register com class" Regards, Matteo From wtwinsoftware at gmail.com Thu Aug 18 17:10:14 2011 From: wtwinsoftware at gmail.com (Kevin Walzer) Date: Thu, 18 Aug 2011 11:10:14 -0400 Subject: [python-win32] Questions about deploying COM server via py2exe Message-ID: Hi all, I'm working on a Tkinter app that is being deployed to Windows via py2exe for wrapping and InnoSetup for its installer. In order to provide a similar scripting capability to the app that is present in its Mac version, I've made the app a COM server using the examples from python-win32 code base. I am running into two issues with the app that I would like some clarification on: 1. What is the best way to register the exe as a COM server? I'm using the code from the python-win32 extension to register the code dynamically, but on Windows 7 this requires administrator privileges--which means that the entire app must be run as an administrator (via a flag in py2exe). This works, but seems overkill. I understand from the list archives that there is no current built-in way to escalate UAC privileges for a single function, cf. to register the server. Is there another way to register the wrapped exe as a server, i.e. from the command line (regsvr32) during the installation phase? 2. I am testing the app via a simple vbscript with a create object() call and then running the command exported by the COM server. While my app launches, it blocks forever, and then eventually the Windows Scripting Host times out with an error ("couldn't create ActiveX object"). Any suggestions on how to debug this? I can find no obvious error in my code and the app does start up successfully, which tells me it's registered, but for some reason it locks up before it can run its command. (The app does pop up a dialog on startup, I don't know if that would have any effect or not.) Thanks, Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From nosebluntslide at gmx.net Thu Aug 18 19:16:58 2011 From: nosebluntslide at gmx.net (=?utf-8?B?bm9zZWJsdW50c2xpZGVAZ214Lm5ldA==?=) Date: Thu, 18 Aug 2011 19:16:58 +0200 Subject: [python-win32] =?utf-8?q?Problems_passing_VARIANT_SAFEARRAY_datat?= =?utf-8?q?ype?= Message-ID: <3RfvR560L1zN5Z@mail.python.org> hi there! in short: is there a way to create a datatype in python like this: VARIANT(SAFEARRAY(byte[...])) of arbitrary size ?? problem is the COM-interface of the software i want to communicate with expects a value of the mentioned datatype from me. so when i'm initializing an attribute of the used COM-object with a common tuple like (1,2,3,4,5,6,7,8,9,10) i get (3,0,149,0,0,0,0,0,1,0) back reading it... i read somewhere, that python allegedly passes VARIANT(SAFEARRAY(VARIANT (...))) when delivering a tuple to a COM-structure. so i was trying to fix that by using the comtypes- and array-lib. but creating an array with uint8 values didn't work out also... to get hints about the COM-interface and to avoid conversion-mistakes i already did a makepy - still not working! i should say that i just getting started with COM, but i am programming python for some years. so, maybe i'm not informed enough about python-COM until now...or maybe i just reached my limits ! :) hope you guys can help me out!! thanks in advance seb -------------- next part -------------- An HTML attachment was scrubbed... URL: From matteo.boscolo at boscolini.eu Fri Aug 19 09:01:19 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Fri, 19 Aug 2011 09:01:19 +0200 Subject: [python-win32] Questions about deploying COM server via py2exe In-Reply-To: References: Message-ID: <4E4E0A3F.5010400@boscolini.eu> Hi Kevin , Il 18/08/2011 17:10, Kevin Walzer ha scritto: > Hi all, > > I'm working on a Tkinter app that is being deployed to Windows via > py2exe for wrapping and InnoSetup for its installer. In order to > provide a similar scripting capability to the app that is present in > its Mac version, I've made the app a COM server using the examples > from python-win32 code base. > > I am running into two issues with the app that I would like some > clarification on: > > 1. What is the best way to register the exe as a COM server? I'm using > the code from the python-win32 extension to register the code > dynamically, but on Windows 7 this requires administrator > privileges--which means that the entire app must be run as an > administrator (via a flag in py2exe). This works, but seems overkill. > I understand from the list archives that there is no current built-in > way to escalate UAC privileges for a single function, cf. to register > the server. Is there another way to register the wrapped exe as a > server, i.e. from the command line (regsvr32) during the installation > phase? For registering the com server we use innosetup with the following line [Run] Filename: "{app}\openclerk.exe"; Parameters: "/regserver"; WorkingDir: "{app}" ; StatusMsg: "Registering openclerk.exe ..." > > 2. I am testing the app via a simple vbscript with a create object() > call and then running the command exported by the COM server. While my > app launches, it blocks forever, and then eventually the Windows > Scripting Host times out with an error ("couldn't create ActiveX > object"). Any suggestions on how to debug this? usually you get this error because you miss some reference into py2exe the way that we use to trace this error is to try catch all com method even the __init__ and use the logging system: here you get an example: def SetIntegration(self, integrationObject, activeEditor=""): """ set the integration object """ try: except: print_exc_plus() return E_FAIL return S_O def print_exc_plus(): """ Print the usual traceback information, followed by a listing of all the local variables in each frame. """ logging.error("*"*20) for m in sys.exc_info(): logging.error(str(m)) logging.error("*"*20) tb = sys.exc_info( )[2] while tb.tb_next: tb = tb.tb_next stack = [ ] f = tb.tb_frame while f: stack.append(f) f = f.f_back stack.reverse( ) traceback.print_exc() logging.error( "Locals by frame, innermost last") for frame in stack: logging.error("Frame %s in %s at line %s" % (frame.f_code.co_name, frame.f_code.co_filename, frame.f_lineno)) for key, value in frame.f_locals.items(): # we must _absolutely_ avoid propagating exceptions, and str(value) # COULD cause any exception, so we MUST catch any...: try: logging.error("\t%20s = %s"%(key ,str(value))) except: logging.error( "") Regards, Matteo > I can find no obvious error in my code and the app does start up > successfully, which tells me it's registered, but for some reason it > locks up before it can run its command. (The app does pop up a dialog > on startup, I don't know if that would have any effect or not.) > > Thanks, > Kevin > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > Nessun virus nel messaggio. > Controllato da AVG - www.avg.com > Versione: 10.0.1392 / Database dei virus: 1520/3841 - Data di > rilascio: 17/08/2011 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From blindza at gmail.com Fri Aug 19 12:57:07 2011 From: blindza at gmail.com (Jacob Kruger) Date: Fri, 19 Aug 2011 12:57:07 +0200 Subject: [python-win32] PyCharm rather inaccessible/useless to me as such Message-ID: Ok, thought would try out the 30 day demo/trial of PyCharm, but their whole interface is apparently done in something with no accessibility information in it, or something since tabbing around in interface, nothing gets mentioned to me, and not even sure if it has a menu system as such, so, for now will be sticking to text editor, or maybe try out eclipse, since that's what they want me to use here at work in any case, but anyway... Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From vernondcole at gmail.com Fri Aug 19 15:31:25 2011 From: vernondcole at gmail.com (Vernon Cole) Date: Fri, 19 Aug 2011 07:31:25 -0600 Subject: [python-win32] PyCharm rather inaccessible/useless to me as such In-Reply-To: References: Message-ID: The entire idea of a Python IDE written in java is frightening to me... Vernon Cole (sent from my 'droid phone) -------------- next part -------------- An HTML attachment was scrubbed... URL: From M.Schulte-Oversohl at pragmatis.de Fri Aug 19 16:12:38 2011 From: M.Schulte-Oversohl at pragmatis.de (Manfred Schulte-Oversohl) Date: Fri, 19 Aug 2011 16:12:38 +0200 Subject: [python-win32] Pythonwin Combobox Message-ID: I played with controls on a window (no dialog). For example an edit control with CreateEdit() and everything works fine. I'd like to use a combobox control. Getting it with dialog is no problem. But I could not create a combobox on a window. With the following code I got an error by CreateWindowEx. When it worked (for example with wclass="PyCListCtrl") I get an error with GetDlgItem(): win32ui: Internal error - existing object has type 'PyCWnd', but 'PyCListCtrl' was requested. class MyCtrl(window.Wnd): def __init__(self): window.Wnd.__init__(self, win32ui.CreateWnd()) def CreateWindowEx(self, ex_style, wnclass, text, style, rect, parent, id): self._obj_.CreateWindow(wnclass, text, style, rect, parent, id, None) def DivCtrl(parent, wclass="COMBOBOX", text=None, rect=(10,200,120,250),id=1021): d = MyCtrl() cs = (win32con.WS_CHILD | win32con.WS_VISIBLE) ccs = cs | win32con.CBS_DISABLENOSCROLL | win32con.CBS_DROPDOWN d.CreateWindowEx(win32con.WS_EX_CLIENTEDGE, wclass, text, ccs, rect, parent, id) return d Is there any chance to get a combobox? Could a CreateCombobox() - or other controls - be created by python? Or is the only solution to make one with an ocx control? I'm grateful for any suggestion. Manfred -------------- next part -------------- An HTML attachment was scrubbed... URL: From sirgnip at gmail.com Fri Aug 19 21:40:06 2011 From: sirgnip at gmail.com (Scott Nelson) Date: Fri, 19 Aug 2011 14:40:06 -0500 Subject: [python-win32] SHOpenFolderAndSelectItems Message-ID: Greetings, I'm looking to get access to the shell function: SHOpenFolderAndSelectItems (MSDN: http://msdn.microsoft.com/en-us/library/bb762232(v=VS.85).aspx) But, after looking around for quite some time (and googling, and searching the pywin32 archives, reading examples...), I am not able to find it. Though, I believe I am close as a good number of win32 shell functions are displayed when I do the following: >>> from win32com.shell import shell >>> print('\n'.join(sorted(dir(shell)))) >>> shell.SHOpenFolderAndSelectedItems Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'SHOpenFolderAndSelectedItems' I am using Python 3.2 with pywin32-216.win-amd64-py3.2 installed in a 64 bit Windows 7 machine. Does pywin have support for SHOpenFolderAndSelectItems()? If so, where is it located? I'm new to the pywin32 world, so let me know if I'm missing something obvious. Many thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sat Aug 20 02:25:40 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 20 Aug 2011 12:25:40 +1200 Subject: [python-win32] Pythonwin Combobox In-Reply-To: References: Message-ID: <4E4EFF04.9020703@canterbury.ac.nz> Manfred Schulte-Oversohl wrote: > I'd like to use a combobox control. Getting it with dialog is no problem. > > But I could not create a combobox on a window. I had the same problem -- pywin32 is missing a CreateComboBox function. After much frustration, I found the following workaround: hwnd = win32gui.CreateWindow("COMBOBOX", ...) pycwnd = win32ui.CreateWindowFromHandle(hwnd) -- Greg From wtwinsoftware at gmail.com Sat Aug 20 05:29:13 2011 From: wtwinsoftware at gmail.com (Kevin Walzer) Date: Fri, 19 Aug 2011 23:29:13 -0400 Subject: [python-win32] Questions about deploying COM server via py2exe In-Reply-To: <4E4E0A3F.5010400@boscolini.eu> References: <4E4E0A3F.5010400@boscolini.eu> Message-ID: <0A17F234BC7E4AACBBE780471E8ED193@KevinPC> For registering the com server we use innosetup with the following line [Run] Filename: "{app}\openclerk.exe"; Parameters: "/regserver"; WorkingDir: "{app}" ; StatusMsg: "Registering openclerk.exe ..." --- I?ve used a variation of this techinque, it seems to work fine. Thanks. usually you get this error because you miss some reference into py2exe the way that we use to trace this error is to try catch all com method even the __init__ and use the logging system: ---- I haven?t been able to figure out how to integrate your example into my own code. The COM/py2exe integration is wholly opaque to me. Here is my code, can you or anyone else suggest what I might be doing wrong? from quickwho_main import quickwhoApp import time import tempfile from win32com.server.exception import COMException import winerror import win32com.server.register #expose basic functionality to COM class QuickWho_Domain: _public_methods_ = ['GetDomain'] _reg_progid_ = 'QuickWho.Application' _reg_clsid_= '{9F825846-F10B-47DD-91E8-88DA93C1A05E}' def GetDomain(self, domain): try: app.searchfield.delete(0, 'end') app.searchfield.insert(0, str(domain)) app.getInfo() time.sleep(1) alltext=app.getData() tempfile = tempfile.gettempdir()+ '/urltext.txt' data = open(tempfile, 'r') finaltext = data.read() data.close() return finaltext except: raise COMException(desc='Unable to retrieve domain data', scode=winerror.E_FAIL) try: win32com.server.register.RegisterClasses(QuickWho_Domain) except: pass app = quickwhoApp(None) app.mainloop() The idea is to use the COM method (GetDomain) to drive the app?s UI (which in turn fires to external executables via subprocess), parse the data, display it in the GUI , and then return the data to the calling application. Is this how COM is supposed to work? This is how the app works on the Mac in responding to AppleScript calls. Perhaps it?s not the right mechanism for Windows, although I don?t know of a better one that can be accessed from the MS desktop scripting languages, cf. VBScript. Suggestions are appreciated. I?m about to give up on this, as I can?t grok it. --Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From matteo.boscolo at boscolini.eu Sat Aug 20 08:44:10 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Sat, 20 Aug 2011 08:44:10 +0200 Subject: [python-win32] Questions about deploying COM server via py2exe In-Reply-To: <0A17F234BC7E4AACBBE780471E8ED193@KevinPC> References: <4E4E0A3F.5010400@boscolini.eu> <0A17F234BC7E4AACBBE780471E8ED193@KevinPC> Message-ID: <4E4F57BA.7020206@boscolini.eu> Hi Kevin, run this script and it will be registered for debug .. run the win32traceutil.py as mentioned in the following link : http://www.boscolini.eu/Boscolini/index.php?option=com_content&view=article&id=62%3Apython-win32debug-tutorial&catid=38%3Aprogramming&Itemid=55&lang=en now you get the trace in the win32traceutil.py .. so you can use print to debug your code I do not know what the quickwhoApp dose, but I think that if you call the mainloop method all the events are stopped there so you are not able to access other method .. if you send me the code I can give a look at .. Regards, Matteo from quickwho_main import quickwhoApp import time import tempfile from win32com.server.exception import COMException import winerror import win32com.server.register #expose basic functionality to COM class QuickWho_Domain: _public_methods_ = ['GetDomain'] _reg_progid_ = 'QuickWho.Application' _reg_clsid_= '{9F825846-F10B-47DD-91E8-88DA93C1A05E}' def GetDomain(self, domain): try: app.searchfield.delete(0, 'end') app.searchfield.insert(0, str(domain)) app.getInfo() time.sleep(1) alltext=app.getData() tempfile = tempfile.gettempdir()+ '/urltext.txt' data = open(tempfile, 'r') finaltext = data.read() data.close() return finaltext except Exception ,ex: exMsg='Unable to retrieve domain data '+str(ex) raise COMException(desc=exMsg, scode=winerror.E_FAIL) if __name__=="__main__": print "*"*20 import sys import win32com.server.register sys.argv.append('--debug') win32com.server.register.UseCommandLine(QuickWho_Domain) print "*"*20 try: app = quickwhoApp(None) app.mainloop() except Exception ,ex: print "error !! " + str(ex) Il 20/08/2011 05:29, Kevin Walzer ha scritto: > ** > For registering the com server we use innosetup with the following line > [Run] > Filename: "{app}\openclerk.exe"; Parameters: "/regserver"; WorkingDir: > "{app}" ; StatusMsg: "Registering openclerk.exe ..." > --- > I?ve used a variation of this techinque, it seems to work fine. Thanks. >> usually you get this error because you miss some reference into py2exe >> the way that we use to trace this error is to try catch all com >> method even the __init__ and use the logging system: >> ---- > I haven?t been able to figure out how to integrate your example into > my own code. The COM/py2exe integration is wholly opaque to me. Here > is my code, can you or anyone else suggest what I might be doing wrong? > from quickwho_main import quickwhoApp > import time > import tempfile > from win32com.server.exception import COMException > import winerror > import win32com.server.register > #expose basic functionality to COM > class QuickWho_Domain: > _public_methods_ = ['GetDomain'] > _reg_progid_ = 'QuickWho.Application' > _reg_clsid_= '{9F825846-F10B-47DD-91E8-88DA93C1A05E}' > def GetDomain(self, domain): > try: > app.searchfield.delete(0, 'end') > app.searchfield.insert(0, str(domain)) > app.getInfo() > time.sleep(1) > alltext=app.getData() > tempfile = tempfile.gettempdir()+ '/urltext.txt' > data = open(tempfile, 'r') > finaltext = data.read() > data.close() > return finaltext > except: > raise COMException(desc='Unable to retrieve domain data', > scode=winerror.E_FAIL) > try: > win32com.server.register.RegisterClasses(QuickWho_Domain) > except: > pass > app = quickwhoApp(None) > app.mainloop() > The idea is to use the COM method (GetDomain) to drive the app?s UI > (which in turn fires to external executables via subprocess), parse > the data, display it in the GUI , and then return the data to the > calling application. Is this how COM is supposed to work? This is how > the app works on the Mac in responding to AppleScript calls. Perhaps > it?s not the right mechanism for Windows, although I don?t know of a > better one that can be accessed from the MS desktop scripting > languages, cf. VBScript. > Suggestions are appreciated. I?m about to give up on this, as I can?t > grok it. > --Kevin > ------------------------------------------------------------------------ > > Nessun virus nel messaggio. > Controllato da AVG - www.avg.com > Versione: 10.0.1392 / Database dei virus: 1520/3844 - Data di > rilascio: 19/08/2011 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From M.Schulte-Oversohl at pragmatis.de Sat Aug 20 18:45:10 2011 From: M.Schulte-Oversohl at pragmatis.de (Manfred Schulte-Oversohl) Date: Sat, 20 Aug 2011 18:45:10 +0200 Subject: [python-win32] Pythonwin Combobox In-Reply-To: <4E4EFF04.9020703@canterbury.ac.nz> References: <4E4EFF04.9020703@canterbury.ac.nz> Message-ID: Hi Greg, that did exactly what I want! Thank you very much. Cheers Manfred -------------- next part -------------- An HTML attachment was scrubbed... URL: From wtwinsoftware at gmail.com Sat Aug 20 20:30:38 2011 From: wtwinsoftware at gmail.com (Kevin Walzer) Date: Sat, 20 Aug 2011 14:30:38 -0400 Subject: [python-win32] Questions about deploying COM server via py2exe In-Reply-To: <4E4F57BA.7020206@boscolini.eu> References: <4E4E0A3F.5010400@boscolini.eu> <0A17F234BC7E4AACBBE780471E8ED193@KevinPC> <4E4F57BA.7020206@boscolini.eu> Message-ID: Hi Matteo, Thanks for the suggestions. I have integrated the win32trace module into my frozen app. Here is my final code: from quickwho_main import quickwhoApp import time import tempfile from win32com.server.exception import COMException import winerror import win32com.server.register import win32traceutil import sys sys.stdout = open('C:/Users/Kevin/Desktop/my_stdout.log', 'w') sys.stderr = open('C:/Users/Kevin/Desktop/my_stderr.log', 'w') #expose basic functionality to COM class QuickWho_Domain: _public_methods_ = ['GetDomain'] _reg_progid_ = 'QuickWho.Application' _reg_clsid_= '{9F825846-F10B-47DD-91E8-88DA93C1A05E}' def GetDomain(self, domain): try: app.searchfield.delete(0, 'end') app.searchfield.insert(0, str(domain)) app.getInfo() time.sleep(1) alltext=app.getData() tempfile = tempfile.gettempdir()+ '/urltext.txt' data = open(tempfile, 'r') finaltext = data.read() data.close() return finaltext except Exception ,ex: exMsg='Unable to retrieve domain data '+str(ex) raise COMException(desc=exMsg, scode=winerror.E_FAIL) print "*"*20 import win32com.server.register sys.argv.append('--debug') win32com.server.register.UseCommandLine(QuickWho_Domain) print "*"*20 try: app = quickwhoApp(None) app.mainloop() except Exception ,ex: print "error !! " + str(ex) (I put the code into a frozen app because it isn?t practical to debug the app itself when run as a Python module?it won?t be deployed that way.) I did get some debugging output, though not what I expected: Exception in Tkinter callback Traceback (most recent call last): File "Tkinter.pyc", line 1410, in __call__ File "quickwho_main.pyc", line 159, in File "quickwho_main.pyc", line 253, in getInfo File "subprocess.pyc", line 537, in check_output File "subprocess.pyc", line 672, in __init__ File "subprocess.pyc", line 784, in _get_handles File "subprocess.pyc", line 823, in _make_inheritable WindowsError: [Error 6] The handle is invalid This appears to be related to the bug logged at http://bugs.python.org/issue3905. My app makes use of subprocess to obtain various bits of data that it then parses and displays in its UI. For what it?s worth, injecting the trace module into my frozen app causes no output to appear at all in the app itself, and returns the error above; the trace module seems to trigger the suprocess bug. However, it seems to have no bearing at all on the failure of VBScript to create a COM object from my application, and the debugging output logged to my stdout/stderr file did not yield any insight on that. I investigated whether running the mainloop() in the app might interfere with the application receiving the COM request from the Windows Script Host, but commenting out the mainloop only caused the app to crash (since Tkinter apps require a mainloop to run). The bottom line of all this investigation is that I am no closer to understanding why my Tkinter app does not respond to the CreateObject request from VBS. It appears that those requests simply disappear into a black hole. It also appears that integrating a GUI toolkit with its own event loop in Python may not be very practical with a COM server (see http://trac.wxwidgets.org/ticket/12105 for some other issues with wxPython and COM). Unfortunately, this means my best option is probably to move ahead without COM support. Thanks again for your help. --Kevin -------------- next part -------------- An HTML attachment was scrubbed... URL: From the_little_guy at gmx.com Sun Aug 21 04:55:39 2011 From: the_little_guy at gmx.com (The Little Guy) Date: Sat, 20 Aug 2011 19:55:39 -0700 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? Message-ID: Hi, I apologize for the lengthy post. I'm using Python 2.7, Win 7, Excel 2003. When trying to enter a time object and text data into a, simple, Excel 2003 file. I've tried different combinations for saving the file. I've used workbook.Save(), workbook.SaveAs(filename), etc. Sometimes I receive a replace file dialog box, but other times, I receive following message, when it tries to save: ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------------------- Traceback (most recent call last): File "C:\Users\tech\Documents\Python\row_end.py", line 63, in workbook.Save() File "C:\Python27\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00000 0000046x0x1x5\_Workbook.py", line 207, in Save return self._oleobj_.InvokeTypes(283, LCID, 1, (24, 0), (),) com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Office Excel', u"Your changes could not be saved to 'simple.xls' because of a sharing violation. Try saving to a different file.", u'C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284), None) What I'd like to do is: Open an excel file, stored either locally or on a net share, Look for the last row in a particular sheet, say Sheet1, Append a time object to last row + 1, first column, Append text data to last row + 1, second column, Ask to save the file (1 = save, 2 = discard changes) Save the Excel workbook, Close and Quit without confirmation dialogs. Basically, there is a sharing violation, sometimes excel.exe is in task manager and sometimes it is not, but the sharing violation message appears to cause the script to crash. I've tried saving the file to a different file name, which works, and then closing the current file, then removing it, but still get a sharing violation as it appears to still be in use by some unknown process, probabaly the OS, though can't track which process it is. Is there a simple way to save an opened Excel file without getting errors? As win32com documentation (on python side) is scarce, I'm using xlrd to get the last row on the excel sheet. I'm using this simple test code, which, due to, trial and error experimentation, has grown a bit unwieldy: ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------------------- #!/usr/bin/env python import shutil # shell utility module to work with os from xlrd import open_workbook # Third party library allows us to open Excel files, find last row. import pythoncom # Allows us to use MakeTime(date_object) import win32com.client # Allows to connect to Windows object using COM objects. import os, sys, time # Allows us to work with time and os functions. # Set the Excel file name, working directory and path old_file_name = 'simple.xls' working_dir = r"C:\Users\some_user\Documents\Python" + os.sep old_file_path = os.path.join(working_dir, old_file_name) #-----------------------------xlrd section----------------------------------------------- # Open the Excel file for reading book = open_workbook(old_file_path, on_demand=True) sheet = book.sheet_by_name('Current') lst_row = sheet.nrows print lst_row #-------------------------Today's date section------------------------------------- # Returns date object (yyyy-mm-dd) today = date.today() print today date_today = pythoncom.MakeTime(today) # Return date/time object (mm/dd/yy hh:mm:ss) print date_today #--------------------------------------------------------------------------- --------- # The win32com function to open Excel. xlApp = win32com.client.Dispatch("Excel.Application") xlApp.Visible = True # Open the file we want in Excel workbook = xlApp.Workbooks.Open(old_file_path) # Extract some of the file's components we may need. workbook = xlApp.ActiveWorkbook xlApp.Sheets('Current').Select() activesheet = xlApp.ActiveSheet xlSheet.Cells(lst_row + 1, 1).Value = "Time Object" # Text data for now xlSheet.Cells(lst_row + 1, 2).Value = date_today save_file = int(raw_input("Save the data Yes = 1, No = 2? ")) try: if save_file == 1: workbook.Saved = 0 workbook.Save() workbook.Close(SaveChanges=True) else: print 'File not saved!' workbook.Close() xlApp.Quit() del activesheet except KeyboardInterrupt: print 'Error: ' xlApp.Visible = 0 xlApp = None del xlApp del workbook pythoncom.CoUninitialize() ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------------------- Regards, Little Guy -------------- next part -------------- An HTML attachment was scrubbed... URL: From matteo.boscolo at boscolini.eu Sun Aug 21 08:43:22 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Sun, 21 Aug 2011 08:43:22 +0200 Subject: [python-win32] Questions about deploying COM server via py2exe In-Reply-To: References: <4E4E0A3F.5010400@boscolini.eu> <0A17F234BC7E4AACBBE780471E8ED193@KevinPC> <4E4F57BA.7020206@boscolini.eu> Message-ID: <4E50A90A.3040502@boscolini.eu> Hi Kevin, Il 20/08/2011 20:30, Kevin Walzer ha scritto: > nfortunately, this means my best option is probably to move ahead > without COM support. Try with the pyqt we use it with the main loop opened and it works very well here you get a basic example: from PyQt4.QtCore import * from PyQt4.QtGui import * app = QApplication(sys.argv) app.setQuitOnLastWindowClosed(False) Regards, Matteo From skippy.hammond at gmail.com Mon Aug 22 05:10:29 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 22 Aug 2011 13:10:29 +1000 Subject: [python-win32] Questions about deploying COM server via py2exe In-Reply-To: References: <4E4E0A3F.5010400@boscolini.eu> <0A17F234BC7E4AACBBE780471E8ED193@KevinPC> <4E4F57BA.7020206@boscolini.eu> Message-ID: <4E51C8A5.5060500@gmail.com> On 21/08/2011 4:30 AM, Kevin Walzer wrote: > Hi Matteo, > Thanks for the suggestions. I have integrated the win32trace module into > my frozen app. Here is my final code: ... > This appears to be related to the bug logged at > http://bugs.python.org/issue3905. My app makes use of subprocess to > obtain various bits of data that it then parses and displays in its UI. > For what it?s worth, injecting the trace module into my frozen app > causes no output to appear at all in the app itself, and returns the > error above; the trace module seems to trigger the suprocess bug. Yeah, but as mentioned in that bug, the issue is to do with your app being a "gui" app rather than a console one - you can probably reproduce the same problem wothout py2exe using pythonw.exe instead of python.exe. Fortunately, it sounds like you can just use subprocess.PIPE and still get at the output. > However, it seems to have no bearing at all on the failure of VBScript > to create a COM object from my application, and the debugging output > logged to my stdout/stderr file did not yield any insight on that. > I investigated whether running the mainloop() in the app might interfere > with the application receiving the COM request from the Windows Script > Host, but commenting out the mainloop only caused the app to crash > (since Tkinter apps require a mainloop to run). > The bottom line of all this investigation is that I am no closer to > understanding why my Tkinter app does not respond to the CreateObject > request from VBS. It appears that those requests simply disappear into a > black hole. It also appears that integrating a GUI toolkit with its own > event loop in Python may not be very practical with a COM server (see > http://trac.wxwidgets.org/ticket/12105 for some other issues with > wxPython and COM). Unfortunately, this means my best option is probably > to move ahead without COM support. Sadly the Tkinter main loop doesn't play well with many things. Mark From skippy.hammond at gmail.com Mon Aug 22 05:14:51 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 22 Aug 2011 13:14:51 +1000 Subject: [python-win32] CF_ENHMETAFILE SetClipboardData 'The handle is invalid' In-Reply-To: <32280484.post@talk.nabble.com> References: <32280484.post@talk.nabble.com> Message-ID: <4E51C9AB.3070705@gmail.com> On 18/08/2011 1:02 AM, RuiDC wrote: > > import win32clipboard > > filename = r"C:\tmp\test.emf" > with open(filename, "rb") as f: > data = f.read() > win32clipboard.OpenClipboard() > win32clipboard.EmptyClipboard() > win32clipboard.SetClipboardData(win32clipboard.CF_ENHMETAFILE, data) > win32clipboard.CloseClipboard() > > why do I get the below message? > > pywintypes.error: (6, 'SetClipboardData', 'The handle is invalid.') CF_ENHMETAFILE requires a handle to a metafile, not simply the data. You might like to google for some examples of using this format in any language. HTH, Mark From skippy.hammond at gmail.com Mon Aug 22 05:15:54 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 22 Aug 2011 13:15:54 +1000 Subject: [python-win32] SHOpenFolderAndSelectItems In-Reply-To: References: Message-ID: <4E51C9EA.5000106@gmail.com> On 20/08/2011 5:40 AM, Scott Nelson wrote: ... > Does pywin have support for SHOpenFolderAndSelectItems()? Unfortunately not - you can open a feature request at sourceforge and I'll add it for the next release. Cheers, Mark From davidf at sjsoft.com Mon Aug 22 10:39:10 2011 From: davidf at sjsoft.com (David Fraser) Date: Mon, 22 Aug 2011 03:39:10 -0500 (CDT) Subject: [python-win32] win32timezone.TimeZoneDefinition.current and GetDynamicTimeZoneInformation In-Reply-To: Message-ID: <08595aef-0afb-46ea-b70b-afbabd80aecc@jackdaw.local> Hi I'm trying to get hold of the registry key name of the current timezone on a multilingual Windows 2008 machine. GetDynamicTimeZoneInformation returns this information in TimeZoneKeyName, but -GetTimeZoneInformation doesn't. It seems that TimeZoneDefinition.current just calls GetTimeZoneInformation although it used to call the dynamic variant - see http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/rev/53671320a8e0 The comment on that commit doesn't seem to fully explain this - I'm wondering whether it would be helpful to add this to win32api, whether it would be possible to restore the functionality where possible, or whether I should just be doing the kernel call directly as was done before the patch? Any advice appreciated David -- David Fraser St James Software -------------- next part -------------- An HTML attachment was scrubbed... URL: From ruidc at yahoo.com Mon Aug 22 11:42:55 2011 From: ruidc at yahoo.com (RuiDC) Date: Mon, 22 Aug 2011 02:42:55 -0700 (PDT) Subject: [python-win32] CF_ENHMETAFILE SetClipboardData 'The handle is invalid' In-Reply-To: <4E51C9AB.3070705@gmail.com> References: <32280484.post@talk.nabble.com> <4E51C9AB.3070705@gmail.com> Message-ID: <32309764.post@talk.nabble.com> Thanks, but I still can't see how to achieve the same thing with Python, I've looked at: API way http://www.codeguru.com/forum/archive/index.php/t-341163.html GetEnhMetaFile API http://msdn.microsoft.com/en-us/library/dd144880%28v=VS.85%29.aspx dotNet way: http://support.microsoft.com/kb/323530 VBA Way http://www.lebans.com/imagecontroltoclipboard.htm and several variations, but they all seem to rely on GDI or GetEnhMetaFile or (from the VBA example) just plain don't seem to work (invalid handle back from the SetClipboardData call) Am I missing something that should be obvious here? -- View this message in context: http://old.nabble.com/CF_ENHMETAFILE-SetClipboardData-%27The-handle-is-invalid%27-tp32280484p32309764.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From sirgnip at gmail.com Mon Aug 22 16:10:58 2011 From: sirgnip at gmail.com (Scott Nelson) Date: Mon, 22 Aug 2011 09:10:58 -0500 Subject: [python-win32] SHOpenFolderAndSelectItems In-Reply-To: <4E51C9EA.5000106@gmail.com> References: <4E51C9EA.5000106@gmail.com> Message-ID: Done (ID #3396444) https://sourceforge.net/tracker/?func=detail&aid=3396444&group_id=78018&atid=551957 Many thanks for considering this! On Sun, Aug 21, 2011 at 10:15 PM, Mark Hammond wrote: > On 20/08/2011 5:40 AM, Scott Nelson wrote: > ... > > Does pywin have support for SHOpenFolderAndSelectItems()? >> > > Unfortunately not - you can open a feature request at sourceforge and I'll > add it for the next release. > > Cheers, > > Mark > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Aug 22 23:01:51 2011 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Aug 2011 14:01:51 -0700 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? In-Reply-To: References: Message-ID: <4E52C3BF.8050603@probo.com> The Little Guy wrote: > > Hi, > > > > I apologize for the lengthy post. > > > > I?m using Python 2.7, Win 7, Excel 2003. When trying to enter a time > object and text data into a, simple, Excel 2003 file. I?ve tried > different combinations for saving the file. I?ve used > workbook.Save(), workbook.SaveAs(filename), etc. Sometimes I receive > a replace file dialog box, but other times, I receive following > message, when it tries to save: > It is important to remember that none of these cause Excel to exit: xlApp.Visible = 0 xlApp = None del xlApp If you have Excel open with your file and set Visible to 0, it can be very difficult to remember that your file is still open. You should use xlApp.Quit() in every exit path. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From the_little_guy at gmx.com Tue Aug 23 15:32:15 2011 From: the_little_guy at gmx.com (Little Guy) Date: Tue, 23 Aug 2011 13:32:15 +0000 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? Message-ID: <20110823133215.227900@gmx.com> Mr. Roberts, I tried your suggestion about the varialble.quit() usage but still get the same results. What normally happens is that I open up the excel file, and make it visible. I then try to populate two cells, at the last row + 1 with text, then try to save, close and quit. What occurs is that, either, sharing violations occur, and the script crashes, or another instance of excel pops up, with a save dialog box, asking to save with a random filename generated by the OS, I presume. Yesterday, I noted that there were over 15 of these randome filenames saved in the directory of the exce file, but all lacking an .xls extension. This occured eventhough, I chose not to save the excel file when the save dialog window came up. No matter what I do, the workbook does not close and quit, silently saving all changes, it either crashes or aks to save the file, providing a different filename. Thanks for the reply, LG ----- Original Message ----- From: python-win32-request at python.org Sent: 08/23/11 03:00 AM To: python-win32 at python.org Subject: python-win32 Digest, Vol 101, Issue 22 Send python-win32 mailing list submissions to python-win32 at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request at python.org You can reach the person managing the list at python-win32-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." Today's Topics: 1. Re: SHOpenFolderAndSelectItems (Scott Nelson) 2. Re: Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) ---------------------------------------------------------------------- Message: 1 Date: Mon, 22 Aug 2011 09:10:58 -0500 From: Scott Nelson To: mhammond at skippinet.com.au Cc: python-win32 at python.org Subject: Re: [python-win32] SHOpenFolderAndSelectItems Message-ID: Content-Type: text/plain; charset="iso-8859-1" Done (ID #3396444) https://sourceforge.net/tracker/?func=detail&aid=3396444&group_id=78018&atid=551957 Many thanks for considering this! On Sun, Aug 21, 2011 at 10:15 PM, Mark Hammond wrote: > On 20/08/2011 5:40 AM, Scott Nelson wrote: > ... > > Does pywin have support for SHOpenFolderAndSelectItems()? >> > > Unfortunately not - you can open a feature request at sourceforge and I'll > add it for the next release. > > Cheers, > > Mark > -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 2 Date: Mon, 22 Aug 2011 14:01:51 -0700 From: Tim Roberts To: Python-Win32 List Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? Message-ID: <4E52C3BF.8050603 at probo.com> Content-Type: text/plain; charset="windows-1252" The Little Guy wrote: > > Hi, > > > > I apologize for the lengthy post. > > > > I?m using Python 2.7, Win 7, Excel 2003. When trying to enter a time > object and text data into a, simple, Excel 2003 file. I?ve tried > different combinations for saving the file. I?ve used > workbook.Save(), workbook.SaveAs(filename), etc. Sometimes I receive > a replace file dialog box, but other times, I receive following > message, when it tries to save: > It is important to remember that none of these cause Excel to exit: xlApp.Visible = 0 xlApp = None del xlApp If you have Excel open with your file and set Visible to 0, it can be very difficult to remember that your file is still open. You should use xlApp.Quit() in every exit path. -- 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 End of python-win32 Digest, Vol 101, Issue 22 ********************************************* Regards, Little Guy -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Tue Aug 23 21:58:35 2011 From: drobinow at gmail.com (David Robinow) Date: Tue, 23 Aug 2011 15:58:35 -0400 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? In-Reply-To: References: Message-ID: On Sat, Aug 20, 2011 at 10:55 PM, The Little Guy wrote: > Hi, > I apologize for the lengthy post. The code you posted does not run at all. I had to rename a few things to get it to do anything at all. It appears that xlrd is holding a reference to the excel file. I was able to get it to work by adding: book.release_resources() after the xlrd code. From the_little_guy at gmx.com Wed Aug 24 03:07:44 2011 From: the_little_guy at gmx.com (The Little Guy) Date: Tue, 23 Aug 2011 18:07:44 -0700 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) In-Reply-To: References: Message-ID: <208B140CC38E4C25B6D97F663A421B2F@BLASTER7> Mr. Roberts, I've actually, gone through the, routine of placing quit in multiple places but still I get errors. Either an unknown process error is generated or another instance of Excel pops up, with a SaveAs dialog, box, with a random filename as default. Something has grabbed the excel file. -----Original Message----- From: python-win32-bounces+the_little_guy=gmx.com at python.org [mailto:python-win32-bounces+the_little_guy=gmx.com at python.org] On Behalf Of python-win32-request at python.org Sent: Tuesday, August 23, 2011 3:00 AM To: python-win32 at python.org Subject: python-win32 Digest, Vol 101, Issue 22 Send python-win32 mailing list submissions to python-win32 at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request at python.org You can reach the person managing the list at python-win32-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." Today's Topics: 1. Re: SHOpenFolderAndSelectItems (Scott Nelson) 2. Re: Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) ---------------------------------------------------------------------- Message: 1 Date: Mon, 22 Aug 2011 09:10:58 -0500 From: Scott Nelson To: mhammond at skippinet.com.au Cc: python-win32 at python.org Subject: Re: [python-win32] SHOpenFolderAndSelectItems Message-ID: Content-Type: text/plain; charset="iso-8859-1" Done (ID #3396444) https://sourceforge.net/tracker/?func=detail&aid=3396444&group_id=78018&atid =551957 Many thanks for considering this! On Sun, Aug 21, 2011 at 10:15 PM, Mark Hammond wrote: > On 20/08/2011 5:40 AM, Scott Nelson wrote: > ... > > Does pywin have support for SHOpenFolderAndSelectItems()? >> > > Unfortunately not - you can open a feature request at sourceforge and I'll > add it for the next release. > > Cheers, > > Mark > -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 2 Date: Mon, 22 Aug 2011 14:01:51 -0700 From: Tim Roberts To: Python-Win32 List Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? Message-ID: <4E52C3BF.8050603 at probo.com> Content-Type: text/plain; charset="windows-1252" The Little Guy wrote: > > Hi, > > > > I apologize for the lengthy post. > > > > I?m using Python 2.7, Win 7, Excel 2003. When trying to enter a time > object and text data into a, simple, Excel 2003 file. I?ve tried > different combinations for saving the file. I?ve used > workbook.Save(), workbook.SaveAs(filename), etc. Sometimes I receive > a replace file dialog box, but other times, I receive following > message, when it tries to save: > It is important to remember that none of these cause Excel to exit: xlApp.Visible = 0 xlApp = None del xlApp If you have Excel open with your file and set Visible to 0, it can be very difficult to remember that your file is still open. You should use xlApp.Quit() in every exit path. -- 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 End of python-win32 Digest, Vol 101, Issue 22 ********************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Aug 24 03:18:33 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 23 Aug 2011 18:18:33 -0700 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) In-Reply-To: <208B140CC38E4C25B6D97F663A421B2F@BLASTER7> References: <208B140CC38E4C25B6D97F663A421B2F@BLASTER7> Message-ID: <4E545169.8070209@probo.com> The Little Guy wrote: > > Mr. Roberts, > > > > I?ve actually, gone through the, routine of placing quit in multiple > places but still I get errors. Either an unknown process error is > generated or another instance of Excel pops up, with a SaveAs dialog, > box, with a random filename as default. Something has grabbed the > excel file. > Can you post the whole script as you have it now? How many times to you have to run it before it fails? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From the_little_guy at gmx.com Wed Aug 24 03:33:34 2011 From: the_little_guy at gmx.com (The Little Guy) Date: Tue, 23 Aug 2011 18:33:34 -0700 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? In-Reply-To: References: Message-ID: <5DAE6EBACB59467E90DD27657EE2BC3D@BLASTER7> Mr. Robinow, The code is only a small test code, not really meant to do anything. It's just meant to be used as a simple test to see if I can save data onto an excel sheet. This is the final part of larger code project. All it does is open an excel file, append data to it, and try to save the modified file. Most likely, I may have accidentally, left a line or two out of the code which is probabaly why it did not work for you. I apologize for that error on my part. Since win32com documentation is not localized, not easily accessible, at least by me, coding is a trial and error thing for me. FYI: I tried your suggestion and it worked. Now if I can only find the win32com way of finding the last row and column in a sheet, I'd be a happy camper :-) Thanks for the assist Little Guy -----Original Message----- From: David Robinow [mailto:drobinow at gmail.com] Sent: Tuesday, August 23, 2011 12:59 PM To: The Little Guy Cc: python-win32 at python.org Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? On Sat, Aug 20, 2011 at 10:55 PM, The Little Guy wrote: > Hi, > I apologize for the lengthy post. The code you posted does not run at all. I had to rename a few things to get it to do anything at all. It appears that xlrd is holding a reference to the excel file. I was able to get it to work by adding: book.release_resources() after the xlrd code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Andrew.MacIntyre at acma.gov.au Wed Aug 24 03:24:05 2011 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Wed, 24 Aug 2011 01:24:05 +0000 Subject: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) [SEC=PERSONAL] In-Reply-To: <208B140CC38E4C25B6D97F663A421B2F@BLASTER7> References: <208B140CC38E4C25B6D97F663A421B2F@BLASTER7> Message-ID: The code you posted doesn't look right, but I suspect your code is not properly cleaning up all references to Excel objects before terminating, and you will find you still have an Excel process in the background which is hanging on to the file (hence the sharing violations). I have encountered this with scripts that encounter unhandled exceptions. You must ensure that you release all Excel object references before calling the Quit method on the Excel object. Using a function or class to encapsulate the Excel operations can make this easier. To make it reliable, comprehensive exception handling will also be required. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre Operations Branch tel: +61 2 6219 5356 Communications Infrastructure Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au http://www.acma.gov.au/ From: python-win32-bounces+andrew.macintyre=acma.gov.au at python.org [mailto:python-win32-bounces+andrew.macintyre=acma.gov.au at python.org] On Behalf Of The Little Guy Sent: Wednesday, 24 August 2011 11:08 AM To: python-win32 at python.org Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) Mr. Roberts, I've actually, gone through the, routine of placing quit in multiple places but still I get errors. Either an unknown process error is generated or another instance of Excel pops up, with a SaveAs dialog, box, with a random filename as default. Something has grabbed the excel file. NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From the_little_guy at gmx.com Wed Aug 24 03:56:45 2011 From: the_little_guy at gmx.com (The Little Guy) Date: Tue, 23 Aug 2011 18:56:45 -0700 Subject: [python-win32] python-win32 Digest, Vol 101, Issue 24 In-Reply-To: References: Message-ID: <250670E1A15346ED98B5A6157C1088A5@BLASTER7> Mr. Roberts, It's, working, now, with the suggestion from Mr. Robinow. It hasn't failed at this point. But to answer your question, it was failing, every single time depending on how I modified the code. I was about to give up on it. Now EXCEL.EXE goes away from Windows Task Manager, which happened only 50% of the time. It appears, that, indeed, xlrd was hogging up the file. That was, really, unexpected as I had read information on xlrd, suggesting that would not happen. Maybe, I did not do, enough, research on it, before using it. Here's, the fully, working script. Please keep in mind that, it's got bugs, no error checking as of yet, as I was concentrating on getting the file to save without complaining. Thanks for all the help. It is appretiated :-) Little Guy The code: (if you test it, make sure to change the working_dir path) --------------------------------------------------------------------------- #!/usr/bin/env python # shell utility module to work with os import shutil # Third party library allows us to open Excel files, find last row. from xlrd import open_workbook # Allows us to use MakeTime(date_object) import pythoncom # Allows to connect to Windows object using COM objects. import win32com.client # Allows us to work with date, time objects. from datetime import date, time, datetime # Allows us to work with time and os functions. import os, sys, time # Set the Excel file name, working directory and path old_file_name = 'simple.xls' working_dir = r"C:\Users\TestUser\Documents\Python" + os.sep old_file_path = os.path.join(working_dir, old_file_name) #-----------------------------xlrd section-------------------------------------- # Open the Excel file for reading book = open_workbook(old_file_path, on_demand=True) sheet = book.sheet_by_name('Current') lst_row = sheet.nrows print lst_row book.release_resources() #-------------------------Today's date section---------------------------------- # Returns date object (yyyy-mm-dd) today = date.today() print today # Return date/time object (mm/dd/yy hh:mm:ss) date_today = pythoncom.MakeTime(today) print date_today #--------------------------------------------------------------------------- ---- # The win32com function to open Excel. xlApp = win32com.client.Dispatch("Excel.Application") xlApp.Visible = True # Open the file we want in Excel workbook = xlApp.Workbooks.Open(old_file_path) # Extract some of the file's components we may need. workbook = xlApp.ActiveWorkbook xlApp.Sheets('Current').Select() activesheet = xlApp.ActiveSheet activesheet.Cells(lst_row + 1, 1).Value = "Time Object" # Text data for now activesheet.Cells(lst_row + 1, 2).Value = date_today save_file = int(raw_input("Save the data Yes = 1, No = 2? ")) try: if save_file == 1: ## workbook.Saved = 0 workbook.Save() ## workbook.Close(SaveChanges=True) xlApp.Quit() else: print 'File not saved!' workbook.Close() xlApp.Quit() except KeyboardInterrupt: print 'Error: ' pythoncom.CoUninitialize() ---------------------------------------------------------------------------- --- -----Original Message----- From: python-win32-bounces+the_little_guy=gmx.com at python.org [mailto:python-win32-bounces+the_little_guy=gmx.com at python.org] On Behalf Of python-win32-request at python.org Sent: Tuesday, August 23, 2011 6:34 PM To: python-win32 at python.org Subject: python-win32 Digest, Vol 101, Issue 24 Send python-win32 mailing list submissions to python-win32 at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request at python.org You can reach the person managing the list at python-win32-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of python-win32 digest..." Today's Topics: 1. Re: Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) (Tim Roberts) 2. Re: Opening, Modifying, and Saving an Excel File from Python? (The Little Guy) 3. Re: Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) [SEC=PERSONAL] (Andrew MacIntyre) ---------------------------------------------------------------------- Message: 1 Date: Tue, 23 Aug 2011 18:18:33 -0700 From: Tim Roberts To: Python-Win32 List Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) Message-ID: <4E545169.8070209 at probo.com> Content-Type: text/plain; charset="windows-1252" The Little Guy wrote: > > Mr. Roberts, > > > > I?ve actually, gone through the, routine of placing quit in multiple > places but still I get errors. Either an unknown process error is > generated or another instance of Excel pops up, with a SaveAs dialog, > box, with a random filename as default. Something has grabbed the > excel file. > Can you post the whole script as you have it now? How many times to you have to run it before it fails? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. ------------------------------ Message: 2 Date: Tue, 23 Aug 2011 18:33:34 -0700 From: "The Little Guy" To: "'David Robinow'" Cc: python-win32 at python.org Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? Message-ID: <5DAE6EBACB59467E90DD27657EE2BC3D at BLASTER7> Content-Type: text/plain; charset="us-ascii" Mr. Robinow, The code is only a small test code, not really meant to do anything. It's just meant to be used as a simple test to see if I can save data onto an excel sheet. This is the final part of larger code project. All it does is open an excel file, append data to it, and try to save the modified file. Most likely, I may have accidentally, left a line or two out of the code which is probabaly why it did not work for you. I apologize for that error on my part. Since win32com documentation is not localized, not easily accessible, at least by me, coding is a trial and error thing for me. FYI: I tried your suggestion and it worked. Now if I can only find the win32com way of finding the last row and column in a sheet, I'd be a happy camper :-) Thanks for the assist Little Guy -----Original Message----- From: David Robinow [mailto:drobinow at gmail.com] Sent: Tuesday, August 23, 2011 12:59 PM To: The Little Guy Cc: python-win32 at python.org Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? On Sat, Aug 20, 2011 at 10:55 PM, The Little Guy wrote: > Hi, > I apologize for the lengthy post. The code you posted does not run at all. I had to rename a few things to get it to do anything at all. It appears that xlrd is holding a reference to the excel file. I was able to get it to work by adding: book.release_resources() after the xlrd code. -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Message: 3 Date: Wed, 24 Aug 2011 01:24:05 +0000 From: "Andrew MacIntyre" To: "python-win32 at python.org" Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) [SEC=PERSONAL] Message-ID: Content-Type: text/plain; charset="us-ascii" The code you posted doesn't look right, but I suspect your code is not properly cleaning up all references to Excel objects before terminating, and you will find you still have an Excel process in the background which is hanging on to the file (hence the sharing violations). I have encountered this with scripts that encounter unhandled exceptions. You must ensure that you release all Excel object references before calling the Quit method on the Excel object. Using a function or class to encapsulate the Excel operations can make this easier. To make it reliable, comprehensive exception handling will also be required. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre Operations Branch tel: +61 2 6219 5356 Communications Infrastructure Division fax: +61 2 6253 3277 Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au http://www.acma.gov.au/ From: python-win32-bounces+andrew.macintyre=acma.gov.au at python.org [mailto:python-win32-bounces+andrew.macintyre=acma.gov.au at python.org] On Behalf Of The Little Guy Sent: Wednesday, 24 August 2011 11:08 AM To: python-win32 at python.org Subject: Re: [python-win32] Opening, Modifying, and Saving an Excel File from Python? (Tim Roberts) Mr. Roberts, I've actually, gone through the, routine of placing quit in multiple places but still I get errors. Either an unknown process error is generated or another instance of Excel pops up, with a SaveAs dialog, box, with a random filename as default. Something has grabbed the excel file. NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 End of python-win32 Digest, Vol 101, Issue 24 ********************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: From aschneiderman at gmail.com Thu Aug 25 00:25:46 2011 From: aschneiderman at gmail.com (Anders Schneiderman) Date: Wed, 24 Aug 2011 18:25:46 -0400 Subject: [python-win32] Accessing non-default folders in Outlook 2010? Message-ID: I'm trying to read messages that are in folders in Outlook 2010, and I'm running into trouble. Between looking at other folk's code and trying to make sense out of the Microsoft Object Model documentation, I've been able to figure out how to read items in the inbox and other things in default folders, such as tasks: by using GetDefaultFolder. ---------------------------------------------------- import win32com.client outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") # Count the number of messages in the inbox inbox = outlook.GetDefaultFolder(win32com.client.constants.olFolderInbox) messages = inbox.Items print "number of messages in inbox:", messages.Count # Count the number of tasks in the task list task_list = outlook.GetDefaultFolder(win32com.client.constants.olFolderTasks) tasks = task_list.Items print "number of tasks in the task list:", tasks.Count ----------------------------------------------------- But I can?t figure out how to read folders that aren?t default folders ? i.e., inbox, deleted items, sent items ? but instead are folders that I?ve created. If the folders were located under the Inbox, it?d be pretty straightforward, but they aren't. And I?ve yet to find any examples or anything in the Object Model that?ll help me (which could be because I still don't quite understand it), and poking around using dir() hasn?t helped very much. Any pointers on how to figure this out? I'm running Outlook 2010 under Vista and using python 1.5 (for compatibility with Vocola) Thanks, Anders Schneiderman -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Aug 25 00:37:43 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Aug 2011 15:37:43 -0700 Subject: [python-win32] Accessing non-default folders in Outlook 2010? In-Reply-To: References: Message-ID: <4E557D37.5020400@probo.com> Anders Schneiderman wrote: > > I'm trying to read messages that are in folders in Outlook 2010, and > I'm running into trouble. Between looking at other folk's code and > trying to make sense out of the Microsoft Object Model documentation, > I've been able to figure out how to read items in the inbox and other > things in default folders, such as tasks: by using GetDefaultFolder. > I think you want outlook.GetRootFolder(), then enumerate the Folders collection within that. http://msdn.microsoft.com/en-us/library/ff860733.aspx -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From aschneiderman at gmail.com Thu Aug 25 11:47:00 2011 From: aschneiderman at gmail.com (Anders Schneiderman) Date: Thu, 25 Aug 2011 05:47:00 -0400 Subject: [python-win32] Accessing non-default folders in Outlook 2010? In-Reply-To: <4E557D1B.6000806@probo.com> References: <4E557D1B.6000806@probo.com> Message-ID: When I tried it: folders = outlook.GetRootFolder() I got the following error message: AttributeError: object has no attribute 'GetRootFolder FYI, when I do: print dir(outlook) that method doesn't show up: ['AddStore', 'AddStoreEx', 'CLSID', 'CompareEntryIDs', 'CreateContactCard', 'CreateRecipient', 'CreateSharingItem', 'Dial', 'GetAddressEntryFromID', 'GetDefaultFolder', 'GetFolderFromID', 'GetGlobalAddressList', 'GetItemFromID', 'GetRecipientFromID', 'GetSelectNamesDialog', 'GetSharedDefaultFolder', 'GetStoreFromID', 'Logoff', 'Logon', 'OpenSharedFolder', 'OpenSharedItem', 'PickFolder', 'RefreshRemoteHeaders', 'RemoveStore', 'SendAndReceive', '_ApplyTypes_', '__cmp__', '__doc__', '__getattr__', '__init__', '__module__', '__repr__', '__setattr__', '_get_good_object_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_', '_prop_map_put_', 'coclass_clsid'] dir doesn't always pick everything up, but just in case it's useful... Full code below: ---------------------------------- import win32com.client # Connect to Outlook, which has to be running try: print "trying to open up Outlook..." outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") except: print "Could not open Outlook" print "successfully connected to Outlook\n" # Count the number of messages in the inbox inbox = outlook.GetDefaultFolder(win32com.client.constants.olFolderInbox) messages = inbox.Items print "number of messages in inbox:", messages.Count # Count the number of tasks in the task list task_list = outlook.GetDefaultFolder(win32com.client.constants.olFolderTasks) tasks = task_list.Items print "number of tasks in the task list:", tasks.Count folders = outlook.GetRootFolder() ---------------------------------- Thanks, Anders On Wed, Aug 24, 2011 at 6:37 PM, Tim Roberts wrote: > Anders Schneiderman wrote: > > > > I'm trying to read messages that are in folders in Outlook 2010, and > > I'm running into trouble. Between looking at other folk's code and > > trying to make sense out of the Microsoft Object Model documentation, > > I've been able to figure out how to read items in the inbox and other > > things in default folders, such as tasks: by using GetDefaultFolder. > > > > I think you want outlook.GetRootFolder(), then enumerate the Folders > collection within that. > > http://msdn.microsoft.com/en-us/library/ff860733.aspx > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From blindza at gmail.com Thu Aug 25 15:02:08 2011 From: blindza at gmail.com (Jacob Kruger) Date: Thu, 25 Aug 2011 15:02:08 +0200 Subject: [python-win32] Recurring DLL error with py2exe Message-ID: Thought this problem was specific to pyaudiere, but now got same thing when tried to test using py2exe on a very small, test wxPython app to make sure it was worth focusing on this in terms of GUI's etc., but it again tells me the same thing. Typed in following command line code using sort of standard setup.py file that works on other things like my mapData IF engine, but did change the name of the .py file it should process: python setup.py py2exe The last 2 lines rendered in that window are then the following: *** finding dlls needed *** error: MSVCP90.dll: No such file or directory That specific DLL gets copied quite easily into the relevant subfolder of the dist folder when I run a similar command for my much larger, but, I suppose, simpler, mapData app, since that one doesn't try to import libraries/modules like piaudiere or wxPython as such. Any thoughts on what could really be happening here, or should I try sort out reinstalling windows7 or something...? TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From werner.bruhin at free.fr Thu Aug 25 16:06:05 2011 From: werner.bruhin at free.fr (Werner F. Bruhin) Date: Thu, 25 Aug 2011 16:06:05 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: References: Message-ID: Hi Jacob, On 08/25/2011 03:02 PM, Jacob Kruger wrote: > Thought this problem was specific to pyaudiere, but now got same thing when tried to test using py2exe on a very small, test wxPython app to make sure it was worth focusing on this in terms of GUI's etc., but it again tells me the same thing. > > Typed in following command line code using sort of standard setup.py file that works on other things like my mapData IF engine, but did change the name of the .py file it should process: > python setup.py py2exe > > The last 2 lines rendered in that window are then the following: > *** finding dlls needed *** > error: MSVCP90.dll: No such file or directory > > That specific DLL gets copied quite easily into the relevant subfolder of the dist folder when I run a similar command for my much larger, but, I suppose, simpler, mapData app, since that one doesn't try to import libraries/modules like piaudiere or wxPython as such. > > Any thoughts on what could really be happening here, or should I try sort out reinstalling windows7 or something...? py2exe is getting confused on this DLL for some reason, you just need to exclude it. dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] Additional information for wxPython and py2exe can be found on the wiki here: http://wiki.wxpython.org/py2exe Werner From blindza at gmail.com Thu Aug 25 16:30:56 2011 From: blindza at gmail.com (Jacob Kruger) Date: Thu, 25 Aug 2011 16:30:56 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: Message-ID: Ok, where should I include that exclude line? I tried just copying it into the setup.py file a bit higher up, but not sure if needs to be specifically included in some part of it, and I found out if I also tried to tell it not to copy the MSVCRT subfolder it still generates that error so it must have something to do with the actual compilation processing of the external module or something, but, maybe if I just need to tell it to exclude those files from a specific spot in the setup.py file that could sort it out? Anyway, here's current source of my setup.py file: #---start of source--- from glob import glob from distutils.core import setup import py2exe dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] data_files = [ ("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')) ] #data_files= [] options = { "bundle_files": 1, "ascii": 1, # to make a smaller executable, don't include the encodings "compressed": 1, # compress the library archive } setup( # The first three parameters are not required, if at least a # 'version' is given, then a versioninfo resource is built from # them and added to the executables. version = "1.0.0", description = "testingWxPython", name = "aboutBox", options = {'py2exe': options}, # targets to build console = ["AboutBox.py"], data_files=data_files ) #---end of source--- Could it also maybe be something to do with this line?: console = ["AboutBox.py"], Since while setup.py is running in console mode, don't know if the resulting wxPython based .exe runs in a console mode window as such..? Thanks Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message --------------- Subject: Re: [python-win32] Recurring DLL error with py2exe From: "Werner F. Bruhin" Date: Thu, 25 Aug 2011 16:06:05 +0200 To: python-win32 at python.org >Hi Jacob, > >On 08/25/2011 03:02 PM, Jacob Kruger wrote: >> Thought this problem was specific to pyaudiere, but now got same thing when tried to test using py2exe on a very small, test wxPython app to make sure it was worth focusing on this in terms of GUI's etc., but it again tells me the same thing. >> >> Typed in following command line code using sort of standard setup.py file that works on other things like my mapData IF engine, but did change the name of the .py file it should process: >> python setup.py py2exe >> >> The last 2 lines rendered in that window are then the following: >> *** finding dlls needed *** >> error: MSVCP90.dll: No such file or directory >> >> That specific DLL gets copied quite easily into the relevant subfolder of the dist folder when I run a similar command for my much larger, but, I suppose, simpler, mapData app, since that one doesn't try to import libraries/modules like piaudiere or wxPython as such. >> >> Any thoughts on what could really be happening here, or should I try sort out reinstalling windows7 or something...? >py2exe is getting confused on this DLL for some reason, you just need to >exclude it. > >dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', >'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] > >Additional information for wxPython and py2exe can be found on the wiki >here: > >http://wiki.wxpython.org/py2exe > >Werner > >_______________________________________________ >python-win32 mailing list >python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From tom at pentest.7safe.com Thu Aug 25 18:50:48 2011 From: tom at pentest.7safe.com (Tom) Date: Thu, 25 Aug 2011 17:50:48 +0100 Subject: [python-win32] Issue with inserting Microsoft Excel charts into Word Message-ID: Hello all, I am writing a reporting application that uses word's COM interface. I recently found myself needing to insert a chart into the document, and the "AddChart" method seemed ideal ( http://msdn.microsoft.com/en-us/library/bb226069(v=office.12).aspx). The code is this: image_chart = word.ActiveWindow.Selection.InlineShapes.AddChart(Type=constants.xlBarClustered) chart = image_chart.Chart chart.ChartData.Activate() ... fill chart with data ... This runs fine on my laptop machine (Windows 7) and a little excel window pops up with some basic starting data that my application modifies. I deployed it to our Windows 2003 server and I was dismayed to find that it failed. The issue was that image_chart had no Chart attribute, no exception is being raised when AddChart is called and an object is returned as normal, just without a Chart (and thus no ability to edit the data?). I did a little digging around and it seems that excel is spawned when I call AddChart, but it quits a second or two afterwards for no apparent reason, according to the event viewer "Excel terminated normally after a runtime of 1 seconds". The code is being called from a Celery task queue (so it is called from within a thread), and this has not been an issue before - the code is incredibly COM heavy. However when I spin up IDLE and use AddChart on a blank document the Excel window appears as normal and does not close. Has anyone encountered this before, or can think of a reason why this might be happening? ~Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Aug 25 18:54:12 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Aug 2011 09:54:12 -0700 Subject: [python-win32] Accessing non-default folders in Outlook 2010? In-Reply-To: References: <4E557D1B.6000806@probo.com> Message-ID: <4E567E34.40904@probo.com> Anders Schneiderman wrote: > > When I tried it: > folders = outlook.GetRootFolder() > > I got the following error message: > AttributeError: object has no attribute 'GetRootFolder > Hmmm. Are you able to refer to outlook.Folders(0)? http://support.microsoft.com/kb/208520/EN-US -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Aug 25 18:57:11 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Aug 2011 09:57:11 -0700 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: References: Message-ID: <4E567EE7.1000707@probo.com> Jacob Kruger wrote: > Typed in following command line code using sort of standard setup.py file that works on other things like my mapData IF engine, but did change the name of the .py file it should process: > python setup.py py2exe > > The last 2 lines rendered in that window are then the following: > *** finding dlls needed *** > error: MSVCP90.dll: No such file or directory > > That specific DLL gets copied quite easily into the relevant subfolder of the dist folder when I run a similar command for my much larger, but, I suppose, simpler, mapData app, since that one doesn't try to import libraries/modules like piaudiere or wxPython as such. MSVCP90.DLL is one of the DLLs caught up in the Microsoft "side-by-side" stupidity. It cannot just be copied into a destination folder, it has to be properly installed with a manifest. Do you have some custom extensions? I didn't think there were any versions of Python that were built with Visual Studio 2008. VS2010 wisely eliminates the side-by-side stuff for the CRT DLLs, so the problem goes away. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From werner.bruhin at free.fr Thu Aug 25 17:57:05 2011 From: werner.bruhin at free.fr (Werner F. Bruhin) Date: Thu, 25 Aug 2011 17:57:05 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: References: Message-ID: <4E5670D1.3010809@free.fr> On 08/25/2011 04:30 PM, Jacob Kruger wrote: > Ok, where should I include that exclude line? > > I tried just copying it into the setup.py file a bit higher up, but not sure if needs to be specifically included in some part of it, and I found out if I also tried to tell it not to copy the MSVCRT subfolder it still generates that error so it must have something to do with the actual compilation processing of the external module or something, but, maybe if I just need to tell it to exclude those files from a specific spot in the setup.py file that could sort it out? dll_exludes is a py2exe option, should we in your options dict - see below. > Anyway, here's current source of my setup.py file: > #---start of source--- > from glob import glob > from distutils.core import setup > import py2exe > dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] > data_files = [ > ("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')) > ] > #data_files= [] > options = { > "bundle_files": 1, Option "1" is more trouble then it is worse - would recommend 2 and use a installer such as InnoSetup to deliver a single file. Some of this is shown/explained on the wxPython wiki. > "ascii": 1, # to make a smaller executable, don't include the encodings > "compressed": 1, # compress the library archive "dll_excludes": dll_excludes, > } > > setup( > # The first three parameters are not required, if at least a > # 'version' is given, then a versioninfo resource is built from > # them and added to the executables. > version = "1.0.0", > description = "testingWxPython", > name = "aboutBox", > options = {'py2exe': options}, > > # targets to build > console = ["AboutBox.py"], > data_files=data_files > ) > #---end of source--- > > Could it also maybe be something to do with this line?: > console = ["AboutBox.py"], > > Since while setup.py is running in console mode, don't know if the resulting wxPython based .exe runs in a console mode window as such..? No problem, it will show a console window and a second window is opened with the wxPython GUI. This is sometimes handy to track down some tracebacks which don't show if you use "window". Werner From jacobk at mailzone.co.za Thu Aug 25 19:05:38 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Thu, 25 Aug 2011 19:05:38 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: <4E567EE7.1000707@probo.com> References: <4E567EE7.1000707@probo.com> Message-ID: <918563377C2B460E8E7AFB65D56905F9@jakes> Custom extensions? Not in VS.Net itsself, and aside from other general stuff on machine, it still works for the other python code, and only seems to generate this error/issue when trying to generate .exe files for these two pieces that make use of either piaudiere or now wxPython as such. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message ----- From: "Tim Roberts" To: "Python-Win32 List" Sent: Thursday, August 25, 2011 6:57 PM Subject: Re: [python-win32] Recurring DLL error with py2exe > Jacob Kruger wrote: >> Typed in following command line code using sort of standard setup.py file >> that works on other things like my mapData IF engine, but did change the >> name of the .py file it should process: >> python setup.py py2exe >> >> The last 2 lines rendered in that window are then the following: >> *** finding dlls needed *** >> error: MSVCP90.dll: No such file or directory >> >> That specific DLL gets copied quite easily into the relevant subfolder of >> the dist folder when I run a similar command for my much larger, but, I >> suppose, simpler, mapData app, since that one doesn't try to import >> libraries/modules like piaudiere or wxPython as such. > > MSVCP90.DLL is one of the DLLs caught up in the Microsoft "side-by-side" > stupidity. It cannot just be copied into a destination folder, it has > to be properly installed with a manifest. > > Do you have some custom extensions? I didn't think there were any > versions of Python that were built with Visual Studio 2008. VS2010 > wisely eliminates the side-by-side stuff for the CRT DLLs, so the > problem goes away. > > -- > 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 mark.mordeca at prosensus.ca Thu Aug 25 19:20:39 2011 From: mark.mordeca at prosensus.ca (Mark Mordeca) Date: Thu, 25 Aug 2011 13:20:39 -0400 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: <4E567EE7.1000707@probo.com> References: <4E567EE7.1000707@probo.com> Message-ID: Hi, Python is built using 2008. You can find this in the readme.txt under the PCbuild folder (from the 2.7.2 source at least): "This directory is used to build Python for Win32 and x64 platforms, e.g. Windows 2000, XP, Vista and Windows Server 2008. In order to build 32-bit debug and release executables, Microsoft Visual C++ 2008 Express Edition is required at the very least. In order to build 64-bit debug and release executables, Visual Studio 2008 Standard Edition is required at the very least. In order to build all of the above, as well as generate release builds that make use of Profile Guided Optimisation (PG0), Visual Studio 2008 Professional Edition is required at the very least. The official Python releases are built with this version of Visual Studio." Thanks. Mark -----Original Message----- From: python-win32-bounces+mark.mordeca=prosensus.ca at python.org [mailto:python-win32-bounces+mark.mordeca=prosensus.ca at python.org] On Behalf Of Tim Roberts Sent: Thursday, August 25, 2011 12:57 PM To: Python-Win32 List Subject: Re: [python-win32] Recurring DLL error with py2exe Jacob Kruger wrote: > Typed in following command line code using sort of standard setup.py file that works on other things like my mapData IF engine, but did change the name of the .py file it should process: > python setup.py py2exe > > The last 2 lines rendered in that window are then the following: > *** finding dlls needed *** > error: MSVCP90.dll: No such file or directory > > That specific DLL gets copied quite easily into the relevant subfolder of the dist folder when I run a similar command for my much larger, but, I suppose, simpler, mapData app, since that one doesn't try to import libraries/modules like piaudiere or wxPython as such. MSVCP90.DLL is one of the DLLs caught up in the Microsoft "side-by-side" stupidity. It cannot just be copied into a destination folder, it has to be properly installed with a manifest. Do you have some custom extensions? I didn't think there were any versions of Python that were built with Visual Studio 2008. VS2010 wisely eliminates the side-by-side stuff for the CRT DLLs, so the problem goes away. -- 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 timr at probo.com Thu Aug 25 19:29:01 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Aug 2011 10:29:01 -0700 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: References: <4E567EE7.1000707@probo.com> Message-ID: <4E56865D.3000900@probo.com> Mark Mordeca wrote: > Hi, > > Python is built using 2008. You can find this in the readme.txt under the > PCbuild folder (from the 2.7.2 source at least): Memory fault on my part. I was thinking they had bypassed 2008 and gone from 2005 straight to 2010, but I see both 2.6 and 2.7 use VS2008. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From werner.bruhin at free.fr Thu Aug 25 19:52:52 2011 From: werner.bruhin at free.fr (Werner F. Bruhin) Date: Thu, 25 Aug 2011 19:52:52 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: <4E56865D.3000900@probo.com> References: <4E567EE7.1000707@probo.com> <4E56865D.3000900@probo.com> Message-ID: <4E568BF4.8070009@free.fr> Tim and Mark, On 08/25/2011 07:29 PM, Tim Roberts wrote: > Mark Mordeca wrote: >> Hi, >> >> Python is built using 2008. You can find this in the readme.txt under the >> PCbuild folder (from the 2.7.2 source at least): > > Memory fault on my part. I was thinking they had bypassed 2008 and gone > from 2005 straight to 2010, but I see both 2.6 and 2.7 use VS2008. > The OP's problem is that when he tries to compile the dll is not found by py2exe. The simple solution which works for me is just to exclude it as I mentioned in a previous post and it is also mentioned in the wxPython wiki - http://wiki.wxpython.org/py2exe IIRC this problem only shows up with py 2.6 and higher. Werner From werner.bruhin at free.fr Thu Aug 25 19:52:52 2011 From: werner.bruhin at free.fr (Werner F. Bruhin) Date: Thu, 25 Aug 2011 19:52:52 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: <4E56865D.3000900@probo.com> References: <4E567EE7.1000707@probo.com> <4E56865D.3000900@probo.com> Message-ID: <4E568BF4.8070009@free.fr> Tim and Mark, On 08/25/2011 07:29 PM, Tim Roberts wrote: > Mark Mordeca wrote: >> Hi, >> >> Python is built using 2008. You can find this in the readme.txt under the >> PCbuild folder (from the 2.7.2 source at least): > > Memory fault on my part. I was thinking they had bypassed 2008 and gone > from 2005 straight to 2010, but I see both 2.6 and 2.7 use VS2008. > The OP's problem is that when he tries to compile the dll is not found by py2exe. The simple solution which works for me is just to exclude it as I mentioned in a previous post and it is also mentioned in the wxPython wiki - http://wiki.wxpython.org/py2exe IIRC this problem only shows up with py 2.6 and higher. Werner From rays at blue-cove.com Thu Aug 25 16:22:07 2011 From: rays at blue-cove.com (RayS) Date: Thu, 25 Aug 2011 07:22:07 -0700 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: References: Message-ID: <201108251422.p7PEMA5Q030323@blue-cove.com> At 06:02 AM 8/25/2011, Jacob Kruger wrote: >The last 2 lines rendered in that window are then the following: >*** finding dlls needed *** >error: MSVCP90.dll: No such file or directory > >That specific DLL gets copied quite easily into the relevant >subfolder of the dist folder when I run a similar command for my >much larger, but, I suppose, simpler, mapData app, since that one >doesn't try to import libraries/modules like piaudiere or wxPython as such. > >Any thoughts on what could really be happening here, or should I try >sort out reinstalling windows7 or something...? I always explicitly bundle the *90 dlls with the exe using includes [], or the user needs the redistributable. Even if Win7 ships with *90 dlls you might still need explicit copies. Re-view the tutorial for more setup hints http://www.py2exe.org/index.cgi/Tutorial#Step52 I'm still wrangling with dynamic import errors... -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacobk at mailzone.co.za Fri Aug 26 09:11:06 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 26 Aug 2011 09:11:06 +0200 Subject: [python-win32] Recurring DLL error with py2exe Message-ID: Thanks, Werner Adding the reference to the dll_excludes to the options dict made the py2exe setup.py now run fine. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message --------------- Subject: Re: [python-win32] Recurring DLL error with py2exe From: "Werner F. Bruhin" Date: Thu, 25 Aug 2011 17:57:05 +0200 To: jacobk at mailzone.co.za Cc: Jacob Kruger , python-win32 at python.org >On 08/25/2011 04:30 PM, Jacob Kruger wrote: >> Ok, where should I include that exclude line? >> >> I tried just copying it into the setup.py file a bit higher up, but not sure if needs to be specifically included in some part of it, and I found out if I also tried to tell it not to copy the MSVCRT subfolder it still generates that error so it must have something to do with the actual compilation processing of the external module or something, but, maybe if I just need to tell it to exclude those files from a specific spot in the setup.py file that could sort it out? >dll_exludes is a py2exe option, should we in your options dict - see below. >> Anyway, here's current source of my setup.py file: >> #---start of source--- >> from glob import glob >> from distutils.core import setup >> import py2exe >> dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] >> data_files = [ >> ("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')) >> ] >> #data_files= [] >> options = { >> "bundle_files": 1, >Option "1" is more trouble then it is worse - would recommend 2 and use >a installer such as InnoSetup to deliver a single file. Some of this is >shown/explained on the wxPython wiki. >> "ascii": 1, # to make a smaller executable, don't include the encodings >> "compressed": 1, # compress the library archive > "dll_excludes": dll_excludes, >> } >> >> setup( >> # The first three parameters are not required, if at least a >> # 'version' is given, then a versioninfo resource is built from >> # them and added to the executables. >> version = "1.0.0", >> description = "testingWxPython", >> name = "aboutBox", >> options = {'py2exe': options}, >> >> # targets to build >> console = ["AboutBox.py"], >> data_files=data_files >> ) >> #---end of source--- >> >> Could it also maybe be something to do with this line?: >> console = ["AboutBox.py"], >> >> Since while setup.py is running in console mode, don't know if the resulting wxPython based .exe runs in a console mode window as such..? >No problem, it will show a console window and a second window is opened >with the wxPython GUI. This is sometimes handy to track down some >tracebacks which don't show if you use "window". > >Werner From blindza at gmail.com Fri Aug 26 10:53:23 2011 From: blindza at gmail.com (Jacob Kruger) Date: Fri, 26 Aug 2011 10:53:23 +0200 Subject: [python-win32] Recurring DLL error with py2exe In-Reply-To: Message-ID: Oh yes, and it also lets me build the .exe for the small test app making use of pyaudiere, so I can now get it to play sounds, with panning etc. quite easily - will just get some friends etc. to test this on cleaner, older versions of operating systems etc. once can upload the zip file to FTP server from home where connection is at least decent... So, thanks again, and stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message --------------- Subject: Re: [python-win32] Recurring DLL error with py2exe From: Jacob Kruger Date: Fri, 26 Aug 2011 09:11:06 +0200 To: >Thanks, Werner > >Adding the reference to the dll_excludes to the options dict made the >py2exe setup.py now run fine. > >Stay well > >Jacob Kruger >Blind Biker >Skype: BlindZA >'...fate had broken his body, but not his spirit...' > > >----- Original Message --------------- > >Subject: Re: [python-win32] Recurring DLL error with py2exe > From: "Werner F. Bruhin" > Date: Thu, 25 Aug 2011 17:57:05 +0200 > To: jacobk at mailzone.co.za > Cc: Jacob Kruger , > python-win32 at python.org > >>On 08/25/2011 04:30 PM, Jacob Kruger wrote: >>> Ok, where should I include that exclude line? >>> >>> I tried just copying it into the setup.py file a bit higher up, but not >sure if needs to be specifically included in some part of it, and I found >out if I also tried to tell it not to copy the MSVCRT subfolder it still >generates that error so it must have something to do with the actual >compilation processing of the external module or something, but, maybe if I >just need to tell it to exclude those files from a specific spot in the >setup.py file that could sort it out? >>dll_exludes is a py2exe option, should we in your options dict - see >below. >>> Anyway, here's current source of my setup.py file: >>> #---start of source--- >>> from glob import glob >>> from distutils.core import setup >>> import py2exe >>> dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', >'tcl84.dll', 'tk84.dll', 'MSVCP90.dll', 'mswsock.dll', 'powrprof.dll'] >>> data_files = [ >>> ("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio >9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')) >>> ] >>> #data_files= [] >>> options = { >>> "bundle_files": 1, >>Option "1" is more trouble then it is worse - would recommend 2 and use >>a installer such as InnoSetup to deliver a single file. Some of this is >>shown/explained on the wxPython wiki. >>> "ascii": 1, # to make a smaller executable, don't include the >encodings >>> "compressed": 1, # compress the library archive >> "dll_excludes": dll_excludes, >>> } >>> >>> setup( >>> # The first three parameters are not required, if at least a >>> # 'version' is given, then a versioninfo resource is built from >>> # them and added to the executables. >>> version = "1.0.0", >>> description = "testingWxPython", >>> name = "aboutBox", >>> options = {'py2exe': options}, >>> >>> # targets to build >>> console = ["AboutBox.py"], >>> data_files=data_files >>> ) >>> #---end of source--- >>> >>> Could it also maybe be something to do with this line?: >>> console = ["AboutBox.py"], >>> >>> Since while setup.py is running in console mode, don't know if the >resulting wxPython based .exe runs in a console mode window as such..? >>No problem, it will show a console window and a second window is opened >>with the wxPython GUI. This is sometimes handy to track down some >>tracebacks which don't show if you use "window". >> >>Werner > >_______________________________________________ >python-win32 mailing list >python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From mail at timgolden.me.uk Fri Aug 26 11:28:49 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 26 Aug 2011 10:28:49 +0100 Subject: [python-win32] Issue with inserting Microsoft Excel charts into Word In-Reply-To: References: Message-ID: <4E576751.8040709@timgolden.me.uk> On 25/08/2011 17:50, Tom wrote: > Hello all, > I am writing a reporting application that uses word's COM interface. I > recently found myself needing to insert a chart into the document, and > the "AddChart" method seemed ideal > (http://msdn.microsoft.com/en-us/library/bb226069(v=office.12).aspx). > The code is this: > image_chart = > word.ActiveWindow.Selection.InlineShapes.AddChart(Type=constants.xlBarClustered) > chart = image_chart.Chart > chart.ChartData.Activate() > ... fill chart with data ... > > This runs fine on my laptop machine (Windows 7) and a little excel > window pops up with some basic starting data that my application > modifies. I deployed it to our Windows 2003 server and I was dismayed to > find that it failed. The issue was that image_chart had no Chart > attribute, no exception is being raised when AddChart is called and an > object is returned as normal, just without a Chart (and thus no ability > to edit the data?). I did a little digging around and it seems that > excel is spawned when I call AddChart, but it quits a second or two > afterwards for no apparent reason, according to the event viewer "Excel > terminated normally after a runtime of 1 seconds". > > The code is being called from a Celery task queue (so it is called from > within a thread), and this has not been an issue before - the code is > incredibly COM heavy. However when I spin up IDLE and use AddChart on a > blank document the Excel window appears as normal and does not close. Frankly clutching at straws, but there was something recently where -- surprisingly -- using dynamic or static dispatching made a difference. Might this apply here? TJG From tom at pentest.7safe.com Fri Aug 26 15:35:46 2011 From: tom at pentest.7safe.com (Tom) Date: Fri, 26 Aug 2011 14:35:46 +0100 Subject: [python-win32] Fwd: Issue with inserting Microsoft Excel charts into Word In-Reply-To: References: <4E576751.8040709@timgolden.me.uk> <4E577A79.8040703@timgolden.me.uk> Message-ID: Me and Tim started to email each other directly, here are the messages for anyone who is interested. ~Tom ---------- Forwarded message ---------- From: Tom Date: Fri, Aug 26, 2011 at 12:04 PM Subject: Re: [python-win32] Issue with inserting Microsoft Excel charts into Word To: Tim Golden Thank you so much for your help, I really appreciate it. I'm really not sure what the issue is, but I have it working now. I changed DispatchEx to EnsureDispatch and I changed the WorkSheets call (Which apparently doesn't exist on server 2003) to ActiveSheet and this went through fine. I expect me not knowing why this happened will come back to bite me soon enough, but its working now. ~Tom On Fri, Aug 26, 2011 at 11:50 AM, Tim Golden wrote: > On 26/08/2011 11:42, Tom wrote: > >> Ok, this is weird. I think you were right Tim: >> I tried running makepy on all the libraries I thought I would need, and >> that didn't work. So I just copied all the gen_py files to the server >> and re-ran the report generation. This seemed to produce a different >> error - instead of not finding the Chart object it now does, but it >> errors because excels workbook object (_workbook) doesn't have a >> WorkSheets attribute (worksheet = chart.ChartData.Workbook.** >> WorkSheets(1)). >> >> Can you explain more about dynamic and static dispatching, can I force >> win32com to do one or the other? >> > > It's a concept basically invented by Mark Hammond when he created > the Python bindings to COM -- ie it's not COM terminology as such. > > By good fortune, the (slightly ancient but still relevant) book > on Python Win32 has a sample chapter which covers this stuff: > > http://oreilly.com/catalog/**pythonwin32/chapter/ch12.html > > In short, though, the win32com modules will either generate > a temporary wrapper around the IDispatch-interfaces objects; > or will generate an actual Python module which is squirrels > away under the gen_py directory. > > The most notable difference is that the former simply passes > everything it can through to the underlying COM objects, > which are case-insensitive, while the latter uses Python > module which is therefore case-sensitive. So this code: > > xl = win32com.client.Dispatch ("Excel.Application") > xl.visible = 1 > > will work if the xl object has been dynamically dispatched > (the default) but will fail if it's statically dispatched > because the documented attribute is actually Visible with > an initial cap. > > To force one or another: > > xl = win32com.client.dynamic.**Dispatch ("Excel.Application") > > for dynamic; or > > xl = win32com.client.gencache.**EnsureDispatch ("Excel.Application") > > for static. > > HTH > > TJG > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw_win at wtwinsoftware.com Sun Aug 28 21:18:26 2011 From: kw_win at wtwinsoftware.com (Kevin Walzer) Date: Sun, 28 Aug 2011 15:18:26 -0400 Subject: [python-win32] win32api / py23xe / com server Message-ID: Hello all, I?ve continued my efforts to create a COM server with Python and have found success by implementing one without the overhead of a GUI event loop (my Tkinter app didn?t work as a COM server). I?ve created the server and confirmed that it works when run from Python, but I am not able to deploy it via py2exe. I get this familiar error: Traceback (most recent call last): File "boot_com_servers.py", line 4, in ImportError: No module named win32api I?ve reviewed the list archives and elsewhere to determine what might be the issue, and I?ve added all the appropriate statements that I can think of to the setup script (importing various pywin modules, explicitly setting win32api as a package to include, etc.). I?m using the latest ActivePython 2.7 with fresh installations of py2exe and pythonwin on Windows 7. I?m a bit baffled here, so any advice is appreciated. My setup.py script is below. Thanks! # -*- coding: cp1252 -*- # This is the distutils script for creating a Python-based com (exe or dll) # server using win32com. This script should be run like this: # # % python setup.py py2exe # # After you run this (from this directory) you will find two directories here: # "build" and "dist". The .dll or .exe in dist is what you are looking for. ############################################################################## import glob import os import sys import shutil import pywintypes import pythoncom import win32api try: # py2exe 0.6.4 introduced a replacement modulefinder. # This means we have to add package paths there, not to the built-in # one. If this new modulefinder gets integrated into Python, then # we might be able to revert this some day. # if this doesn't work, try import modulefinder try: import py2exe.mf as modulefinder except ImportError: 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 from distutils.core import setup import py2exe import sys class Target: def __init__(self, **kw): self.__dict__.update(kw) self.version = "3.2.0" self.company_name = "WordTech Communications LLC" self.copyright = "(c) 2011 WordTech Communications LLC" self.name = "QuickWho" quickwho_com_target = Target( description = "QuickWho COM server", # use module name for win32com exe/dll server modules = ["quickwho_com"], create_exe = True, create_dll = False ) setup( name="QuickWho", # the following two parameters embed support files within exe/dll file options={"py2exe": { "bundle_files": 3, 'packages' : ['win32api'] } }, zipfile=None, version="3.2.0", description="QuickWho COM Server", com_server=[quickwho_com_target], ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw_win at wtwinsoftware.com Mon Aug 29 15:12:02 2011 From: kw_win at wtwinsoftware.com (Kevin Walzer) Date: Mon, 29 Aug 2011 09:12:02 -0400 Subject: [python-win32] win32api / py23xe / com server In-Reply-To: References: Message-ID: <89AC989A2800421DAE48F67D10970BDF@KevinPC> I somehow got the component to load, finally. One trick I did use was absolute import of the win32api module, which seemed to help. However, I can?t pinpoint exactly what I did wrong vs. what I did right. That?s a bit frustrating, but no worries. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steffen.froemer at gns-systems.de Wed Aug 31 14:38:47 2011 From: steffen.froemer at gns-systems.de (=?ISO-8859-1?Q?Steffen_Fr=F6mer?=) Date: Wed, 31 Aug 2011 14:38:47 +0200 Subject: [python-win32] checking file permission on network share Message-ID: <4E5E2B57.2040708@gns-systems.de> Hello, i try to check, if a file on network-share is read only. I tried different ways. filename = r'//server/share/filename.txt' 1: import win32api, win32con fileAtt = win32api.GetFileAttributes(filename) if (fileAtt & win32con.FILE_ATTRIBUTE_READONLY): print("READONLY") 2: import os, stat fileAtt = os.stat(filename)[0] if (not fileAtt & stat.S_IWRITE): print("READONLY") 3: import os if not os.access(filename, os.W_OK): print("READONLY") all variants give me same result, that file is NOT readonly, but in real it is. The network-share is a Samba-Service with share-option "read only = yes" i also tried to set "read only"-Flag in windows and copy this file to network share. Is there a solution, to find out, if my file is writeable or not? Regards, Steffen From M.Schulte-Oversohl at pragmatis.de Wed Aug 31 16:55:22 2011 From: M.Schulte-Oversohl at pragmatis.de (Manfred Schulte-Oversohl) Date: Wed, 31 Aug 2011 16:55:22 +0200 Subject: [python-win32] Pythonwin MDI Child Size Message-ID: I tried to fill a MDI child at start up or on open to the full size of the enclosing frame but self.ShowWindow(win32con.SW_SHOWMAXIMIZED) or self.SetWindowPlacement(placement) did not work (self is the MDI Child PyCWnd). Did I miss something or is it impossible? Many thanks for any hint. Manfred -------------- next part -------------- An HTML attachment was scrubbed... URL: