From keating at acm.org Mon Jan 4 01:11:09 2010 From: keating at acm.org (Paul Keating) Date: Mon, 04 Jan 2010 01:11:09 +0100 Subject: [python-win32] Question concerning wmi c.CIM_DataFile References: <2E8EE617FF5865459F6EF9217BC466E2063E3C@opr-pr-exc-01.rgfc.main> Message-ID: <014a01ca8cd2$6d32ff80$4801a8c0@vuurpijlhuisje.local> Don't do this: #File to query string = "C:\DOCUME~1\profileName\LOCALS~1\Temp\\Temporary Directory 1 for deluxetreee (2).zip\Christmas.exe" #Substitute "\" to "\\" path = re.sub('\\\\', '\\\\\\\\', string) I can see nothing wrong with this particular bit of code, but sooner or later doing this sort of thing will trip you up. Instead use a raw string (r"mys\t\ri\ng") that will leave your whacks intact. All you need is this: path = r"C:\DOCUME~1\profileName\LOCALS~1\Temp\\Temporary Directory 1 for deluxetreee (2).zip\Christmas.exe" I notice you have a doubled \ in path after Temp which may be the problem, depending on the target filesystem. -- Paul Keating The Hague -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sunny.Carter at metaswitch.com Mon Jan 4 17:51:42 2010 From: Sunny.Carter at metaswitch.com (Sunny Carter) Date: Mon, 4 Jan 2010 16:51:42 +0000 Subject: [python-win32] Boolean type changed in Python 3.0? Message-ID: <44EE1E31095AE349AC6C3C0B69FFBF02932E0B3D6F@ENFIMBOX1.ad.datcon.co.uk> Hi all, I'm trying my posting again with a different subject so that it is more generic. I am having problems calling across the win32 API using a Boolean argument in Python 3.0 (False in my python script) which is not recognised as a Boolean (The error I get back from setattr is 'Boolean value expected'). Has the way that a Boolean is represented changed in Python 3.0? This worked fine in Python 2.6. I cannot get it to work and have tried values of False,True,0 and 1, all to no avail. It sounds like a bug in the win32com API for 3.0 to me. Further details below. Many thanks to anyone that can help, Sunny Carter ============================================================================================================== I am writing a Python script to call across to Adobe Photoshop, to automate some image manipulation. (For historical reasons I'm writing using Python rather than javascript or VB) My problem is that my script works fine using Python 2.6, but fails after upgrading to Python 3.0 or 3.1.1. I've converted the script to Python 3.0 format, and it all works except the call across the Photoshop API. The problem seems to be with the win32 API call using a Boolean value (False in my python script) which is not recognised as a Boolean by Photoshop. Details: Script based in part on http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html Script uses pywin32 from http://sourceforge.net/projects/pywin32/files/ - I have installed pywin32-214.win32-py2.6.exe for Python 2.6 and pywin32-214.win32-py3.0.exe for use with Python 3.0 Subset of the script: import win32com.client psApp = win32com.client.Dispatch('Photoshop.Application') doc = psApp.Open(os.path.abspath(psd_image.psd_filename)) # Here I do the image manipulation which I haven't included here as it is irrelevant (and working fine - # calling Photoshop and making it do stuff) psd_save_options = win32com.client.Dispatch("Photoshop.PNGSaveOptions") psd_save_options.Interlaced = False print("Save as %s" % (os.path.join(output_directory, psd_image.final_filename))) doc.SaveAs(os.path.join(output_directory, psd_image.final_filename), psd_save_options, True, 2) # lower case extension Exception hit: Unexpected error detail: Traceback (most recent call last): File "C:\brander\brander.py", line 6464, in main() File "C:\brander\brander.py", line 6407, in main recf) File "C:\brander\brander.py", line 4303, in createBranding brand_widgets) File "C:\brander\brander.py", line 1961, in reconstructImageDirectory brand_widgets) File "C:\brander\brander.py", line 1961, in reconstructImageDirectory brand_widgets) File "C:\brander\brander.py", line 1961, in reconstructImageDirectory brand_widgets) File "C:\brander\brander.py", line 1999, in reconstructImageDirectory new_color_palette) File "C:\brander\brander.py", line 2519, in reconstructPSDImageFile psd_save_options.Interlaced = False File "C:\Program Files\Python31\lib\site-packages\win32com\client\dynamic.py", line 550, in __setattr__ self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Adobe Photoshop' , 'Boolean value expected', None, 0, -2147220276), None) Investigation tracing from pywintypes.py The dll being loaded is C:\WINDOWS\system32\pywintypes30.dll Things tried so far I've already tried setting psd_save_options.Interlaced to True, "False", 0, 1 and None. In this, None gets further on in the script but then fails on the SaveAs call. If I delete the psd_save_options.Interlaced line, then the script fails in exactly the same way on the SaveAs call (this time the parameter True is the culprit). As I say - the same script works fine using Python 2.6 and pywin32-214.win32-py2.6.exe. I am running on Windows XP. Help? If anyone can help with a solution that would be great. If there is no way of fixing, is it possible to run my python script using Python 2.6 but call out to a separate script running Python 3.0 for the part where I require 3.0? (not included here) Thanks so much, Sunny Carter -------------- next part -------------- An HTML attachment was scrubbed... URL: From wade.dyck at gmail.com Mon Jan 4 18:06:20 2010 From: wade.dyck at gmail.com (Wade Dyck) Date: Mon, 4 Jan 2010 10:06:20 -0700 Subject: [python-win32] Exception: object has no attribute 'Win32_Process' Message-ID: I create a wmi connection to a server in a separate domain from where the script is running like this: remote = wmi.connect_server(server=server, user=r"%s\%s" % (domain, user), password=password, impersonation_level="impersonate") self.c = wmi.WMI(wmi=remote) I then successfully run a few Win32_Process.create() commands (which fail if the initial connection above uses impersonation_level="delegate"). Next I use adsi to trust the server for delegation: computer.Put('userAccountControl', value) computer.Setinfo() At this point I want to use Win32_Process.create() to xcopy some files from a third server, so I switch to delegation since impersonate won't allow access to network resources: remote = wmi.connect_server(server=self.server, user=r"%s\%s" % (self.domain, self.user), password=self.password, impersonation_level="delegate") self.c = wmi.WMI(wmi=remote) But then when I try to create the process using: pid, res = self.c.Win32_Process.Create('cmd.exe /c xcopy %s %s \ /s /e /i /y /c /q' % (src, dest)) I get the following exception: AttributeError: '' object has no attribute 'Win32_Process' However, this works fine if I don't set the userAccountControl attribute above using adsi. It also seems specific to actually setting the attribute, as the code is always using adsi to get DNs and the current value of userAccountControl. Am I doing something wrong, or does anyone have suggestions on what to try next? -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Jan 4 19:57:45 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 04 Jan 2010 10:57:45 -0800 Subject: [python-win32] Question concerning wmi c.CIM_DataFile In-Reply-To: <2E8EE617FF5865459F6EF9217BC466E2063E3C@opr-pr-exc-01.rgfc.main> References: <2E8EE617FF5865459F6EF9217BC466E2063E3C@opr-pr-exc-01.rgfc.main> Message-ID: <4B423A29.9050305@probo.com> Kelvin Lomboy Mendez wrote: > > I?m currently writing a script to access approximately 400 computers > for removing a particular app from the system. I?m having problems > getting results using the wmi c.CIM_DataFile (name=file). When I use > file as a variable which equals to the path to the app I want to > remove I don?t get nothing back, however, if I hard code the path, I > get results. See snippet below for an example of what I?m talking > about. I appreciate in advance for any help I can get. Thank you. > > > > import wmi > > import re > > > > def queryFile(file, host): > > print '[Debug nukeXmas()]:' + file > > c = wmi.WMI(host) > > for f in c.CIM_DataFile (name=file): > > print 'Install Date:', f.InstallDate > > > > def queryFile2(file, host): > > print '[Debug nukeXmas()]:' + file > > c = wmi.WMI(host) > > for f in c.CIM_DataFile > (name="C:\\DOCUME~1\\profileName\\LOCALS~1\\Temp\\Temporary Directory > 1 for deluxetreee (2).zip\\Christmas.exe"): > > print 'Install Date:', f.InstallDate > > > > #File to query > > string = "C:\DOCUME~1\profileName\LOCALS~1\Temp\\Temporary Directory 1 > for deluxetreee (2).zip\Christmas.exe" > > > > #Substitute "\" to "\\" > > path = re.sub('\\\\', '\\\\\\\\', string) > Don't do this. You WANT the string to contain single backslashes. This is one of the most confusing things about working with strings in Python on Windows. Here's a test. How many characters are in this string? xyz = "a\\b\tc" The answer is 5. There's a letter "a", a backslash, a letter "b", a tab, and a letter "c". When you pass a file name into an API, the name should only contain single backslashes (or forward slashes -- both work equally well in the Win32 API). In order to GET single backslashes in a Python string literal, you need to type TWO (or use the raw r"string" concept), but the string itself only contains one. > #Close query path with double quotes > > file = '"'+path+'"' > Don't do this either. The file name does not contain quotes. If you are typing the file name on a command-line, you have to provide quotes so they get handled by the command line parser properly, but when you're calling an API, you should NEVER use quotes. > #I'm having problems here, query brings back nothing > > queryFile(file, '172.27.1.5') > Right, because the file name you are passing here is literally this: "C:\\DOCUME~1\\profileName\\LOCALS~1\\Temp\\Temporary Directory 1 for deluxetreee (2).zip\\Christmas.exe" > > > #Here, I hard code the path to the exe and it works > > queryFile2(file, '172.27.1.5') > Right, because the file name you are passing here is literally this: C:\DOCUME~1\profileName\LOCALS~1\Temp\Temporary Directory 1 for deluxetreee (2).zip\Christmas.exe And THAT is what the file name really is. By the way, your whole concept is loony. This will not work at all on Vista or Win 7, because the "Documents and Settings" tree is now called "Users". You are assuming that every system is going to have this file as "...tree (2).zip", but depending on how many times it has been downloaded, it might be called something different (like "...tree.zip" or "...tree(3).zip"). Further, the directory names you are using are configurable. They don't have to be called "Documents and Setting" or "Local Settings", and they don't have to be located on "C:". You should be using the shell folder APIs to find the names of the "well-known folders". Plus, the whole "Local Settings\Temp" folder is volatile. You should just be able to wipe out that whole directory without causing any damage. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mdriscoll at co.marshall.ia.us Mon Jan 4 22:18:43 2010 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 04 Jan 2010 15:18:43 -0600 Subject: [python-win32] Question concerning wmi c.CIM_DataFile In-Reply-To: <4B423A29.9050305@probo.com> References: <2E8EE617FF5865459F6EF9217BC466E2063E3C@opr-pr-exc-01.rgfc.main> <4B423A29.9050305@probo.com> Message-ID: <4B425B33.2060003@co.marshall.ia.us> On 1:59 PM, Tim Roberts wrote: > Kelvin Lomboy Mendez wrote: > >> I'm currently writing a script to access approximately 400 computers >> for removing a particular app from the system. I'm having problems >> getting results using the wmi c.CIM_DataFile (name=file). When I use >> file as a variable which equals to the path to the app I want to >> remove I don't get nothing back, however, if I hard code the path, I >> get results. See snippet below for an example of what I'm talking >> about. I appreciate in advance for any help I can get. Thank you. >> >> >> >> import wmi >> >> import re >> >> >> >> def queryFile(file, host): >> >> print '[Debug nukeXmas()]:' + file >> >> c = wmi.WMI(host) >> >> for f in c.CIM_DataFile (name=file): >> >> print 'Install Date:', f.InstallDate >> >> >> >> def queryFile2(file, host): >> >> print '[Debug nukeXmas()]:' + file >> >> c = wmi.WMI(host) >> >> for f in c.CIM_DataFile >> (name="C:\\DOCUME~1\\profileName\\LOCALS~1\\Temp\\Temporary Directory >> 1 for deluxetreee (2).zip\\Christmas.exe"): >> >> print 'Install Date:', f.InstallDate >> >> >> >> #File to query >> >> string = "C:\DOCUME~1\profileName\LOCALS~1\Temp\\Temporary Directory 1 >> for deluxetreee (2).zip\Christmas.exe" >> >> >> >> #Substitute "\" to "\\" >> >> path = re.sub('\\\\', '\\\\\\\\', string) >> >> > Don't do this. You WANT the string to contain single backslashes. This > is one of the most confusing things about working with strings in Python > on Windows. Here's a test. How many characters are in this string? > > xyz = "a\\b\tc" > > The answer is 5. There's a letter "a", a backslash, a letter "b", a > tab, and a letter "c". > > When you pass a file name into an API, the name should only contain > single backslashes (or forward slashes -- both work equally well in the > Win32 API). In order to GET single backslashes in a Python string > literal, you need to type TWO (or use the raw r"string" concept), but > the string itself only contains one. > > >> #Close query path with double quotes >> >> file = '"'+path+'"' >> >> > Don't do this either. The file name does not contain quotes. If you > are typing the file name on a command-line, you have to provide quotes > so they get handled by the command line parser properly, but when you're > calling an API, you should NEVER use quotes. > > >> #I'm having problems here, query brings back nothing >> >> queryFile(file, '172.27.1.5') >> >> > Right, because the file name you are passing here is literally this: > "C:\\DOCUME~1\\profileName\\LOCALS~1\\Temp\\Temporary Directory 1 > for deluxetreee (2).zip\\Christmas.exe" > > >> >> >> #Here, I hard code the path to the exe and it works >> >> queryFile2(file, '172.27.1.5') >> >> > Right, because the file name you are passing here is literally this: > C:\DOCUME~1\profileName\LOCALS~1\Temp\Temporary Directory 1 for > deluxetreee (2).zip\Christmas.exe > > And THAT is what the file name really is. > > By the way, your whole concept is loony. This will not work at all on > Vista or Win 7, because the "Documents and Settings" tree is now called > "Users". You are assuming that every system is going to have this file > as "...tree (2).zip", but depending on how many times it has been > downloaded, it might be called something different (like "...tree.zip" > or "...tree(3).zip"). Further, the directory names you are using are > configurable. They don't have to be called "Documents and Setting" or > "Local Settings", and they don't have to be located on "C:". You should > be using the shell folder APIs to find the names of the "well-known > folders". > > Plus, the whole "Local Settings\Temp" folder is volatile. You should > just be able to wipe out that whole directory without causing any damage. > > The OP should check out Tim Golden's winshell module as it gives access to the common folders quite easily: http://timgolden.me.uk/python/winshell.html -- *Mike Driscoll* Blog: http://blog.pythonlibrary.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Jan 5 00:43:24 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 04 Jan 2010 18:43:24 -0500 Subject: [python-win32] Create a QueryInfo type Windows Shell Extension to provide InfoTip data in Windows Explorer Message-ID: <1262648604.4336.1352935453@webmail.messagingengine.com> Wondering if its possible to create Windows Shell Extensions using pywin32 and if so, has anyone has tried to create a QueryInfo type Windows Shell Extension? I would like to create a Python equivalent of the simple InfoTip described in this well written tutorial. http://www.codeproject.com/KB/shell/shellextguide3.aspx Here's a quick excerpt from this article: Quote: The Active Desktop shell introduced a new feature: tooltips that show a description of certain objects if you hover the mouse over them. For example, hovering over My Documents shows this tooltip: [My Computer tooltip - 6K] Other objects like My Computer and Control Panel have similar tooltips. These bits of text are called infotips, since they are tooltips that provide information about the file, folder, or object that the mouse is over. We can provide our own infotip text for other objects in the shell, using an infotip extension. An example of an infotip extension that you have probably already seen is in WinZip, which shows the contents of compressed files: [WinZip tooltip - 5K] This article's sample extension will be a quick text file viewer - it will display the first line of the file, along with the total file size. This information will appear in an infotip when the user hovers the mouse over a .TXT file. Extracting the info I want to display in an InfoTIp is easy :) ... its the plumbing to support the display of information that has me stuck. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Jan 5 02:15:03 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 04 Jan 2010 17:15:03 -0800 Subject: [python-win32] Create a QueryInfo type Windows Shell Extension to provide InfoTip data in Windows Explorer In-Reply-To: <1262648604.4336.1352935453@webmail.messagingengine.com> References: <1262648604.4336.1352935453@webmail.messagingengine.com> Message-ID: <4B429297.4000400@probo.com> python at bdurham.com wrote: > Wondering if its possible to create Windows Shell Extensions using > pywin32 and if so, has anyone has tried to create a QueryInfo type > Windows Shell Extension? Sure, it's possible. A shell extension is just a COM server. There are lots of example showing how to build a COM server in Python. You'll need to support IPersistFile and IQueryInfo. Here's a web page from Tim Golden showing a sample shell extension in Python. You'll need to modify this to support IPersistFile and IQueryInfo based on the information in that article, but this will show you the mechanics of it: http://timgolden.me.uk/python/win32_how_do_i/add-my-own-icon-overlays.html -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From keesvanschaik at gmail.com Tue Jan 5 03:28:47 2010 From: keesvanschaik at gmail.com (Kees van Schaik) Date: Tue, 05 Jan 2010 02:28:47 +0000 Subject: [python-win32] win32com calling IE: OLE error 0x800704a6 Message-ID: <4B42A3DF.20003@gmail.com> (This is a cross post from the Python mailing list where unfortunately nobody responded. I would be very grateful if someone could give me some insights!) Dear all, I have written a Python script that runs on Windows XP with Python 2.5 and uses Internet Explorer to 'pretty print' some HTML output. This has been working perfectly fine for a few years until recently IE was upgraded to version 8. Now occasionally Python throws an error that originates from the win32com.client.Dispatch() method and has description 'OLE error 0x800704a6'. (Occasionally means that sometimes it happens, sometimes it doesn't. I haven't been able to figure out what the trigger exactly is.) The most recent version of win32com is installed. Google on the error code didn't give me a lot of hits, and no useful ones. So, I was hoping somebody might be able to give me some pointers what might be going on. Here is the relevant (very straightforward) Python code: import win32com.client class IE: def __init__(self,url=None,vis=0,standalone=False): #Pas registerwaardes aan voor het printen: if not standalone: self.regOld=self.getRegValues() self.setRegValues ({'margin_left':'0.00000','margin_right':'0.00000','footer':'','header':''}) #Start instantie van IE op: self.ie=win32com.client.Dispatch ('InternetExplorer.Application') self.ie.Visible = vis if url!=None: self.ie.Navigate(url) and the class furthermore implements some methods to open & print some HTML-file. Unfortunately I only have a screenshot of the error: http://tweakers.net/ext/f/cAdKjyjs7w4yZRu6s4RqNwjW/full.png Thanks in advance for your thoughts, Kees -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Tue Jan 5 08:58:21 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 05 Jan 2010 18:58:21 +1100 Subject: [python-win32] Boolean type changed in Python 3.0? In-Reply-To: <44EE1E31095AE349AC6C3C0B69FFBF02932E0B3D6F@ENFIMBOX1.ad.datcon.co.uk> References: <44EE1E31095AE349AC6C3C0B69FFBF02932E0B3D6F@ENFIMBOX1.ad.datcon.co.uk> Message-ID: <4B42F11D.3010109@gmail.com> On 5/01/2010 3:51 AM, Sunny Carter wrote: > Hi all, > I'm trying my posting again with a different subject so that it is more > generic. > I am having problems calling across the win32 API using a Boolean > argument in Python 3.0 (False in my python script) which is not > recognised as a Boolean (The error I get back from setattr is 'Boolean > value expected'). > Has the way that a Boolean is represented changed in Python 3.0? This > worked fine in Python 2.6. I cannot get it to work and have tried values > of False,True,0 and 1, all to no avail. > It sounds like a bug in the win32com API for 3.0 to me. > Further details below. > Many thanks to anyone that can help, I expect something subtle is going on with boolean conversions in 3.x, but the test suite does have coverage of booleans, so I'm really not sure what the problem could be. I don't have photoshop so I'm unable to reproduce - I intend revisiting the tests to see if I can spot an edge case which isn't tested, but I'm yet to get to that after the holidays... Cheers, Mark From timr at probo.com Tue Jan 5 19:09:19 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Jan 2010 10:09:19 -0800 Subject: [python-win32] win32com calling IE: OLE error 0x800704a6 In-Reply-To: <4B42A3DF.20003@gmail.com> References: <4B42A3DF.20003@gmail.com> Message-ID: <4B43804F.1010501@probo.com> Kees van Schaik wrote: > > I have written a Python script that runs on Windows XP with Python 2.5 > and uses Internet Explorer to 'pretty print' some HTML output. This > has been working perfectly fine for a few years until recently IE was > upgraded to version 8. Now occasionally Python throws an error that > originates from the win32com.client.Dispatch() method and has > description 'OLE error 0x800704a6'. (Occasionally means that sometimes > it happens, sometimes it doesn't. I haven't been able to figure out > what the trigger exactly is.) The most recent version of win32com is > installed. Google on the error code didn't give me a lot of hits, and > no useful ones. > The 80070xxx errors are often COM-wrapped versions of the standard Windows errors. 0x4A6 is 1190, which is "ERROR_SHUTDOWN_IS_SCHEDULED". Is it possible this happens after a Windows Update has occurred but before the reboot? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From keesvanschaik at gmail.com Tue Jan 5 20:28:37 2010 From: keesvanschaik at gmail.com (Kees van Schaik) Date: Tue, 5 Jan 2010 19:28:37 +0000 Subject: [python-win32] win32com calling IE: OLE error 0x800704a6 Message-ID: <5f2152f71001051128r4661f997m8e84aa61aad610d1@mail.gmail.com> >The 80070xxx errors are often COM-wrapped versions of the standard >Windows errors. 0x4A6 is 1190, which is "ERROR_SHUTDOWN_IS_SCHEDULED". >Is it possible this happens after a Windows Update has occurred but >before the reboot? Thanks. It is not impossible, but unlikely given that it has occured so frequently over the last period and the pc gets rebooted each morning. I mean, I don't assume updates that require restarting occur so frequently, do they? Then again, the pc is used by somebody who might be missing such things. Although this is not the right thread, I'm looking at alternatives in case I can't get it resolved. The most straightforward way seems to be to print directly using a win32ui.CreateDC() object. There is only one problem left with that approach, namely dc.TextOut(0, 0, "Text") works perfect to place plain text on the page, but I'd also need to print a limited number of non-ASCII characters (accents in names, eurosign) and feeding the above method a unicode-string seems to throw an error. Is it possible to get non-ASCII characters printed this way? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Tue Jan 5 21:42:44 2010 From: dreadpiratejeff at gmail.com (J) Date: Tue, 5 Jan 2010 15:42:44 -0500 Subject: [python-win32] Still looking for a method to get CPUID info ... Message-ID: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> I've been at this a while :) Thought I'd ask if anyone knew either of a way in python, or just a stand alone tool, to use in Windows to get CPU information. Specifically, I'm looking for Feature sets or Flags. What I'm doing is building a tool for work that gets certain bits of system information to automate test configuration and deployment. So far, I'm using a combination of dmidecode.exe and the Python WMI module to get info from WMI and the BIOS. The problem I'm still stuck with is actually getting the feature sets of a given processor. dmidecode returns a nice list of flags, however, it only seems to support and report the original register (I think it's ECX) and thus, only shows 31 flags. The new feature flags are being dumped, from what I've beed reading, into a different register (I think this one is EDX) and dmidecode (and dmi) can not access that. DMI is dead, in any case, and CIM is the new standard.... The problem is, after pouring through the CIM/WMI stuff over and over, I've found no part of CIM or WMI that reports CPU feature sets. In linux, this is pretty easy... I can just parse /proc/cpuinfo to get every flag, and the new ones show up (assuming I'm running a new enough kernel to handle the new flags). In my case, I'll always be running the newest GA linux distros. BUT, I'll also be using this code on Windows systems running Server 2008 and beyond. So, the problem now is not so much as how do I get the flags, because I can at least get the basic ones, but how to I get ALL the flags. What I'm specifically interested in are flags like VMX and SVN for virtualization extensions, and maybe a couple others that have come with the new generation AMD and Intel processors. Any ideas, outside of what I've already tried (WMI/CIM and dmidecode?) I'm license limited, so any tools I try to include and use have to be GPL. Cheers Jeff, who has a headache right now because of all this. -- Samuel Goldwyn - "I'm willing to admit that I may not always be right, but I am never wrong." - http://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html From timr at probo.com Tue Jan 5 22:53:59 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Jan 2010 13:53:59 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> Message-ID: <4B43B4F7.8070803@probo.com> J wrote: > I've been at this a while :) > > Thought I'd ask if anyone knew either of a way in python, or just a > stand alone tool, to use in Windows to get CPU information. > Specifically, I'm looking for Feature sets or Flags. > > What I'm doing is building a tool for work that gets certain bits of > system information to automate test configuration and deployment. > In my opinion, you could have solved this all much quicker and easier just by writing a trivial DLL. c:\tmp>type cpuid.asm .586 .model flat, stdcall .code GetCpuidEcx proc public xor eax, eax cpuid mov eax, ecx ret GetCpuidEcx endp GetCpuidEdx proc public xor eax, eax cpuid mov eax, edx ret GetCpuidEdx endp start proc public, x:DWORD, y:DWORD, z:DWORD ret start endp end start C:\tmp>ml /Fl /c cpuid.asm Microsoft (R) Macro Assembler Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. Assembling: cpuid.asm C:\tmp>link /dll /out:cpuid.dll /export:GetCpuidEcx /export:GetCpuidEdx /entry:start cpuid.obj Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. Creating library cpuid.lib and object cpuid.exp C:\tmp>python Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] onwin32 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> c = ctypes.windll.cpuid >>> hex(c.GetCpuidEcx()) '0x444d4163' >>> hex(c.GetCpuidEdx()) '0x69746e65' >>> C:\tmp> Modifying this to accept the "cpuid" eax value as a parameter is left as an exercise for the reader. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From dreadpiratejeff at gmail.com Tue Jan 5 23:03:05 2010 From: dreadpiratejeff at gmail.com (J) Date: Tue, 5 Jan 2010 17:03:05 -0500 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <4B43B4F7.8070803@probo.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> Message-ID: <36dec4ff1001051403s28b1590fib76238599d365a61@mail.gmail.com> On Tue, Jan 5, 2010 at 16:53, Tim Roberts wrote: > In my opinion, you could have solved this all much quicker and easier > just by writing a trivial DLL. Indeed... and I may well have tried that, were I actually capable of reading and writing assembly and/or low-level C... Unfortunately, I'm not capable of such things and trivial for you is Magic Blue Smoke to me... I do understand the basics about registers and kinda how things are moved in and out, but when it comes to actual real assembly, or anything more low-level than userspace, I don't know nothin' useful. Just enough to be dangerous. However, that's not meant to be snarky, I'm just honest about my abilities/knowledge. BUT, thanks for this... this seems simple enough that I can dissect it and play with it and actually learn some basic assembly (which I've never done before). > C:\tmp>python > Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit > (Intel)] onwin32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import ctypes > ?>>> c = ctypes.windll.cpuid > ?>>> hex(c.GetCpuidEcx()) > '0x444d4163' > ?>>> hex(c.GetCpuidEdx()) > '0x69746e65' Also have to figure out how to decode the hex value into a more user friendly format ;-) BUT I think there was a white paper or something that I have bookmarked somewhere that does have hex values for the various flags, at least according to the Intel specs, assuming that vendors (in this case IBM) hasn't mucked with them. Seriously though, thanks, even if it turns out I can't really use this for what I'm working on, it certainly does give me something new to play with and learn about. Cheers Jeff -- Joan Crawford - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend." - http://www.brainyquote.com/quotes/authors/j/joan_crawford.html From timr at probo.com Tue Jan 5 23:15:31 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Jan 2010 14:15:31 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <36dec4ff1001051403s28b1590fib76238599d365a61@mail.gmail.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <36dec4ff1001051403s28b1590fib76238599d365a61@mail.gmail.com> Message-ID: <4B43BA03.8070600@probo.com> J wrote: > On Tue, Jan 5, 2010 at 16:53, Tim Roberts wrote: > > >> C:\tmp>python >> Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit >> (Intel)] onwin32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import ctypes >> >>> c = ctypes.windll.cpuid >> >>> hex(c.GetCpuidEcx()) >> '0x444d4163' >> >>> hex(c.GetCpuidEdx()) >> '0x69746e65' >> > > Also have to figure out how to decode the hex value into a more user > friendly format ;-) BUT I think there was a white paper or something > that I have bookmarked somewhere that does have hex values for the > various flags, at least according to the Intel specs, assuming that > vendors (in this case IBM) hasn't mucked with them. > Well, those hex values are actually part of the string "AuthenticAMD" that gets returned in ebx, edx, and ecx in response to the standard "cpuid" (since I'm running an AMD 64X2). That's because I used the "eax=0" variant of cpuid. For the version you want, you'd set eax to 1 before invoking "cpuid", which would return the feature capability bits. Replace the code with this: GetCpuidEcx proc public, style:DWORD mov eax, [style] cpuid mov eax, ecx ret GetCpuidEcx endp GetCpuidEdx proc public, style:DWORD mov eax, [style] cpuid mov eax, edx ret GetCpuidEdx endp Now I can pass the cpuid code as a parameter: C:\tmp>python Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> c = ctypes.windll.cpuid >>> c.GetCpuidEcx(1) 1 >>> hex(c.GetCpuidEdx(1)) '0x178bfbff' >>> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Jan 5 23:40:50 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Jan 2010 14:40:50 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <4B43BA03.8070600@probo.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <36dec4ff1001051403s28b1590fib76238599d365a61@mail.gmail.com> <4B43BA03.8070600@probo.com> Message-ID: <4B43BFF2.7040105@probo.com> Tim Roberts wrote: > J wrote: > >> On Tue, Jan 5, 2010 at 16:53, Tim Roberts wrote: >> >> >> >>> C:\tmp>python >>> Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit >>> (Intel)] onwin32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> import ctypes >>> >>> c = ctypes.windll.cpuid >>> >>> hex(c.GetCpuidEcx()) >>> '0x444d4163' >>> >>> hex(c.GetCpuidEdx()) >>> '0x69746e65' >>> >>> >> Also have to figure out how to decode the hex value into a more user >> friendly format ;-) OK, so I was being overly clever, showing off a bit, demonstrating that it's possible to build a minimal DLL in assembler. It turns out you can do the same thing in Visual C++: c:\tmp>type cpuid.c #include int GetCpuidEcx( int var ) { int parts[4]; __cpuid( parts, var ); return parts[2]; } int GetCpuidEdx( int var ) { int parts[4]; __cpuid( parts, var ); return parts[3]; } C:\tmp>cl /LD cpuid.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. cpuid.c Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. /out:cpuid.dll /dll /implib:cpuid.lib cpuid.obj Creating library cpuid.lib and object cpuid.exp C:\tmp>python Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> c = ctypes.cdll.cpuid >>> c.GetCpuidEcx(1) 1 >>> hex(c.GetCpuidEdx(1)) '0x178bfbff' >>> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Wed Jan 6 00:46:34 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 05 Jan 2010 15:46:34 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <4B43BFF2.7040105@probo.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <36dec4ff1001051403s28b1590fib76238599d365a61@mail.gmail.com> <4B43BA03.8070600@probo.com> <4B43BFF2.7040105@probo.com> Message-ID: <4B43CF5A.20504@probo.com> Tim Roberts wrote: > Tim Roberts wrote: > >> J wrote: >> >> >>> On Tue, Jan 5, 2010 at 16:53, Tim Roberts wrote: >>> >>> >>> >>> >>>> C:\tmp>python >>>> Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit >>>> (Intel)] onwin32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>> import ctypes >>>> >>> c = ctypes.windll.cpuid >>>> >>> hex(c.GetCpuidEcx()) >>>> '0x444d4163' >>>> >>> hex(c.GetCpuidEdx()) >>>> '0x69746e65' >>>> >>>> >>>> >>> Also have to figure out how to decode the hex value into a more user >>> friendly format ;-) >>> > > OK, so I was being overly clever, showing off a bit, demonstrating that > it's possible to build a minimal DLL in assembler. It turns out you can > do the same thing in Visual C++: > > c:\tmp>type cpuid.c > #include > > int > GetCpuidEcx( int var ) > { > int parts[4]; > __cpuid( parts, var ); > return parts[2]; > } > > int > GetCpuidEdx( int var ) > { > int parts[4]; > __cpuid( parts, var ); > return parts[3]; > } > Well, almost. Replace both of the "int" lines with this: int __declspec(dllexport) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Wed Jan 6 09:58:30 2010 From: rwupole at msn.com (Roger Upole) Date: Wed, 6 Jan 2010 03:58:30 -0500 Subject: [python-win32] Boolean type changed in Python 3.0? Message-ID: >From looking at the source of PyCom_VariantFromPyObject in oleargs.cpp, the check for a boolean is done after the check for an int. PyLong_Check is used to determine if the object should be converted to one of the variant integer types. Apparently in Python 3.x, this now returns True for a boolean whereas it doesn't in 2.x. We should be able to just move the boolean check above the int check without breaking anything in 2.x. Roger From gklein at xs4all.nl Wed Jan 6 12:33:32 2010 From: gklein at xs4all.nl (Gertjan Klein) Date: Wed, 06 Jan 2010 12:33:32 +0100 Subject: [python-win32] Still looking for a method to get CPUID info ... References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> Message-ID: Tim Roberts wrote: >In my opinion, you could have solved this all much quicker and easier >just by writing a trivial DLL. Out of pure curiousity (I used to write a lot of assembler, but those days are long gone) I tried your code, and it works as advertised -- on Python 2.6. It fails on Python 2.5 with "WindowsError: exception code 0x20800", but oddly I've also seen error code 0x1020800. I couldn't find much about either of these errors on the Internet. Any idea what could be wrong? I know Python 2.5 and 2.6 use different C runtimes, but the created DLL is completely independent. Gertjan. From timr at probo.com Wed Jan 6 19:32:06 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 06 Jan 2010 10:32:06 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> Message-ID: <4B44D726.6010101@probo.com> Gertjan Klein wrote: > Out of pure curiousity (I used to write a lot of assembler, but those > days are long gone) I tried your code, and it works as advertised -- on > Python 2.6. It fails on Python 2.5 with "WindowsError: exception code > 0x20800", but oddly I've also seen error code 0x1020800. I couldn't find > much about either of these errors on the Internet. Any idea what could > be wrong? I know Python 2.5 and 2.6 use different C runtimes, but the > created DLL is completely independent. > Very interesting. I tried this on Python 2.5.2 on my Windows 7 64 system (using 32-bit Python). The C version works fine, but the assembler version gets a "DLL initialization error". I fixed that by adding "mov eax, 1" to the "start" routine. See if that helps your issue. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From l at urent.org Wed Jan 6 20:15:39 2010 From: l at urent.org (lduchesne) Date: Wed, 6 Jan 2010 11:15:39 -0800 (PST) Subject: [python-win32] mapi.ATTACH_EMBEDDED_MSG Message-ID: <27026941.post@talk.nabble.com> Hi, I'm tying to embed a mail message in another mail using the following code: [...] imsg = draftFolder.CreateMessage(None, 0) message = outboxFolder.CreateMessage(None, 0) attach = message.CreateAttach(None, 0) attach[1].SetProps([(mapitags.PR_ATTACH_METHOD, mapi.ATTACH_EMBEDDED_MSG), (mapitags.PR_ATTACH_DATA_OBJ, imsg), (mapitags.PR_DISPLAY_NAME, filename), (mapitags.PR_ATTACH_LONG_FILENAME, filename)]) [...] The problem is, I always get a: "TypeError: Unsupported MAPI property type 0xD" when trying to set the PR_ATTACH_DATA_OBJ property. I tried various ways of creating a new IMessage to embed (the one above and using CDO) but it seems the property cannot be set. Using CDO all the way is not an option.. so has anybody succedded in embeding a message using the extended MAPI interface? Note that the embedded message will be created from a message/rfc822 source. Thanks, Laurent -- View this message in context: http://old.nabble.com/mapi.ATTACH_EMBEDDED_MSG-tp27026941p27026941.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From keating at acm.org Wed Jan 6 20:39:36 2010 From: keating at acm.org (Paul Keating) Date: Wed, 06 Jan 2010 20:39:36 +0100 Subject: [python-win32] HKLM\Software\Python\PythonCore\2.6\PythonPath - does it serve any purpose? Message-ID: <024601ca8f08$ca833ff0$4801a8c0@vuurpijlhuisje.local> What is the registry key HKLM\Software\Python\PythonCore\2.6\PythonPath for? The docs (http://www.python.org/doc/2.6/using/windows.html) say Modifying the module search path can also be done through the Windows registry: Edit HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath but this doesn't work. Judging by what I see in the registries of old servers at my site, I think it must have worked in Python 1.5, but it doesn't now, as the following shows: Export the value of the key: C:\>regedit /E xxx HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\PythonPath Display it: C:\>type xxx ... @="F:\\Development\\Python26\\Lib;F:\\Development\\Python26\\DLLs;F:\\Developmen t\\Python26\\Lib\\lib-tk;F:\\Development\\Python26\\Lib\\site-packages\\win32;F: \\Development\\Python26\\Lib\\site-packages\\pythonwin;c:\\temp" Note the temporary addition of c:\temp to the end of the path. Now ask Python what it thinks: C:\>python Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', 'C:\\WINNT\\system32\\python26.zip', 'F:\\Development\\Python26\\DLLs', 'F: \\Development\\Python26\\lib', 'F:\\Development\\Python26\\lib\\plat-win', 'F:\\ Development\\Python26\\lib\\lib-tk', 'F:\\Development\\Python26', 'F:\\Developme nt\\Python26\\lib\\site-packages', 'F:\\Development\\Python26\\lib\\site-package s\\win32', 'F:\\Development\\Python26\\lib\\site-packages\\win32\\lib', 'F:\\Dev elopment\\Python26\\lib\\site-packages\\Pythonwin'] >>> Not only is c:\temp not in sys.path, even the folders that it has in common with the registry entry are in a different order (eg DLLs and lib), so it's hard to believe that the registry entry has any influence at all on sys.path. Also sys.path has lib\plat-win which I think was introduced about Python 1.5 and I think disappeared again about Python 2.0. So, why is that registry key there at all? And why does sys.path have the nonexistent plat-win in it, even in Python 3.0? Is it just historical baggage? I would like to see the registry key once again working as advertised. I know I can set the pythonpath environment variable, and I also know that environment variables just live in another registry key, but changing that key strikes me as inelegant. Python stuff should live in Software\Python, not in System\CurrentControlSet. If the registry key turned out to be a bad idea, it would be illuminating to know why. -- Paul Keating The Hague -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Wed Jan 6 22:06:51 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 6 Jan 2010 16:06:51 -0500 Subject: [python-win32] HKLM\Software\Python\PythonCore\2.6\PythonPath - does it serve any purpose? In-Reply-To: <024601ca8f08$ca833ff0$4801a8c0@vuurpijlhuisje.local> References: <024601ca8f08$ca833ff0$4801a8c0@vuurpijlhuisje.local> Message-ID: <4eb0089f1001061306p2a5d2836o6a64c021c2a3aa7e@mail.gmail.com> On Wed, Jan 6, 2010 at 2:39 PM, Paul Keating wrote: > What is the registry key HKLM\Software\Python\PythonCore\2.6\PythonPath for? > The docs (http://www.python.org/doc/2.6/using/windows.html) say > > Modifying the module search path can also be done through the Windows > registry: Edit > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath > > but this doesn't work. ... > So, why is that registry key?there at all? And why?does sys.path?have?the > nonexistent?plat-win in it, even in Python 3.0? Is?it just historical > baggage? > > I would like to see?the registry key once again working as advertised. I > know I can?set the pythonpath environment variable, and I also know that > environment variables just live in another registry key, but changing that > key strikes me as inelegant. Python stuff should live in Software\Python, > not in System\CurrentControlSet. > > If the registry key?turned out to be a bad idea, it would be illuminating to > know why. > -- > Paul Keating > The Hague This is really the wrong list. The developers hang out at the python-dev list. (They'll probably tell you to file a bug report!) From drobinow at gmail.com Thu Jan 7 00:17:31 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 6 Jan 2010 18:17:31 -0500 Subject: [python-win32] HKLM\Software\Python\PythonCore\2.6\PythonPath - does it serve any purpose? In-Reply-To: <024601ca8f08$ca833ff0$4801a8c0@vuurpijlhuisje.local> References: <024601ca8f08$ca833ff0$4801a8c0@vuurpijlhuisje.local> Message-ID: <4eb0089f1001061517n2e1db95che954f66e404a82f9@mail.gmail.com> On Wed, Jan 6, 2010 at 2:39 PM, Paul Keating wrote: > What is the registry key HKLM\Software\Python\PythonCore\2.6\PythonPath for? > The docs (http://www.python.org/doc/2.6/using/windows.html) say > > Modifying the module search path can also be done through the Windows > registry: Edit > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath > > > but this doesn't work. ... > Well, a little more research shows that we both have been editing the wrong thing. See: http://yuji.wordpress.com/2009/08/31/python-on-windows-setting-pythonpath-environment-variable/ for a description of the correct technique. It works for me. This is definitely a documentation bug. I don't see how anybody could be expected to figure this out from the current docs. From skippy.hammond at gmail.com Thu Jan 7 05:52:05 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 07 Jan 2010 15:52:05 +1100 Subject: [python-win32] mapi.ATTACH_EMBEDDED_MSG In-Reply-To: <27026941.post@talk.nabble.com> References: <27026941.post@talk.nabble.com> Message-ID: <4B456875.7050809@gmail.com> On 7/01/2010 6:15 AM, lduchesne wrote: > > Hi, > > I'm tying to embed a mail message in another mail using the following code: > > [...] > imsg = draftFolder.CreateMessage(None, 0) > message = outboxFolder.CreateMessage(None, 0) > attach = message.CreateAttach(None, 0) > > attach[1].SetProps([(mapitags.PR_ATTACH_METHOD, mapi.ATTACH_EMBEDDED_MSG), > (mapitags.PR_ATTACH_DATA_OBJ, imsg), > (mapitags.PR_DISPLAY_NAME, filename), > (mapitags.PR_ATTACH_LONG_FILENAME, filename)]) You will need something like: attachMsg = imsg.OpenProperty(mapitags.PR_ATTACH_DATA_OBJ, mapi.IID_IMessage, 0, mapi.MAPI_CREATE) After which you have an IMessage for the new item. You can then probably use the CopyTo() method to copy from the source to the new one. HTH, Mark From santosh.mce at gmail.com Thu Jan 7 06:40:51 2010 From: santosh.mce at gmail.com (Santosh Mohan) Date: Thu, 7 Jan 2010 11:10:51 +0530 Subject: [python-win32] Porting code from Python 2.x code to Python 3.x In-Reply-To: <427239421001062137s43a677f3oeff48ec6e03d0cec@mail.gmail.com> References: <427239421001062137s43a677f3oeff48ec6e03d0cec@mail.gmail.com> Message-ID: <427239421001062140g19ad45c6hef94c01820c73157@mail.gmail.com> HI, I installed new version of Python 3.1. I tried to run my older programs, but I couldn't run. I had used "print" statements, in Newer version print statement syntax is changed. Python2.x >>>x=20 >>>print x >>> 20 Python 3.x >>>x=20 >>> print x File "", line 1 print x ^ SyntaxError: invalid syntax >>>print(x) >>>20 Is there any utility for running the older version programs? Regards, Santosh M -------------- next part -------------- An HTML attachment was scrubbed... URL: From mvilas at gmail.com Thu Jan 7 07:01:33 2010 From: mvilas at gmail.com (Mario Alejandro Vilas Jerez) Date: Thu, 7 Jan 2010 03:01:33 -0300 Subject: [python-win32] Porting code from Python 2.x code to Python 3.x In-Reply-To: <427239421001062140g19ad45c6hef94c01820c73157@mail.gmail.com> References: <427239421001062137s43a677f3oeff48ec6e03d0cec@mail.gmail.com> <427239421001062140g19ad45c6hef94c01820c73157@mail.gmail.com> Message-ID: <3fbf862f1001062201r6fa57c87h69b5e5c8265f857e@mail.gmail.com> Try this script, it comes with your Python 3 installation: http://docs.python.org/library/2to3.html You may have to review the source code manually in non trivial cases, though. Regards, -Mario On Thu, Jan 7, 2010 at 2:40 AM, Santosh Mohan wrote: > HI, > > I installed new version of Python 3.1. I tried to run my older programs, > but I couldn't run. > > I had used "print" statements, in Newer version print statement syntax is > changed. > > Python2.x > >>>x=20 > >>>print x > >>> 20 > > Python 3.x > >>>x=20 > >>> print x > File "", line 1 > print x > ^ > SyntaxError: invalid syntax > >>>print(x) > >>>20 > > Is there any utility for running the older version programs? > > > Regards, > Santosh M > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -- HONEY: I want to? put some powder on my nose. GEORGE: Martha, won?t you show her where we keep the euphemism? -------------- next part -------------- An HTML attachment was scrubbed... URL: From gklein at xs4all.nl Thu Jan 7 11:26:34 2010 From: gklein at xs4all.nl (Gertjan Klein) Date: Thu, 07 Jan 2010 11:26:34 +0100 Subject: [python-win32] Still looking for a method to get CPUID info ... References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <4B44D726.6010101@probo.com> Message-ID: <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> Tim Roberts wrote: >Very interesting. I tried this on Python 2.5.2 on my Windows 7 64 >system (using 32-bit Python). The C version works fine, but the >assembler version gets a "DLL initialization error". I fixed that by >adding "mov eax, 1" to the "start" routine. See if that helps your issue. It doesn't, I get the same error (either 0x1020800 or 0x20800, the former the most often, which makes me wonder if the error contains bit flags). Interestingly, if I place a ret after the mov eax, [style] instruction, or even comment out the cpuid instruction, I don't get an exception. This makes me wonder whether there is something permission-related that is different between Python 2.5 and 2.6 -- perhaps the 2.5 executable is not allowed to execute that instruction? Gertjan. From timr at probo.com Thu Jan 7 18:36:09 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 07 Jan 2010 09:36:09 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <4B44D726.6010101@probo.com> <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> Message-ID: <4B461B89.7040009@probo.com> Gertjan Klein wrote: > Interestingly, if I place a ret after the mov eax, [style] instruction, > or even comment out the cpuid instruction, I don't get an exception. > This makes me wonder whether there is something permission-related that > is different between Python 2.5 and 2.6 -- perhaps the 2.5 executable is > not allowed to execute that instruction? > No, that doesn't make sense. I don't think CPUID is a privileged instruction. Even if it were, that's talking about CPU privileges, which do not vary from process to process. However, I'll bet I know what it is. CPUID trashes ebx, and in the x86 calling sequence, that's supposed to be saved and restored. One of the sets of code is probably storing an error code in ebx and assuming that it survives the CPU cal. Try changing the two function headers to this: GetCpuidEcx proc public uses ebx, style:DWORD ... GetCpuidEdx proc public uses ebx, style:DWORD -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gareth at maptel.com.au Fri Jan 8 04:25:15 2010 From: gareth at maptel.com.au (Gareth Walters) Date: Fri, 8 Jan 2010 14:25:15 +1100 Subject: [python-win32] 'No such interface supported' question Message-ID: <8EC4F97637845642809C79C97C0F5440757079B1D9@MAILMAN.maptel.local> Hi Nick, I have done some python work before but I new to the COM stuff. I am trying to Create a MXD and layers to it from python. I have been looking at this PythonNet stuff and it is all getting a bit blurry. I was wondering if you could give me some pointers to basically get python recognizing the ArcMap class or do you have any code that would help me get to that point? Look forward to hearing from you. Cheers, Gareth -------------- next part -------------- An HTML attachment was scrubbed... URL: From gklein at xs4all.nl Fri Jan 8 07:02:53 2010 From: gklein at xs4all.nl (Gertjan Klein) Date: Fri, 08 Jan 2010 07:02:53 +0100 Subject: [python-win32] Still looking for a method to get CPUID info ... References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <4B44D726.6010101@probo.com> <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> <4B461B89.7040009@probo.com> Message-ID: <7phdk5thgprdh9naaul3dodfq5l924athf@4ax.com> Tim Roberts wrote: >However, I'll bet I know what it is. CPUID trashes ebx, and in the x86 >calling sequence, that's supposed to be saved and restored. That's it! Now, both Python 2.5 and 2.6 (and 3.1, if I change the print statement) run this code successfully. Does that mean there is a difference in calling sequence between Python 2.5 and 2.6? Or do they have different expectations of which registers are left untouched? Thanks for sticking with this. I often save little bits of code from this newsgroup that I might want to use later, and now I have a little project that shows me how to create a DLL from assembly code and call it from Python. Gertjan. From davea at ieee.org Fri Jan 8 15:29:46 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 08 Jan 2010 09:29:46 -0500 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <7phdk5thgprdh9naaul3dodfq5l924athf@4ax.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <4B44D726.6010101@probo.com> <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> <4B461B89.7040009@probo.com> <7phdk5thgprdh9naaul3dodfq5l924athf@4ax.com> Message-ID: <4B47415A.9020309@ieee.org> Gertjan Klein wrote: > Tim Roberts wrote: > > >> However, I'll bet I know what it is. CPUID trashes ebx, and in the x86 >> calling sequence, that's supposed to be saved and restored. >> > > That's it! Now, both Python 2.5 and 2.6 (and 3.1, if I change the print > statement) run this code successfully. Does that mean there is a > difference in calling sequence between Python 2.5 and 2.6? Or do they > have different expectations of which registers are left untouched? > > Thanks for sticking with this. I often save little bits of code from > this newsgroup that I might want to use later, and now I have a little > project that shows me how to create a DLL from assembly code and call it > from Python. > > Gertjan. > > > On general principle, I'd use push ebx ... pop ebx pairs around the cpuid instruction, if trashing ebx is a problem. Seems to me it's safer than making any assumptions about implicit saves/restores. I haven't looked at the cpuid instruction for years, but I'd push/pop any register (other than EAX) it modifies, and in between them do the cpuid and an appropriate move of whichever register. DaveA From mail at timgolden.me.uk Fri Jan 8 18:30:02 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 08 Jan 2010 17:30:02 +0000 Subject: [python-win32] Question concerning wmi c.CIM_DataFile In-Reply-To: <4B425B33.2060003@co.marshall.ia.us> References: <2E8EE617FF5865459F6EF9217BC466E2063E3C@opr-pr-exc-01.rgfc.main> <4B423A29.9050305@probo.com> <4B425B33.2060003@co.marshall.ia.us> Message-ID: <4B476B9A.4080009@timgolden.me.uk> On 04/01/2010 21:18, Mike Driscoll wrote: > The OP should check out Tim Golden's winshell module as it gives access > to the common folders quite easily: > > http://timgolden.me.uk/python/winshell.html Thanks for the plug, Mike. Problem is that the OP is after running this code on multiple machines (ie remotely) so the winshell approach won't work. TJG From mail at timgolden.me.uk Fri Jan 8 18:37:04 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 08 Jan 2010 17:37:04 +0000 Subject: [python-win32] Exception: object has no attribute 'Win32_Process' In-Reply-To: References: Message-ID: <4B476D40.8030805@timgolden.me.uk> On 04/01/2010 17:06, Wade Dyck wrote: [...] > At this point I want to use Win32_Process.create() to xcopy some files from > a third server, so I switch to delegation since impersonate won't allow > access to network resources: > > remote = wmi.connect_server(server=self.server, user=r"%s\%s" > % (self.domain, self.user), password=self.password, > impersonation_level="delegate") > self.c = wmi.WMI(wmi=remote) > > But then when I try to create the process using: > > pid, res = self.c.Win32_Process.Create('cmd.exe /c xcopy %s %s \ > /s /e /i /y /c /q' % (src, dest)) As a tiny aside here, I suspect that: (a) you don't need the cmd.exe to run xcopy: it's actually an executable; and (b) you might to double-quote the %s params to xcopy. Neither of these things are going to be causing the error you report, but just to be helpful... > > I get the following exception: > > AttributeError: ' Library.ISWbemSer > vices instance at 0x12790040>' object has no attribute 'Win32_Process' > > However, this works fine if I don't set the userAccountControl attribute > above using adsi. It also seems specific to actually setting the attribute, > as the code is always using adsi to get DNs and the current value of > userAccountControl. It is peculiar, assuming you are running exactly the same code, only with AD setting switched as you describe. ie there's no possibility that self.c has become something other than a WMI instance? I'll try to look it at it when I get back to work (which won't be till Monday now; I'm just back from a week away). If you manage to fix it in the meantime, please do post back. TJG From timr at probo.com Fri Jan 8 19:04:36 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 08 Jan 2010 10:04:36 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <4B47415A.9020309@ieee.org> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <4B44D726.6010101@probo.com> <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> <4B461B89.7040009@probo.com> <7phdk5thgprdh9naaul3dodfq5l924athf@4ax.com> <4B47415A.9020309@ieee.org> Message-ID: <4B4773B4.2030006@probo.com> Dave Angel wrote: >> > On general principle, I'd use > push ebx > ... > pop ebx > > pairs around the cpuid instruction, if trashing ebx is a problem. > Seems to me it's safer than making any assumptions about implicit > saves/restores. That's what the "uses ebx" clause that I added to the "proc" statement does. It pushes ebx on entry, and pops it at every "ret". The advantage of that is that I don't have to worry about saving it repeatedly throughout the function. I'm free to do whatever I want to ebx internally. > I haven't looked at the cpuid instruction for years, but I'd push/pop > any register (other than EAX) it modifies, and in between them do the > cpuid and an appropriate move of whichever register. Well, cpuid is kind of an odd exception, because it modifies all of the general purpose registers (eax, ebx, ecx, edx) in one fell swoop. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Jan 8 19:04:39 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 08 Jan 2010 10:04:39 -0800 Subject: [python-win32] Still looking for a method to get CPUID info ... In-Reply-To: <7phdk5thgprdh9naaul3dodfq5l924athf@4ax.com> References: <36dec4ff1001051242q2ae88c0cx332ced7065b12121@mail.gmail.com> <4B43B4F7.8070803@probo.com> <4B44D726.6010101@probo.com> <6qcbk59t7irtkkee0dul389qjrvgrko231@4ax.com> <4B461B89.7040009@probo.com> <7phdk5thgprdh9naaul3dodfq5l924athf@4ax.com> Message-ID: <4B4773B7.9060206@probo.com> Gertjan Klein wrote: > Tim Roberts wrote >> However, I'll bet I know what it is. CPUID trashes ebx, and in the x86 >> calling sequence, that's supposed to be saved and restored. >> > > That's it! Now, both Python 2.5 and 2.6 (and 3.1, if I change the print > statement) run this code successfully. Does that mean there is a > difference in calling sequence between Python 2.5 and 2.6? Or do they > have different expectations of which registers are left untouched? > This could be something as obscure as different compilers, or even different optimization settings. The generated code in 2.5 happened to store something in ebx and expected it to survive across the API call (a reasonable expectation!). The generated code in 2.6 did not. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Jan 8 19:13:11 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 08 Jan 2010 10:13:11 -0800 Subject: [python-win32] 'No such interface supported' question In-Reply-To: <8EC4F97637845642809C79C97C0F5440757079B1D9@MAILMAN.maptel.local> References: <8EC4F97637845642809C79C97C0F5440757079B1D9@MAILMAN.maptel.local> Message-ID: <4B4775B7.8030206@probo.com> Gareth Walters wrote: > > Hi Nick, > > > > I have done some python work before but I new to the COM stuff. I am > trying to Create a MXD and layers to it from python. I have been > looking at this PythonNet stuff and it is all getting a bit blurry. > > > > I was wondering if you could give me some pointers to basically get > python recognizing the ArcMap class or do you have any code that would > help me get to that point? > There are a number of web resources for this. Google for "arcmap python" and you should find some good hints. It looks like there are even some Python modules available for this, although I don't know if they apply to your particular case. If you do need to use COM, you'll need to know the name of the COM class object to create. You would then do something like: arc = win32com.client.Dispatch("ArcMap.Application") Then you can use methods on the "arc" object. Note that I'm just making up that name -- I don't know what the class really is. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From l at urent.org Mon Jan 11 13:50:00 2010 From: l at urent.org (Laurent Duchesne) Date: Mon, 11 Jan 2010 07:50:00 -0500 Subject: [python-win32] =?utf-8?q?mapi=2EATTACH=5FEMBEDDED=5FMSG?= In-Reply-To: <4B456875.7050809@gmail.com> References: <27026941.post@talk.nabble.com> <4B456875.7050809@gmail.com> Message-ID: Thanks, it's working now :) In case someone wants to know, I will be converting my .eml source file to a message object using this call: IConverterSession::MIMEToMAPI (outlook 2003+) http://msdn.microsoft.com/en-us/library/aa193062(office.11).aspx Since not all calls are available using python, I will use a C++ wrapper which looks something like this: std::wstring ConvertMIMEToMAPI(const std::wstring& p_rSourceFilename); Where the return value is a filename containing a compoung object (CLSID_MailMessage) which I hope I will be able to read back in python. Laurent On Thu, 07 Jan 2010 15:52:05 +1100, Mark Hammond wrote: > On 7/01/2010 6:15 AM, lduchesne wrote: >> >> Hi, >> >> I'm tying to embed a mail message in another mail using the following >> code: >> >> [...] >> imsg = draftFolder.CreateMessage(None, 0) >> message = outboxFolder.CreateMessage(None, 0) >> attach = message.CreateAttach(None, 0) >> >> attach[1].SetProps([(mapitags.PR_ATTACH_METHOD, >> mapi.ATTACH_EMBEDDED_MSG), >> (mapitags.PR_ATTACH_DATA_OBJ, imsg), >> (mapitags.PR_DISPLAY_NAME, filename), >> (mapitags.PR_ATTACH_LONG_FILENAME, filename)]) > > You will need something like: > > attachMsg = imsg.OpenProperty(mapitags.PR_ATTACH_DATA_OBJ, > mapi.IID_IMessage, 0, mapi.MAPI_CREATE) > > After which you have an IMessage for the new item. You can then > probably use the CopyTo() method to copy from the source to the new one. > > HTH, > > Mark From mdriscoll at co.marshall.ia.us Mon Jan 11 15:57:28 2010 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 11 Jan 2010 08:57:28 -0600 Subject: [python-win32] Question concerning wmi c.CIM_DataFile In-Reply-To: <4B476B9A.4080009@timgolden.me.uk> References: <2E8EE617FF5865459F6EF9217BC466E2063E3C@opr-pr-exc-01.rgfc.main> <4B423A29.9050305@probo.com> <4B425B33.2060003@co.marshall.ia.us> <4B476B9A.4080009@timgolden.me.uk> Message-ID: <4B4B3C58.4050403@co.marshall.ia.us> On 1:59 PM, Tim Golden wrote: > On 04/01/2010 21:18, Mike Driscoll wrote: >> The OP should check out Tim Golden's winshell module as it gives access >> to the common folders quite easily: >> >> http://timgolden.me.uk/python/winshell.html > > Thanks for the plug, Mike. Problem is that the > OP is after running this code on multiple machines (ie > remotely) so the winshell approach won't work. > > TJG > I must have read the question wrong then. At my workplace, we use the winshell module in our login scripts, so it works fine on "remote" machines. Alas, I didn't realize he was wanting to do it from his own machine or I wouldn't have said that. Anyway, thanks for the handy module. I use it a quite a bit for various manipulations of files on user accounts. - Mike From ross at biostat.ucsf.edu Tue Jan 12 01:35:35 2010 From: ross at biostat.ucsf.edu (Ross Boylan) Date: Mon, 11 Jan 2010 16:35:35 -0800 Subject: [python-win32] Guaranteed cleanup code execution? Message-ID: <1263256535.15072.119.camel@corn.betterworld.us> Is there a way to ensure that some cleanup code will get run whenever my process terminates? I've tried signal and try:finally:, while noting that, e.g., atexit says it doesn't handle interrupts. I can catch many circumstances, but if I kill the process from task manager my cleanup doesn't happen (at least, print "I'm cleaning up" doesn't come out). I don't see anything in win32api that looks appropriate, and I don't know if Windows provides any sure way to do what I want. There is a call to handle some very abnormal exits, but they are sufficiently bad that, like SIGSEGV, I don't want to run the cleanup code (even if I can). The process will eventually run as a service. I assume there is some protocol for managing normal service control manager requests to start and stop. Thanks for any pointers. Ross Boylan From mvilas at gmail.com Tue Jan 12 03:33:23 2010 From: mvilas at gmail.com (Mario Alejandro Vilas Jerez) Date: Mon, 11 Jan 2010 23:33:23 -0300 Subject: [python-win32] Guaranteed cleanup code execution? In-Reply-To: <1263256535.15072.119.camel@corn.betterworld.us> References: <1263256535.15072.119.camel@corn.betterworld.us> Message-ID: <3fbf862f1001111833s2030b7beuf3fca2cf5c41f902@mail.gmail.com> If your process is being terminated forcefully (like from the task manager) then you probably don't want to run any cleanup code. If you really must you could code something in C, put it in a DLL library and have it executed in DllMain when the library is unloaded. (And I think you'll still have problems if someone with enough privileges calls TerminateProcess on your process). But what I think you're really looking for is the Service Control Manager: http://msdn.microsoft.com/en-us/library/ms685150(VS.85).aspx The ControlService API lets you stop services (among other things): http://msdn.microsoft.com/en-us/library/ms682108(VS.85).aspx And the StartService API lets you start a service manually: http://msdn.microsoft.com/en-us/library/ms686321(VS.85).aspx Hope this helps! :) -Mario On Mon, Jan 11, 2010 at 9:35 PM, Ross Boylan wrote: > Is there a way to ensure that some cleanup code will get run whenever my > process terminates? > > I've tried signal and try:finally:, while noting that, e.g., atexit says > it doesn't handle interrupts. I can catch many circumstances, but if I > kill the process from task manager my cleanup doesn't happen (at least, > print "I'm cleaning up" doesn't come out). > > I don't see anything in win32api that looks appropriate, and I don't > know if Windows provides any sure way to do what I want. There is a > call to handle some very abnormal exits, but they are sufficiently bad > that, like SIGSEGV, I don't want to run the cleanup code (even if I > can). > > The process will eventually run as a service. I assume there is some > protocol for managing normal service control manager requests to start > and stop. > > Thanks for any pointers. > Ross Boylan > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- HONEY: I want to? put some powder on my nose. GEORGE: Martha, won?t you show her where we keep the euphemism? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ah.kode at gmail.com Tue Jan 12 13:03:07 2010 From: ah.kode at gmail.com (a h) Date: Tue, 12 Jan 2010 17:33:07 +0530 Subject: [python-win32] passing c structure into python function Message-ID: Hi I have witten C code which call a function defined in python, passing an structure, but couldn't know how to pass c structure into a python function(data conversion) and how to write python script function which takes an c structure and fill value into it (commented portion) I have looked at struct module but couldn't understand that how it works for below. typedef struct employee { char emp_name[10]; int emp_ID; }emp; int main() { emp e = {0}; Pyobject *pName, *pModule, *pFunc, *pArgs,*pValue; Py_Initialize(); pName = PyString_FromString("test"); pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, "testStruct"); if(pFunc && PyCallable_Check(pFunc)) { pArgs = e //******************logic to assign struct employee into pArgs pValue = PyObject_CallObject(pFunc, pArgs); } } Py_DECREF(pValue); Py_DECREF(pModule); Py_Finalize(); return 0; } and now python script test.py def testStruct(): # **** need any parameter will be specify #**** assign value into the cStructure f=open(filename) f.write(cStructure.Value) # **** value to write in file Thanks in advance regards ah -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Jan 12 18:19:24 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 12 Jan 2010 09:19:24 -0800 Subject: [python-win32] passing c structure into python function In-Reply-To: References: Message-ID: <4B4CAF1C.8050304@probo.com> a h wrote: > > I have witten C code which call a function defined in python, passing > an structure, but couldn't know how to pass c structure into a python > function(data conversion) and how to write python script > function which takes an c structure and fill value into it (commented > portion) > > I have looked at struct module but couldn't understand that how it > works for below. > > typedef struct employee > { > char emp_name[10]; > int emp_ID; > }emp; I would pass the struct as a string of 14 bytes, then use emp_name, emp_ID = struct.unpack( '=10cI', incoming ) class employee: def __init__( self, name, id ): self.name = name self.id = id def to_file( self, f ): f.write( struct,pack( '=10cI', self.name, self.id ) def from_string( self, s ): self.name, self.id = struct.unpack( '=10cI', s ) f = open( 'testing', 'w' ) e = employee( 'Testing', 923 ) e.to_file( f ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From aahz at pythoncraft.com Tue Jan 12 20:41:34 2010 From: aahz at pythoncraft.com (Aahz) Date: Tue, 12 Jan 2010 11:41:34 -0800 Subject: [python-win32] passing c structure into python function In-Reply-To: <4B4CAF1C.8050304@probo.com> References: <4B4CAF1C.8050304@probo.com> Message-ID: <20100112194134.GA27959@panix.com> On Tue, Jan 12, 2010, Tim Roberts wrote: > > I would pass the struct as a string of 14 bytes, then use > emp_name, emp_ID = struct.unpack( '=10cI', incoming ) > > class employee: > def __init__( self, name, id ): > self.name = name > self.id = id > def to_file( self, f ): > f.write( struct,pack( '=10cI', self.name, self.id ) > def from_string( self, s ): > self.name, self.id = struct.unpack( '=10cI', s ) Why are you using the asymmetric "to_file" and "from_string" methods? Just for examples? BTW, I think that in example code it's a Good Idea to follow PEP8... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From timr at probo.com Tue Jan 12 23:07:32 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 12 Jan 2010 14:07:32 -0800 Subject: [python-win32] passing c structure into python function In-Reply-To: <20100112194134.GA27959@panix.com> References: <4B4CAF1C.8050304@probo.com> <20100112194134.GA27959@panix.com> Message-ID: <4B4CF2A4.4000504@probo.com> Aahz wrote: > On Tue, Jan 12, 2010, Tim Roberts wrote: > >> I would pass the struct as a string of 14 bytes, then use >> emp_name, emp_ID = struct.unpack( '=10cI', incoming ) >> >> class employee: >> def __init__( self, name, id ): >> self.name = name >> self.id = id >> def to_file( self, f ): >> f.write( struct,pack( '=10cI', self.name, self.id ) >> def from_string( self, s ): >> self.name, self.id = struct.unpack( '=10cI', s ) >> > > Why are you using the asymmetric "to_file" and "from_string" methods? > Just for examples? > Yes. That nagged me when I wrote it, and I decided to leave it as an exercise for the reader... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ah.kode at gmail.com Wed Jan 13 15:31:43 2010 From: ah.kode at gmail.com (a h) Date: Wed, 13 Jan 2010 20:01:43 +0530 Subject: [python-win32] passing c structure into python function In-Reply-To: References: Message-ID: Hi thanks for your response in the last piece of c code i want to know how do i pass structure into python function in c. I have tried to call a python function which takes string as parameter. i have passed string parameter as : const char *str_pArgs = "hello"; pArgs = PyTuple_New(1); pValue = PyString_FromString(str_pArgs); PyTuple_SetItem(pArgs, 0,pValue); pValue = PyObject_CallObject(pFunc, pArgs); similarly how do i convert this structure for python function argument. ->pArgs = e //******************logic to assign struct employee into pArgs regards ah On Tue, Jan 12, 2010 at 5:33 PM, a h wrote: > Hi > I have witten C code which call a function defined in python, passing an > structure, but couldn't know how to pass c structure into a python > function(data conversion) and how to write python script function which > takes an c structure and fill value into it (commented portion) > > I have looked at struct module but couldn't understand that how it works > for below. > > typedef struct employee > { > char emp_name[10]; > int emp_ID; > }emp; > > int main() > { > emp e = {0}; > Pyobject *pName, *pModule, *pFunc, *pArgs,*pValue; > Py_Initialize(); > pName = PyString_FromString("test"); > pModule = PyImport_Import(pName); > Py_DECREF(pName); > if (pModule != NULL) > { > pFunc = PyObject_GetAttrString(pModule, "testStruct"); > if(pFunc && PyCallable_Check(pFunc)) > { > pArgs = e //******************logic to assign struct employee into pArgs > pValue = PyObject_CallObject(pFunc, pArgs); > } > } > Py_DECREF(pValue); > Py_DECREF(pModule); > Py_Finalize(); > return 0; > } > > and now python script test.py > def testStruct(): # **** need any parameter will be specify > #**** assign value into the cStructure > f=open(filename) > f.write(cStructure.Value) # **** value to write in file > > Thanks in advance > regards > ah > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Jan 13 17:56:21 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Jan 2010 13:56:21 -0300 Subject: [python-win32] Guaranteed cleanup code execution? References: <1263256535.15072.119.camel@corn.betterworld.us> <3fbf862f1001111833s2030b7beuf3fca2cf5c41f902@mail.gmail.com> Message-ID: En Mon, 11 Jan 2010 23:33:23 -0300, Mario Alejandro Vilas Jerez escribi?: > But what I think you're really looking for is the Service Control > Manager: > > http://msdn.microsoft.com/en-us/library/ms685150(VS.85).aspx > > The ControlService API lets you stop services (among other things): > > http://msdn.microsoft.com/en-us/library/ms682108(VS.85).aspx > > And the StartService API lets you start a service manually: > > http://msdn.microsoft.com/en-us/library/ms686321(VS.85).aspx All of which are covered in the win32service and win32serviceutil modules inside PyWin32. There are a couple demos too. It's quite easy to write a service using the classes provided. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Jan 13 18:16:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 13 Jan 2010 14:16:14 -0300 Subject: [python-win32] 'No such interface supported' question References: <8EC4F97637845642809C79C97C0F5440757079B1D9@MAILMAN.maptel.local> Message-ID: En Fri, 08 Jan 2010 00:25:15 -0300, Gareth Walters escribi?: > I have done some python work before but I new to the COM stuff. I am > trying to Create a MXD and layers to it from python. I have been looking > at this PythonNet stuff and it is all getting a bit blurry. > I was wondering if you could give me some pointers to basically get > python recognizing the ArcMap class or do you have any code that would > help me get to that point? Mark Hammond's book "Python Programming On Win32" covers using COM objects from Python. You're mostly interested in chapter 12. I think this chapter is available for preview from the O'Reilly site. http://oreilly.com/catalog/9781565926219/ -- Gabriel Genellina From timr at probo.com Wed Jan 13 19:35:20 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 13 Jan 2010 10:35:20 -0800 Subject: [python-win32] passing c structure into python function In-Reply-To: References: Message-ID: <4B4E1268.4040203@probo.com> a h wrote: > > thanks for your response > in the last piece of c code i want to know how do i pass structure > into python function in c. I have tried to call a python function > which takes string as parameter. > > i have passed string parameter as : > const char *str_pArgs = "hello"; > pArgs = PyTuple_New(1); > pValue = PyString_FromString(str_pArgs); > PyTuple_SetItem(pArgs, 0,pValue); > pValue = PyObject_CallObject(pFunc, pArgs); > > similarly how do i convert this structure for python function argument. > > ->pArgs = e //******************logic to assign struct employee into pArgs There are several ways to do this. If it were me, looking for the easy way, I would just pass the structure as a string (by casting the address of the struct to a (char *)), and unpack it with struct.unpack, as I showed earlier. There are many other ways, however. You could create a tuple from the struct elements, and pass the elements in their native types. You could even go to the trouble of creating a dict or an object in your C code, populate it, and return it. It depends on how often this will be used and who is your audience. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From lyeoh at pop.jaring.my Wed Jan 13 19:32:09 2010 From: lyeoh at pop.jaring.my (Lincoln Yeoh) Date: Thu, 14 Jan 2010 02:32:09 +0800 Subject: [python-win32] Getting a list of "task buttons" or tasks/windows in the "alt-tab" list? Message-ID: <201001131832.o0DIWJPw019549@vsmtp6.jaring.my> Hi, With python win32 is there a way to get only the windows that are represented by the buttons of the Windows taskbar (or the windows listed in the "alt-tab" list)? I have found various ways of doing so, but I can't seem to get them to work with Excel's windows. From what I observe (I may be wrong though), Excel by default appears to have a main window and some "dummy windows" (classname=MS-SDIb) representing the opened Excel documents. If you click on those "dummy windows" the relevant excel document gets foregrounded in the _main_ window (not the dummy windows). If three Excel documents are opened, there are four top level Excel windows (or at least they appear to be top level to me) - the main, and three MS-SDIb ones. But the taskbar and alt-tab list only show 3 items. What logic should one use to create the same list? I've created a python program to dynamically map key combos to top-level windows[1], it kind of works (enough to be helpful to me), but I'm having difficulty handling even common stuff like the Excel case so it's not ready to be inflicted on the public yet :). Thanks, Link. [1] Does something similar to some of the stuff I suggest here: http://www.mail-archive.com/usability at gnome.org/msg04993.html and here: http://live.gnome.org/GnomeShell/DesignersPlayground/KeyboardShortcuts From Andrew.MacIntyre at acma.gov.au Thu Jan 14 00:27:32 2010 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Thu, 14 Jan 2010 10:27:32 +1100 Subject: [python-win32] 'No such interface supported' question [SEC=PERSONAL] In-Reply-To: <8EC4F97637845642809C79C97C0F5440757079B1D9@MAILMAN.maptel.local> References: <8EC4F97637845642809C79C97C0F5440757079B1D9@MAILMAN.maptel.local> Message-ID: <7B01D7143C4AD54899EA079D4557562AFEF8F6@ACT01EXC02.internal.govt> Gareth Walters wrote: ? I have done some python work before but I new to the COM stuff. I am trying to Create a MXD and layers to it from python. I have been looking at this PythonNet stuff and it is all getting a bit blurry. ? I was wondering if you could give me some pointers to basically get python recognizing the ArcMap class or do you have any code that would help me get to that point? You will need the comtypes package to access most of the ArcObjects classes. If you have the Python 2.5 installed by the ArcGIS installer, you will have the requisite ctypes extension. Sadly, most of the ArcObjects classes don't support the Dispatch interfaces required by PythonWin. -------------------------> "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/ If you have received this email in error, please notify the sender immediately and erase all copies of the email and any attachments to it. The information contained in this email and any attachments may be private, confidential and legally privileged or the subject of copyright. If you are not the addressee it may be illegal to review, disclose, use, forward, or distribute this email and/or its contents. Unless otherwise specified, the information in the email and any attachments is intended as a guide only and should not be relied upon as legal or technical advice or regarded as a substitute for legal or technical advice in individual cases. Opinions contained in this email or any of its attachments do not necessarily reflect the opinions of ACMA. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mehgcap at gmail.com Fri Jan 15 06:05:56 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 00:05:56 -0500 Subject: [python-win32] WMI troubles! Message-ID: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> Hello all, I just joined this list. I am pretty new to Python, but I really like and hope to get more into it; right now, it is my second-favorite, second only to java. I am a computer science major in my third year and currently only program as a hobby/for something to do. Also, I am blind so I use JAWS for Windows (from http://www.freedomscientific.com) to do all my computer work; basically, this program reads me the screen. I only mention this so the projects I am doing make sense and so you understand why suggesting things like looking at a diagram or an animation will not work. Anyway, onto the problem. I am working on a simple resource monitor (I have never found one that works well with screen readers, so I am writing one). I am using python2.6 with all the win32 libs installed. My monitor will use wmi to get all of its information, and it was going pretty well until a few hours ago, when I started receiving seemingly random errors. I can call my functions, such as getFreeRam or getLoad, with no problem as long as the call is hard-coded into the script. However, when I try to call said functions from a function monitoring keyboard input (using pyHooks), I get an error and the program crashes (at least it did until I put a try/except in there, but hitting the hotkey over and over always gives me an error). I will paste the entire file below. It is not very commented yet, so if something does not make sense, please let me know. My questions are: 1. Why am I getting these errors? 2. The getLoad function only returns one number (the counter is there to double check that the loop really only runs once). I have a dual core AMD, so I expected two numbers, a LoadPercentage for each core, not just one number. How do I get the load per core, not per physical processor? 3. Regarding pyHook: I press my win-` hotkey on the desktop and get something to happen in my script, which is good. However, I also get a Windows error sound. Is there a way to grab that keystroke before Windows can get it to avoid what seems to be passing the keystroke to the active app before my script can get it? I tried returning False in my keyUp function but that made no difference. I am running Windows 7 Home Premium, 64 bit, on an AMD processor whose exact model escapes me. It is clocked at around 2.4ghz and I have 4gb of 800mhz ddr2 ram. The pc was built by my friend and I from Newegg parts, but has worked well for the last 18 months (seeing three different operating systems). Win7 was installed a few days ago, so I am pretty sure there is no problem with my installation as far as wmi goes. I tried to run the wmi diagnostic utility, but I got an error; I figure the utility cannot run in 64 bit, but I am not sure. Anyway, any help here would be greatly appreciated. This is my first "real" project in python, so go easy on my stupid mistakes. :) Thanks! CODE import os, sys, wmi, win32com.client, pyHook, pythoncom pythoncom.CoInitialize() #a forum post said I should put this... win=0 #is either Windows key pressed? ctrl=0 #either control key pressed? alt=0 #what about either alt key? #for speaking text with the user's active screenreader, or sapi if no reader #http://www.empowermentzone.com/saysetup.exe speaker=win32com.client.Dispatch("Say.Tools") c=wmi.WMI("localhost") #for WMI access def getLoad(): i=0 #get proc load, currently only first core for some reason for p in c.Win32_Processor(): load=p.LoadPercentage i=i+1 # end for speaker.say(str(load)+", looped "+str(i)+" times.") return(load) #end def #following works just fine here, but not when called later in keyUp method getLoad() def getFreeRam(): #get total ram and ram available for info in c.Win32_OperatingSystem(): ram=info.TotalVisibleMemorySize freeRam=info.FreePhysicalMemory #end for return(float(freeRam)/float(ram)*100) #return free ram as % #end def def toBiggestBytes(n): #returns a string where n is in the largest logical measure possible i=0 #counter units=[" bytes","kb","mb","gb","tb"] while(n>=1024): n=n/1024 i=i+1 return(str(n)+units[i]) #end def #following does not work: why? """ for t in c.MSAcpi_ThermalZoneTemperature(): temp=t.CurrentTemperature # end for """ """ #old interface used for early testing end=0 while(end==0): lr=raw_input("\nr for ram, l for CPU load, e to exit.\n") if(lr=='r'): pRam=int(ram)/1024/1024 speaker.say(str(pRam)+"mb total RAM") if(lr=='l'): speaker.say(str(load)+"% for core 1") if(lr=='e'): end=1 #exit loop #endif #end while """ #Copied directly from example.py in the pyHook folder, then modified def OnKeyDownEvent(event): global win global ctrl global alt if(event.KeyID==91 or event.KeyID==92): #user is pressing a Windows key, so set flag win=1 #endif # return True to pass the event to other handlers # return False to stop the event from propagating return True #end def def OnKeyUpEvent(event): global win global ctrl global alt if(event.KeyID==91 or event.KeyID==92): #user released the Windows key, so unset flag win=0 #endif if(win==1 and chr(event.Ascii)=='`'): try: speaker.say(str(getLoad())) except: speaker.say("Stupid errors!") #end except #endif return True #end def # create the hook mananger hm = pyHook.HookManager() # register two callbacks hm.KeyDown = OnKeyDownEvent hm.KeyUp = OnKeyUpEvent # hook into the keyboard event hm.HookKeyboard() if __name__ == '__main__': import pythoncom pythoncom.PumpMessages() #end copying/modifying speaker=None; #release speaker object #reference so I know what properties I can get """ print 'MessageName:',event.MessageName print 'Message:',event.Message print 'Time:',event.Time print 'Window:',event.Window print 'WindowName:',event.WindowName print 'Ascii:', event.Ascii, chr(event.Ascii) print 'Key:', event.Key print 'KeyID:', event.KeyID print 'ScanCode:', event.ScanCode print 'Extended:', event.Extended print 'Injected:', event.Injected print 'Alt', event.Alt print 'Transition', event.Transition print '---' """ Have a great day, Alex Email: mehgcap at gmail.com From mail at timgolden.me.uk Fri Jan 15 10:00:04 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 15 Jan 2010 09:00:04 +0000 Subject: [python-win32] WMI troubles! In-Reply-To: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> Message-ID: <4B502E94.3010007@timgolden.me.uk> On 15/01/2010 05:05, Alex Hall wrote: > Hello all, > I just joined this list. I am pretty new to Python, but I really like and > hope to get more into it; Welcome to the list. And to Python. > Anyway, onto the problem. I am working on a simple resource monitor (I have > never found one that works well with screen readers, so I am writing one). I > am using python2.6 with all the win32 libs installed. My monitor will use > wmi to get all of its information, and it was going pretty well until a few > hours ago, when I started receiving seemingly random errors. What would definitely help, and this is general advice for posting to technical groups, is the exact error you received -- the traceback which looks something like this: Traceback (most recent call last): File "", line 1, in File "c:\work_in_progress\wmi\trunk\wmi.py", line 1124, in __getattr__ return getattr (self._namespace, attribute) File "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 512, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: winmgmts:.Win32_Processx >>> In addition -- and I appreciate that this isn't always easy -- is the smallest self-contained code example which will fail every time. Apart from making it easier for people to help you out, it sometimes makes the source of the error clearer even to you, the developer. I don't have time now, but I will get to this later on today. The likeliest cause is that PyHook is introducing a threading context which is causing problems with the COM-based WMI stuff. Your early CoInitialize is a nod in the right direction, but unfortunately redundant where you've put it at the top of the main thread. But sight of the traceback should help clarify things considerably. TJG From lyeoh at pop.jaring.my Fri Jan 15 18:16:27 2010 From: lyeoh at pop.jaring.my (Lincoln Yeoh) Date: Sat, 16 Jan 2010 01:16:27 +0800 Subject: [python-win32] Getting a list of "task buttons" or tasks/windows in the "alt-tab" list? In-Reply-To: <201001131832.o0DIWJPw019549@vsmtp6.jaring.my> References: <201001131832.o0DIWJPw019549@vsmtp6.jaring.my> Message-ID: <201001151716.o0FHGWcO067512@vsmtp6.jaring.my> At 02:32 AM 1/14/2010, Lincoln Yeoh wrote: >If three Excel documents are opened, there are four top level Excel >windows (or at least they appear to be top level to me) - the main, >and three MS-SDIb ones. But the taskbar and alt-tab list only show 3 >items. What logic should one use to create the same list? OK I think it might be something to do with the "ITaskList_Deleted" window property that the main excel window sometimes has and sometimes doesn't (seems to depend on whether it has MS-SDIb windows or not). Anyway, I'm now having difficulty checking for that window property using win32 python. I can't seem to get user32.GetProp to work for me. I tried: rv=ctypes.windll.user32.GetProp(hwnd,'ITaskList_Deleted') But I get: File "C:\Python26\lib\ctypes\__init__.py", line 366, in __getattr__ func = self.__getitem__(name) File "C:\Python26\lib\ctypes\__init__.py", line 371, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'GetProp' not found I tried: rv=ctypes.windll.user32.GetPropA(hwnd,'ITaskList_Deleted') But I get an ctypes.GetLastError()==2 after that. Any tips? Link. From mehgcap at gmail.com Fri Jan 15 18:58:18 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 12:58:18 -0500 Subject: [python-win32] WMI troubles! In-Reply-To: <4B502E94.3010007@timgolden.me.uk> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B502E94.3010007@timgolden.me.uk> Message-ID: I am trying to put the stack trace into a file, since I cannot copy and paste from the cmd line output. Is there a way to do this? Also, if you run the file (assuming you have all the dependencies) the error happens as soon as you press windows-`. You can change "speaker.say" to "print" and comment out the line creating the speaker object so that you do not have to install sayTools. Have a great day, Alex Email: mehgcap at gmail.com ----- Original Message ----- From: "Tim Golden" Cc: Sent: Friday, January 15, 2010 4:00 Subject: Re: [python-win32] WMI troubles! > On 15/01/2010 05:05, Alex Hall wrote: >> Hello all, >> I just joined this list. I am pretty new to Python, but I really like and >> hope to get more into it; > > Welcome to the list. And to Python. > >> Anyway, onto the problem. I am working on a simple resource monitor (I >> have >> never found one that works well with screen readers, so I am writing >> one). I >> am using python2.6 with all the win32 libs installed. My monitor will use >> wmi to get all of its information, and it was going pretty well until a >> few >> hours ago, when I started receiving seemingly random errors. > > What would definitely help, and this is general advice for posting > to technical groups, is the exact error you received -- the traceback > which looks something like this: > > Traceback (most recent call last): > File "", line 1, in > File "c:\work_in_progress\wmi\trunk\wmi.py", line 1124, in __getattr__ > return getattr (self._namespace, attribute) > File "c:\python26\lib\site-packages\win32com\client\dynamic.py", line > 512, in __getattr__ > raise AttributeError("%s.%s" % (self._username_, attr)) > AttributeError: winmgmts:.Win32_Processx >>>> > > In addition -- and I appreciate that this isn't always easy -- is > the smallest self-contained code example which will fail every time. > Apart from making it easier for people to help you out, it sometimes > makes the source of the error clearer even to you, the developer. > > I don't have time now, but I will get to this later on today. The > likeliest cause is that PyHook is introducing a threading context > which is causing problems with the COM-based WMI stuff. Your early > CoInitialize is a nod in the right direction, but unfortunately > redundant where you've put it at the top of the main thread. > > But sight of the traceback should help clarify things considerably. > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From aahz at pythoncraft.com Fri Jan 15 19:18:49 2010 From: aahz at pythoncraft.com (Aahz) Date: Fri, 15 Jan 2010 10:18:49 -0800 Subject: [python-win32] WMI troubles! In-Reply-To: References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B502E94.3010007@timgolden.me.uk> Message-ID: <20100115181849.GA26279@panix.com> On Fri, Jan 15, 2010, Alex Hall wrote: > > I am trying to put the stack trace into a file, since I cannot copy and > paste from the cmd line output. Is there a way to do this? Also, if you > run the file (assuming you have all the dependencies) the error happens > as soon as you press windows-`. You can change "speaker.say" to "print" > and comment out the line creating the speaker object so that you do not > have to install sayTools. You probably will have difficulty doing this, but yes, you can copy/paste command-line output using a mouse to select a screen area. Actually, I just looked in my Windows virtual machine and you can do alt-space, edit, select all, enter You can also use try/except and the traceback module to capture an exception and write it to a file. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From mehgcap at gmail.com Fri Jan 15 19:26:00 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 13:26:00 -0500 Subject: [python-win32] WMI troubles! In-Reply-To: <20100115181849.GA26279@panix.com> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B502E94.3010007@timgolden.me.uk> <20100115181849.GA26279@panix.com> Message-ID: <12E87B5F255043C084454902F42B8EAD@AlexPC> What is the syntax to write the traceback to a text file? I have the file object and I can open and close the file, I just need the command, like "f.write(StackTrace())" or whatever the command is. I will try the alt-space idea as well. Have a great day, Alex Email: mehgcap at gmail.com ----- Original Message ----- From: "Aahz" To: "Alex Hall" Cc: Sent: Friday, January 15, 2010 13:18 Subject: Re: [python-win32] WMI troubles! > On Fri, Jan 15, 2010, Alex Hall wrote: >> >> I am trying to put the stack trace into a file, since I cannot copy and >> paste from the cmd line output. Is there a way to do this? Also, if you >> run the file (assuming you have all the dependencies) the error happens >> as soon as you press windows-`. You can change "speaker.say" to "print" >> and comment out the line creating the speaker object so that you do not >> have to install sayTools. > > You probably will have difficulty doing this, but yes, you can > copy/paste command-line output using a mouse to select a screen area. > > Actually, I just looked in my Windows virtual machine and you can do > alt-space, edit, select all, enter > > You can also use try/except and the traceback module to capture an > exception and write it to a file. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "If you think it's expensive to hire a professional to do the job, wait > until you hire an amateur." --Red Adair From timr at probo.com Fri Jan 15 19:33:26 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 15 Jan 2010 10:33:26 -0800 Subject: [python-win32] WMI troubles! In-Reply-To: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> Message-ID: <4B50B4F6.1040704@probo.com> Alex Hall wrote: > > Anyway, onto the problem. I am working on a simple resource monitor (I > have never found one that works well with screen readers, so I am > writing one). I am using python2.6 with all the win32 libs installed. > My monitor will use wmi to get all of its information, and it was > going pretty well until a few hours ago, when I started receiving > seemingly random errors. I can call my functions, such as getFreeRam > or getLoad, with no problem as long as the call is hard-coded into the > script. However, when I try to call said functions from a function > monitoring keyboard input (using pyHooks), I get an error and the > program crashes (at least it did until I put a try/except in there, > but hitting the hotkey over and over always gives me an error). Windows hooks run in a unique environment. When you install a Windows hook, you are actually injecting a DLL into every process in the system. (It's not a low overhead operation!) The code in the keyboard hook runs as part of another processs. Now, I have not looked into the pyHooks code to see if they are managing that, by using some kind of inter-process communication. If they are not, then you are very limited in what you can do in your callback. "print" wouldn't work, because that process has a different standard output. You would need to send a signal back to your own process. Further, COM will not have been initialized in that other thread, so you wouldn't be able to use a COM object, like "Say.Tools". You can try calling pythoncom.CoInitialize() in every callback, I suppose. > I will paste the entire file below. It is not very commented yet, so > if something does not make sense, please let me know. My questions are: > > 1. Why am I getting these errors? What errors do you get? I don't think you told us that. > 2. The getLoad function only returns one number (the counter is there > to double check that the loop really only runs once). I have a dual > core AMD, so I expected two numbers, a LoadPercentage for each core, > not just one number. How do I get the load per core, not per physical > processor? Well, it only returns one value because you overwrite the value of "load" every time through the loop. If you want to return multiple values, you should add each new value to a list, and return the list. > 3. Regarding pyHook: I press my win-` hotkey on the desktop and get > something to happen in my script, which is good. However, I also get a > Windows error sound. Is there a way to grab that keystroke before > Windows can get it to avoid what seems to be passing the keystroke to > the active app before my script can get it? I tried returning False in > my keyUp function but that made no difference. This shouldn't be an issue. The hotkeys are handled by Explorer, which sucks up the key after it launches your program. I don't understand who would trigger the sound. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Jan 15 19:35:58 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 15 Jan 2010 10:35:58 -0800 Subject: [python-win32] WMI troubles! In-Reply-To: References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B502E94.3010007@timgolden.me.uk> Message-ID: <4B50B58E.1020703@probo.com> Alex Hall wrote: > I am trying to put the stack trace into a file, since I cannot copy > and paste from the cmd line output. Sure you can. Alt-Space, Edit, Select-All. Then press "Enter" to copy the entire contents of the shell window to the clipboard. If you were sighted, I would suggest Alt-Space, Edit, Mark; then you can use your mouse to draw a box around the text you want to clip, and again press "Enter" to copy that region to the clipboard. Alternatively, there are a couple of very handy tools called "gclip" and "pclip" that are part of the "unxutils" collection on SourceForge. Anything piped into gclip is copied to the clipboard, and pclip prints the clipboard to its standard output. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mehgcap at gmail.com Fri Jan 15 19:39:49 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 13:39:49 -0500 Subject: [python-win32] WMI troubles! In-Reply-To: <20100115181849.GA26279@panix.com> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B502E94.3010007@timgolden.me.uk> <20100115181849.GA26279@panix.com> Message-ID: <29D27DFCDBCD4D4CBE97D79D652EFFBE@AlexPC> Let's try this. Here is the stack trace when I ran my program. It ran fine, even calling the getLoad function once since that call is built into the code, not dependent on a keypress. This trace printed after I pressed win-`, the keypress I have assigned, through pyHook, to trigger a call to getLoad. If you want, you can change the call to getLoad to getFreeRam and a similar error occurs, pasted below this one. Error from keypress calling getLoad(): C:\Users\Alex>python c:\prog\python\sys.py Traceback (most recent call last): File "c:\python26\lib\site-packages\pyHook\HookManager.py", line 351, in Keybo ardSwitch return func(event) File "c:\prog\python\sys.py", line 88, in OnKeyUpEvent speaker.say(str(getLoad())) File "c:\prog\python\sys.py", line 14, in getLoad for p in c.Win32_Processor(): File "c:\python26\lib\site-packages\wmi.py", line 647, in query return self._namespace.query (wql, self, fields) File "c:\python26\lib\site-packages\wmi.py", line 835, in query return [ _wmi_object (obj, instance_of, fields) for obj in self._raw_query(w ql) ] File "c:\python26\lib\site-packages\wmi.py", line 829, in _raw_query raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult)) wmi.x_wmi: -2147352567 Error from keypress calling getFreeRam(): C:\Users\Alex>python c:\prog\python\sys.py Traceback (most recent call last): File "c:\python26\lib\site-packages\pyHook\HookManager.py", line 351, in Keybo ardSwitch return func(event) File "c:\prog\python\sys.py", line 88, in OnKeyUpEvent speaker.say(str(getFreeRam())) File "c:\prog\python\sys.py", line 24, in getFreeRam for info in c.Win32_OperatingSystem(): File "c:\python26\lib\site-packages\wmi.py", line 975, in __getattr__ return getattr (self._namespace, attribute) File "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 512, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: winmgmts:{impersonationLevel=impersonate,authenticationLevel=def ault}//localhost/.Win32_OperatingSystem Have a great day, Alex Email: mehgcap at gmail.com ----- Original Message ----- From: "Aahz" To: "Alex Hall" Cc: Sent: Friday, January 15, 2010 13:18 Subject: Re: [python-win32] WMI troubles! > On Fri, Jan 15, 2010, Alex Hall wrote: >> >> I am trying to put the stack trace into a file, since I cannot copy and >> paste from the cmd line output. Is there a way to do this? Also, if you >> run the file (assuming you have all the dependencies) the error happens >> as soon as you press windows-`. You can change "speaker.say" to "print" >> and comment out the line creating the speaker object so that you do not >> have to install sayTools. > > You probably will have difficulty doing this, but yes, you can > copy/paste command-line output using a mouse to select a screen area. > > Actually, I just looked in my Windows virtual machine and you can do > alt-space, edit, select all, enter > > You can also use try/except and the traceback module to capture an > exception and write it to a file. > -- > Aahz (aahz at pythoncraft.com) <*> > http://www.pythoncraft.com/ > > "If you think it's expensive to hire a professional to do the job, wait > until you hire an amateur." --Red Adair From mehgcap at gmail.com Fri Jan 15 19:49:30 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 13:49:30 -0500 Subject: [python-win32] WMI troubles! In-Reply-To: <4B50B4F6.1040704@probo.com> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B50B4F6.1040704@probo.com> Message-ID: <3164DF6271584B1098783412B56698DB@AlexPC> Regarding question 2, about only receiving one number for two cores, I have a counter in the loop which gets incremented each time the loop runs. This counter always ends up at 1, not 2, so it is only incremented once. When I first started this last week I did put any returns into a list, but the list was always just one element long. This seems to tell me that I am only getting one number, but I should be getting two. Is there a syntax thing that I am missing or confused about, or is wmi refusing me the information about my other core? Is there a different class I should be using to get the load per core? As far as pyHook, it sounds like it is not going to work too well. Are you saying it could be the cause of the wmi troubles? If so, is there another library I should use instead? I want this to be a global thing, so no matter where in Windows you are, you need only press a hotkey to hear the status of your hardware, like a sighted person need only glance at their resource monitor gadget/sidebar app. For that reason I avoided pyGame and wx since, as I understand it, they only monitor keypresses in their windows, not through the entire system. Finally, when you say "calling pythoncom.CoInitialize() in every callback", what do you mean by 'callback'? Have a great day, Alex Email: mehgcap at gmail.com ----- Original Message ----- From: "Tim Roberts" To: "Python-Win32 List" Sent: Friday, January 15, 2010 13:33 Subject: Re: [python-win32] WMI troubles! > Alex Hall wrote: >> >> Anyway, onto the problem. I am working on a simple resource monitor (I >> have never found one that works well with screen readers, so I am >> writing one). I am using python2.6 with all the win32 libs installed. >> My monitor will use wmi to get all of its information, and it was >> going pretty well until a few hours ago, when I started receiving >> seemingly random errors. I can call my functions, such as getFreeRam >> or getLoad, with no problem as long as the call is hard-coded into the >> script. However, when I try to call said functions from a function >> monitoring keyboard input (using pyHooks), I get an error and the >> program crashes (at least it did until I put a try/except in there, >> but hitting the hotkey over and over always gives me an error). > > Windows hooks run in a unique environment. When you install a Windows > hook, you are actually injecting a DLL into every process in the > system. (It's not a low overhead operation!) The code in the keyboard > hook runs as part of another processs. > > Now, I have not looked into the pyHooks code to see if they are managing > that, by using some kind of inter-process communication. If they are > not, then you are very limited in what you can do in your callback. > "print" wouldn't work, because that process has a different standard > output. You would need to send a signal back to your own process. > Further, COM will not have been initialized in that other thread, so you > wouldn't be able to use a COM object, like "Say.Tools". You can try > calling pythoncom.CoInitialize() in every callback, I suppose. > > >> I will paste the entire file below. It is not very commented yet, so >> if something does not make sense, please let me know. My questions are: >> >> 1. Why am I getting these errors? > > What errors do you get? I don't think you told us that. > > >> 2. The getLoad function only returns one number (the counter is there >> to double check that the loop really only runs once). I have a dual >> core AMD, so I expected two numbers, a LoadPercentage for each core, >> not just one number. How do I get the load per core, not per physical >> processor? > > Well, it only returns one value because you overwrite the value of > "load" every time through the loop. If you want to return multiple > values, you should add each new value to a list, and return the list. > > >> 3. Regarding pyHook: I press my win-` hotkey on the desktop and get >> something to happen in my script, which is good. However, I also get a >> Windows error sound. Is there a way to grab that keystroke before >> Windows can get it to avoid what seems to be passing the keystroke to >> the active app before my script can get it? I tried returning False in >> my keyUp function but that made no difference. > > This shouldn't be an issue. The hotkeys are handled by Explorer, which > sucks up the key after it launches your program. I don't understand who > would trigger the sound. > > -- > 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 Fri Jan 15 20:20:41 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 15 Jan 2010 11:20:41 -0800 Subject: [python-win32] WMI troubles! In-Reply-To: <3164DF6271584B1098783412B56698DB@AlexPC> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B50B4F6.1040704@probo.com> <3164DF6271584B1098783412B56698DB@AlexPC> Message-ID: <4B50C009.10300@probo.com> Alex Hall wrote: > Regarding question 2, about only receiving one number for two cores, I > have a counter in the loop which gets incremented each time the loop > runs. This counter always ends up at 1, not 2, so it is only > incremented once. When I first started this last week I did put any > returns into a list, but the list was always just one element long. > This seems to tell me that I am only getting one number, but I should > be getting two. Is there a syntax thing that I am missing or confused > about, or is wmi refusing me the information about my other core? Is > there a different class I should be using to get the load per core? The number you are getting is the average load for the physical processor, which includes all of the cores and hyperthreaded modules. If you have a dual core machine, you'll find that c.NumberOfCores is 2. Check this MSDN article: http://msdn.microsoft.com/en-us/library/aa394317.aspx It describes the WMI Win32_PerfRawData_PerfOS_Processor class, which includes information per logical processor, and describes how to figure that out from the Win32_Processor information. > As far as pyHook, it sounds like it is not going to work too well. Are > you saying it could be the cause of the wmi troubles? Well, you didn't say what the actual error was until just a few minutes ago, so I didn't know the troubles were in WMI. I assumed you were having troubles reaching the "Say" class or doing a "print". It's possible that some of the processes you are hooking do not have permission to access WMI. > If so, is there another library I should use instead? I want this to > be a global thing, so no matter where in Windows you are, you need > only press a hotkey to hear the status of your hardware, like a > sighted person need only glance at their resource monitor > gadget/sidebar app. For that reason I avoided pyGame and wx since, as > I understand it, they only monitor keypresses in their windows, not > through the entire system. In that case, why use a hook at all? Why not just have a single script that fetches and says the resource usage and then exits? You could have that tied to an Explorer hotkey, just like you do now. Windows hooks are a very heavyweight technology. Your hook code gets executed for every keystroke and every mouse motion. > Finally, when you say "calling pythoncom.CoInitialize() in every > callback", what do you mean by 'callback'? Your OnKeyDown and OnKeyUp functions are being called in response to external events. You pass those functions to pyHooks, and it "calls you back" when something happens. Functions that you provide for someone else to call are called "callbacks". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mehgcap at gmail.com Fri Jan 15 20:38:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 14:38:05 -0500 Subject: [python-win32] WMI troubles! In-Reply-To: <4B50C009.10300@probo.com> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC><4B50B4F6.1040704@probo.com><3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> Message-ID: Thanks, I will look at the article! I do not want a single script because, eventually, the plan is to have a keystroke for core 1, a keystroke for core 2, a keystroke for percent of ram used, a keystroke for hard disk space, and so on. While I could write each function in its own script and put a hotkey on each one, it seems easier and faster to just make one script and run it once, avoiding the delay I always get when this script runs for the first time from happening each time I press a hotkey. Sorry for the lack of detail about the errors. I knew they were wmi errors, so when I read back through the messages I wrote it made sense to me, but of course I should have said what kind of errors were being generated. Have a great day, Alex Email: mehgcap at gmail.com ----- Original Message ----- From: "Tim Roberts" To: "Python-Win32 List" Sent: Friday, January 15, 2010 14:20 Subject: Re: [python-win32] WMI troubles! > Alex Hall wrote: >> Regarding question 2, about only receiving one number for two cores, I >> have a counter in the loop which gets incremented each time the loop >> runs. This counter always ends up at 1, not 2, so it is only >> incremented once. When I first started this last week I did put any >> returns into a list, but the list was always just one element long. >> This seems to tell me that I am only getting one number, but I should >> be getting two. Is there a syntax thing that I am missing or confused >> about, or is wmi refusing me the information about my other core? Is >> there a different class I should be using to get the load per core? > > The number you are getting is the average load for the physical > processor, which includes all of the cores and hyperthreaded modules. > If you have a dual core machine, you'll find that c.NumberOfCores is 2. > Check this MSDN article: > http://msdn.microsoft.com/en-us/library/aa394317.aspx > > It describes the WMI Win32_PerfRawData_PerfOS_Processor class, which > includes information per logical processor, and describes how to figure > that out from the Win32_Processor information. > > >> As far as pyHook, it sounds like it is not going to work too well. Are >> you saying it could be the cause of the wmi troubles? > > Well, you didn't say what the actual error was until just a few minutes > ago, so I didn't know the troubles were in WMI. I assumed you were > having troubles reaching the "Say" class or doing a "print". It's > possible that some of the processes you are hooking do not have > permission to access WMI. > > >> If so, is there another library I should use instead? I want this to >> be a global thing, so no matter where in Windows you are, you need >> only press a hotkey to hear the status of your hardware, like a >> sighted person need only glance at their resource monitor >> gadget/sidebar app. For that reason I avoided pyGame and wx since, as >> I understand it, they only monitor keypresses in their windows, not >> through the entire system. > > In that case, why use a hook at all? Why not just have a single script > that fetches and says the resource usage and then exits? You could have > that tied to an Explorer hotkey, just like you do now. Windows hooks > are a very heavyweight technology. Your hook code gets executed for > every keystroke and every mouse motion. > > >> Finally, when you say "calling pythoncom.CoInitialize() in every >> callback", what do you mean by 'callback'? > > Your OnKeyDown and OnKeyUp functions are being called in response to > external events. You pass those functions to pyHooks, and it "calls you > back" when something happens. Functions that you provide for someone > else to call are called "callbacks". > > -- > 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 Fri Jan 15 20:47:23 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 15 Jan 2010 11:47:23 -0800 Subject: [python-win32] WMI troubles! In-Reply-To: References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC><4B50B4F6.1040704@probo.com><3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> Message-ID: <4B50C64B.7070803@probo.com> Alex Hall wrote: > > I do not want a single script because, eventually, the plan is to have > a keystroke for core 1, a keystroke for core 2, a keystroke for > percent of ram used, a keystroke for hard disk space, and so on. While > I could write each function in its own script and put a hotkey on each > one, it seems easier and faster to just make one script and run it > once, avoiding the delay I always get when this script runs for the > first time from happening each time I press a hotkey. I guess that depends on how you define "easier" and "faster". For development time, it's certainly going to be faster to create a set of small, self-contained, single-purpose scripts that start, run, and end, than it is to figure out the twisty paths involved in Windows hooks. This is very much like the trade-off between writing CGI scripts and writing a full-blown web application. It's a lot quicker to get a CGI script up and running. Yes, there is a short delay when starting a Python app, but after the interpreter has been loaded once, it should stay in the file cache, so subsequent loads go faster. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mail at timgolden.me.uk Fri Jan 15 21:19:37 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 15 Jan 2010 20:19:37 +0000 Subject: [python-win32] WMI troubles! In-Reply-To: <12E87B5F255043C084454902F42B8EAD@AlexPC> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B502E94.3010007@timgolden.me.uk> <20100115181849.GA26279@panix.com> <12E87B5F255043C084454902F42B8EAD@AlexPC> Message-ID: <4B50CDD9.109@timgolden.me.uk> On 15/01/2010 18:26, Alex Hall wrote: > What is the syntax to write the traceback to a text file? I have the > file object and I can open and close the file, I just need the command, > like "f.write(StackTrace())" or whatever the command is. I will try the > alt-space idea as well. Just to answer this question on its own for the moment: the following code is the kind of thing you can use to trap an error and write the traceback to a file. (You could also use the stdlib logging module): import traceback try: 1 / 0 # or something more useful except: with open ("error.log", "a") as f: traceback.print_exc (file=f) # or f.write (traceback.format_exc ()) TJG From mail at timgolden.me.uk Fri Jan 15 21:31:42 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 15 Jan 2010 20:31:42 +0000 Subject: [python-win32] WMI troubles! In-Reply-To: References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC><4B50B4F6.1040704@probo.com><3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> Message-ID: <4B50D0AE.1060509@timgolden.me.uk> On 15/01/2010 19:38, Alex Hall wrote: > I do not want a single script because, eventually, the plan is to have a > keystroke for core 1, a keystroke for core 2, a keystroke for percent of > ram used, a keystroke for hard disk space, and so on. While I could > write each function in its own script and put a hotkey on each one, it > seems easier and faster to just make one script and run it once, > avoiding the delay I always get when this script runs for the first time > from happening each time I press a hotkey. I've got slightly lost in this thread (not helped, I'm afraid Alex, by your habit of top-posting ;) ) but in an effort to be helpful, can I suggest the following. Instead of fiddling with pyHooks which are -- as Tim R points out -- somewhat dark and messy, consider adapting the following example instead: http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html This uses a straightforward Windows message loop to provide to sort of global hotkeys I think you're after. You might, for example, change the handle_win_f3 function to start a wmi instance (or use an existing one) and then produce the output you were after. TJG From mehgcap at gmail.com Fri Jan 15 21:57:28 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 15:57:28 -0500 Subject: [python-win32] WMI troubles! In-Reply-To: <4B50D0AE.1060509@timgolden.me.uk> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC><4B50B4F6.1040704@probo.com><3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> <4B50D0AE.1060509@timgolden.me.uk> Message-ID: Subject: Re: [python-win32] WMI troubles! > On 15/01/2010 19:38, Alex Hall wrote: >> I do not want a single script because, eventually, the plan is to have a >> keystroke for core 1, a keystroke for core 2, a keystroke for percent of >> ram used, a keystroke for hard disk space, and so on. While I could >> write each function in its own script and put a hotkey on each one, it >> seems easier and faster to just make one script and run it once, >> avoiding the delay I always get when this script runs for the first time >> from happening each time I press a hotkey. > > I've got slightly lost in this thread (not helped, I'm > afraid Alex, by your habit of top-posting ;) ) but in > an effort to be helpful, can I suggest the following. > Instead of fiddling with pyHooks which are -- as Tim R > points out -- somewhat dark and messy, consider adapting > the following example instead: > > http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html > > This uses a straightforward Windows message loop to > provide to sort of global hotkeys I think you're after. > You might, for example, change the handle_win_f3 > function to start a wmi instance (or use an existing > one) and then produce the output you were after. Thanks!! I "top post" since, when you use a screen reader, it is far easier to read a response straight away than it is to wade through a bunch of text you have already read, complete with many repetitions of "greater than". I will try to make in-line comments. Anyway, I have copied the example you provided and am about to go modify it. If it works, it should help a lot! I just hope it will clear up the wmi errors I keep getting... Thanks for the link! > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From mehgcap at gmail.com Sat Jan 16 01:26:17 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 19:26:17 -0500 Subject: [python-win32] syntax? Message-ID: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> Hi all I am getting a "syntax error" on the line def sayUsedRam(): and I am not sure why. Nothing is wrong with that line, but I was playing with the preceeding function when this started happening. Does anyone see anything obvious about these two functions that would cause an error? I do not always trust errors with line numbers to give me the right line number. Thanks in advance for any help. def sayLoad(): i=0 #get proc load, currently only first core for some reason load=[] for p in c.Win32_PerfFormattedData_PerfOS_Processor(): load.push(p.PercentProcessorTime) #speaker.say(str(load)) i=i+1 #end for speaker.say(str(load[0])+", "+str(load[1]) #end def def sayUsedRam(): #get total ram and ram available #then speak used ram as a percent, rounded to 1 place for info in c.Win32_OperatingSystem(): ram=info.TotalVisibleMemorySize freeRam=info.FreePhysicalMemory #end for #speaker.say(toBiggestBytes(freeRam,2)+". ") used=100-(float(freeRam)/float(ram)*100) speaker.say(str(round(used,1))+"% ram used.") #end def Have a great day, Alex Email: mehgcap at gmail.com From aahz at pythoncraft.com Sat Jan 16 01:55:35 2010 From: aahz at pythoncraft.com (Aahz) Date: Fri, 15 Jan 2010 16:55:35 -0800 Subject: [python-win32] syntax? In-Reply-To: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> References: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> Message-ID: <20100116005535.GA6401@panix.com> On Fri, Jan 15, 2010, Alex Hall wrote: > > I am getting a "syntax error" on the line > def sayUsedRam(): > and I am not sure why. Nothing is wrong with that line, but I was playing > with the preceeding function when this started happening. Does anyone see > anything obvious about these two functions that would cause an error? I > do not always trust errors with line numbers to give me the right line > number. You probably have an indentation error, but I can't tell because the code from your message had completely messed up indentation. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From mehgcap at gmail.com Sat Jan 16 02:53:28 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 20:53:28 -0500 Subject: [python-win32] letter and number key codes for win32con Message-ID: Hello all, I am successfully using hotkeys with win32con (thanks so much for that tip!!) but I want to use the numbers 1-0 (on the keyboard, not the numpad) instead of F keys. The code example I have says to use ord('x'), but I am not quite sure what this means or how to give the result of ord() to the hotkey dictionary. Does anyone know the codes to use? I have tried using win32con.49, win32con.VK_49, and all kinds of variants (using 1 instead of 49, using ord() right in the dictionary, using single quotes...) Google is not much help on this; the only forum I found talking about this said that it could not be done. Have a great day, Alex Email: mehgcap at gmail.com From timr at probo.com Sat Jan 16 03:51:20 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 15 Jan 2010 18:51:20 -0800 Subject: [python-win32] letter and number key codes for win32con In-Reply-To: References: Message-ID: <4B5129A8.1080108@probo.com> Alex Hall wrote: > > I am successfully using hotkeys with win32con (thanks so much for that > tip!!) but I want to use the numbers 1-0 (on the keyboard, not the > numpad) instead of F keys. The code example I have says to use > ord('x'), but I am not quite sure what this means or how to give the > result of ord() to the hotkey dictionary. Does anyone know the codes > to use? I have tried using win32con.49, win32con.VK_49, and all kinds > of variants (using 1 instead of 49, using ord() right in the > dictionary, using single quotes...) Google is not much help on this; > the only forum I found talking about this said that it could not be done. "ord" is a standard Python function that returns the numeric ASCII value of a character. The hotkey code for the 1 key is the ASCII value for the character '1', which is the plain, ordinary integer 49. You should be able to use either ord('1') or 49. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mehgcap at gmail.com Sat Jan 16 04:03:52 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 15 Jan 2010 22:03:52 -0500 Subject: [python-win32] letter and number key codes for win32con In-Reply-To: <4B5129A8.1080108@probo.com> References: <4B5129A8.1080108@probo.com> Message-ID: Subject: Re: [python-win32] letter and number key codes for win32con > Alex Hall wrote: >> >> I am successfully using hotkeys with win32con (thanks so much for that >> tip!!) but I want to use the numbers 1-0 (on the keyboard, not the >> numpad) instead of F keys. The code example I have says to use >> ord('x'), but I am not quite sure what this means or how to give the >> result of ord() to the hotkey dictionary. Does anyone know the codes >> to use? I have tried using win32con.49, win32con.VK_49, and all kinds >> of variants (using 1 instead of 49, using ord() right in the >> dictionary, using single quotes...) Google is not much help on this; >> the only forum I found talking about this said that it could not be done. > > "ord" is a standard Python function that returns the numeric ASCII value > of a character. The hotkey code for the 1 key is the ASCII value for > the character '1', which is the plain, ordinary integer 49. You should > be able to use either ord('1') or 49. Okay, the problem was that I was leaving on the "win32con." part, using "win32con.49" instead of just 49. It worked after I took off that win32con bit. > -- > 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 mail at timgolden.me.uk Sat Jan 16 08:07:02 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 16 Jan 2010 07:07:02 +0000 Subject: [python-win32] WMI troubles! In-Reply-To: References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC><4B50B4F6.1040704@probo.com><3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> <4B50D0AE.1060509@timgolden.me.uk> Message-ID: <4B516596.8040303@timgolden.me.uk> On 15/01/2010 20:57, Alex Hall wrote: > Thanks!! I "top post" since, when you use a screen reader, it is far > easier to read a response straight away than it is to wade through a > bunch of text you have already read, complete with many repetitions of > "greater than". I thought of that a few seconds after I sent the comment :) The main problem for me was that I was getting emails out of order (which happens often enough to be unsurprising). That, combined with the rapid series of exchanges between you and Tim Roberts all with a lot of text meant that I rather lost track. > Anyway, I have copied the example you provided and am about to go modify > it. If it works, it should help a lot! I just hope it will clear up the > wmi errors I keep getting... Thanks for the link! Hope it helps TJG From narisipalli at gmail.com Sun Jan 17 15:32:26 2010 From: narisipalli at gmail.com (Gowtham) Date: Sun, 17 Jan 2010 09:32:26 -0500 Subject: [python-win32] syntax? In-Reply-To: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> References: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> Message-ID: Hi Alex, I understand your code but its very difficult to read in python if the indentation is not clear. Run through the Python style guide - http://www.python.org/dev/peps/pep-0008/ or Google's pyguide - http://google-styleguide.googlecode.com/svn/trunk/pyguide.html Typical indentation is 4 spaces. Cheers. On Fri, Jan 15, 2010 at 7:26 PM, Alex Hall wrote: > Hi all > I am getting a "syntax error" on the line > def sayUsedRam(): > and I am not sure why. Nothing is wrong with that line, but I was playing > with the preceeding function when this started happening. Does anyone see > anything obvious about these two functions that would cause an error? I do > not always trust errors with line numbers to give me the right line number. > Thanks in advance for any help. > > def sayLoad(): > > i=0 > #get proc load, currently only first core for some reason > load=[] > for p in c.Win32_PerfFormattedData_PerfOS_Processor(): > load.push(p.PercentProcessorTime) > #speaker.say(str(load)) > > i=i+1 > #end for > speaker.say(str(load[0])+", "+str(load[1]) > #end def > > def sayUsedRam(): > > #get total ram and ram available > #then speak used ram as a percent, rounded to 1 place > > for info in c.Win32_OperatingSystem(): > ram=info.TotalVisibleMemorySize > freeRam=info.FreePhysicalMemory > #end for > #speaker.say(toBiggestBytes(freeRam,2)+". ") > used=100-(float(freeRam)/float(ram)*100) > speaker.say(str(round(used,1))+"% ram used.") > #end def > > > > Have a great day, > Alex > Email: mehgcap at gmail.com > _______________________________________________ > 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 kevin.horn at gmail.com Mon Jan 18 17:21:16 2010 From: kevin.horn at gmail.com (Kevin Horn) Date: Mon, 18 Jan 2010 10:21:16 -0600 Subject: [python-win32] syntax? In-Reply-To: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> References: <5DA9BA03F5534642BBA4F69CAA91FB7B@AlexPC> Message-ID: <562bcc11001180821h1724eb9ama6cad4bc0e304da8@mail.gmail.com> On Fri, Jan 15, 2010 at 6:26 PM, Alex Hall wrote: > Hi all > I am getting a "syntax error" on the line > def sayUsedRam(): > and I am not sure why. Nothing is wrong with that line, but I was playing > with the preceeding function when this started happening. Does anyone see > anything obvious about these two functions that would cause an error? I do > not always trust errors with line numbers to give me the right line number. > Thanks in advance for any help. > > def sayLoad(): > i=0 > #get proc load, currently only first core for some reason > load=[] > for p in c.Win32_PerfFormattedData_PerfOS_Processor(): > load.push(p.PercentProcessorTime) > #speaker.say(str(load)) > i=i+1 > #end for > speaker.say(str(load[0])+", "+str(load[1]) > #end def > > def sayUsedRam(): > #get total ram and ram available > #then speak used ram as a percent, rounded to 1 place > for info in c.Win32_OperatingSystem(): > ram=info.TotalVisibleMemorySize > freeRam=info.FreePhysicalMemory > #end for > #speaker.say(toBiggestBytes(freeRam,2)+". ") > used=100-(float(freeRam)/float(ram)*100) > speaker.say(str(round(used,1))+"% ram used.") > #end def > > > Have a great day, > Alex > Email: mehgcap at gmail.com > You appear to be missing a close paren on this line: speaker.say(str(load[0])+", "+str(load[1]) in the sayLoad() function Kevin Horn -------------- next part -------------- An HTML attachment was scrubbed... URL: From whateverwd at hotmail.com Wed Jan 20 04:16:21 2010 From: whateverwd at hotmail.com (Wesley Overhults) Date: Tue, 19 Jan 2010 21:16:21 -0600 Subject: [python-win32] pywin32 214 Problem Message-ID: So I have a new computer that runs Windows 7 and I have a program called Hellanzb that uses Python. I installed Python 2.5 and I installed pywin-32 214 but when I try to use Hellanzb, it gives me this message. "The program can't start because pywintypes25.dll is missing from your computer. Try reinstalling the program to fix this problem." I've reinstalled numerous times but nothing seems to work. pywintypes25.dll is on my computer. It's in the Python25 folder. Where should it be to get this program to work? _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/196390707/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From metolone+gmane at gmail.com Wed Jan 20 09:02:44 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Wed, 20 Jan 2010 00:02:44 -0800 Subject: [python-win32] pywin32 214 Problem References: Message-ID: "Wesley Overhults" wrote in message news:SNT108-W408B6AA1D92598D590F16BD2640 at phx.gbl... > So I have a new computer that runs Windows 7 and I have a program called > Hellanzb that uses Python. I installed Python 2.5 and I installed > pywin-32 214 but when I try to use Hellanzb, it gives me this message. > "The program can't start because pywintypes25.dll is missing from your > computer. Try reinstalling the program to fix this problem." > I've reinstalled numerous times but nothing seems to work. > pywintypes25.dll is on my computer. It's in the Python25 folder. Where > should it be to get this program to work? Sounds like a Windows manifest issue. Try Process Monitor from SysInternals if you want to determine where your system is looking for and failing to find pywintypes25.dll. It may give a clue what is wrong. HTH, Mark From skippy.hammond at gmail.com Wed Jan 20 12:36:19 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 20 Jan 2010 22:36:19 +1100 Subject: [python-win32] pywin32 214 Problem In-Reply-To: References: Message-ID: <4B56EAB3.2050702@gmail.com> On 20/01/2010 2:16 PM, Wesley Overhults wrote: > So I have a new computer that runs Windows 7 and I have a program called > Hellanzb that uses Python. I installed Python 2.5 and I installed > pywin-32 214 but when I try to use Hellanzb, it gives me this message. > > "The program can't start because pywintypes25.dll is missing from your > computer. Try reinstalling the program to fix this problem." > > I've reinstalled numerous times but nothing seems to work. > pywintypes25.dll is on my computer. It's in the Python25 folder. Where > should it be to get this program to work? I suspect you installed python "just for me" instead of for all users. try uninstalling python and reinstalling for all users, then reinstall pywin32. Cheers, Mark From Olof.Rutgersson at xelerated.com Wed Jan 20 15:57:53 2010 From: Olof.Rutgersson at xelerated.com (Olof Rutgersson) Date: Wed, 20 Jan 2010 15:57:53 +0100 Subject: [python-win32] wexpect and running without a console Message-ID: <987E17118F2F994D92C0EFD24784D10B1A34257840@xelwa4.xelerated.com> Hello I'm using wexpect to access various programs such as plink, cygwin and other command line tools in windows. The code works fine when the python interpreter is launched from a console window, but when I launch it through any other process (for instance, a scheduler for automation of certain tasks) I get an exception. The spawn call for creating a child process to the python process works (and really does spawn the child process), but as soon as I do an expect() call the following exception occurs: File "...\expect\wexpect.py", line 1330, in expect return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) File "...\expect\wexpect.py", line 1344, in expect_list return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) File "...\expect\wexpect.py", line 1397, in expect_loop c = self.read_nonblocking (self.maxread, timeout) File "...\expect\wexpect.py", line 1771, in read_nonblocking s = self.wtty.read_nonblocking(timeout, size) File "...\expect\wexpect.py", line 2149, in read_nonblocking self.switchBack() File "...\expect\wexpect.py", line 1975, in switchBack FreeConsole() error: (87, 'FreeConsole', 'The parameter is incorrect.') A closer look reveals that line 2149 is the exception handling of another error thrown: Traceback (most recent call last): File "...\expect\wexpect.py", line 2135, in read_nonblocking self.switchBack() File "...\expect\wexpect.py", line 1976, in switchBack AttachConsole(self.__parentPid) error: (6, 'AttachConsole', 'The handle is invalid.') The invalid handle error seems to be related to the fact that I'm not launching python.exe from a console but from another process, can it be related to issue 1124861 (http://bugs.python.org/issue1124861)? Do I need to create different stdin and stdout or spawn the child process in any other way from wexpect? Are there any other ways of solving this problem? The wexpect code used can be found at: http://wstein.org/home/goreckc/sage/wexpect/wexpect.py If this is not the correct mailing list, I apologize and hope that you can show me where to post my question. Olof Rutgersson System Test Engineer Xelerated AB Olof Palmes Gata 29 SE-111 22 Stockholm Sweden From m.echavarriagregory at umiami.edu Wed Jan 20 18:56:58 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Wed, 20 Jan 2010 12:56:58 -0500 Subject: [python-win32] How to use data on disk in this generator Message-ID: <2E95F75EDC25D54999387A1E2E6EF6274349045A57@MBX02.cgcent.miami.edu> Good afternoon, I use PythonWin32 in my XP machine. I am programming an application and have trouble with memory when using the sumComb list below, that has a size of 2,657,205 elements. I DO NEED this many elements because they are product of combinatorial math operations. To solve my memory problem I created a file on disk that stores the elements of the list as they are created. Now, I need to use the 'list' in a generator and have not been able to replicate the effect without actually calling/storing the list in memory, that is, using the data directly from the file on disk: I need to mimic what the following generator does: def validList(sumComb, GammaPossible, valid): for l in sumComb: for m in sumComb: for n in sumComb: k = [l,m,n] i = 0 while i < valid: C = 0 j = 0 while j < 3: C = C +((GammaPossible[i][j])*k[j]) j += 1 yield C i += 1 By not using the list sumComb in memory, but having its elements in a file F writen using F = open("my_list.txt", "w") and where elements are stored with column "/n" separation. I have not been able to find the appropriate syntax for the nested 'for' loops to replace sumComb list by using F.readlines(), str.split(), etc. Please help me with this little challenge. Angelica. From aahz at pythoncraft.com Wed Jan 20 20:07:08 2010 From: aahz at pythoncraft.com (Aahz) Date: Wed, 20 Jan 2010 11:07:08 -0800 Subject: [python-win32] How to use data on disk in this generator In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274349045A57@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274349045A57@MBX02.cgcent.miami.edu> Message-ID: <20100120190707.GA6662@panix.com> On Wed, Jan 20, 2010, Echavarria Gregory, Maria Angelica wrote: > > I use PythonWin32 in my XP machine. I am programming an application > and have trouble with memory when using the sumComb list below, that > has a size of 2,657,205 elements. I DO NEED this many elements because > they are product of combinatorial math operations. To solve my memory > problem I created a file on disk that stores the elements of the list > as they are created. Now, I need to use the 'list' in a generator > and have not been able to replicate the effect without actually > calling/storing the list in memory, that is, using the data directly > from the file on disk: This doesn't seem like a win32-specific issue -- you may get better responses by posting to comp.lang.python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair From m.echavarriagregory at umiami.edu Wed Jan 20 20:22:19 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Wed, 20 Jan 2010 14:22:19 -0500 Subject: [python-win32] How to use data on disk in this generator In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274349045A57@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274349045A57@MBX02.cgcent.miami.edu> Message-ID: <2E95F75EDC25D54999387A1E2E6EF6274349045A5A@MBX02.cgcent.miami.edu> Good afternoon, I use PythonWin32 in my XP machine. I am programming an application and have trouble with memory when using the sumComb list below, that has a size of 2,657,205 elements. I DO NEED this many elements because they are product of combinatorial math operations. To solve my memory problem I created a file on disk that stores the elements of the list as they are created. Now, I need to use the 'list' in a generator and have not been able to replicate the effect without actually calling/storing the list in memory, that is, using the data directly from the file on disk: I need to mimic what the following generator does: def validList(sumComb, GammaPossible, valid): for l in sumComb: for m in sumComb: for n in sumComb: k = [l,m,n] i = 0 while i < valid: C = 0 j = 0 while j < 3: C = C +((GammaPossible[i][j])*k[j]) j += 1 yield C i += 1 By not using the list sumComb in memory, but having its elements in a file F writen using F = open("my_list.txt", "w") and where elements are stored with column "/n" separation. I have not been able to find the appropriate syntax for the nested 'for' loops to replace sumComb list by using F.readlines(), str.split(), etc. Please help me with this little challenge. Angelica. From skippy.hammond at gmail.com Wed Jan 20 23:22:10 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 21 Jan 2010 09:22:10 +1100 Subject: [python-win32] wexpect and running without a console In-Reply-To: <987E17118F2F994D92C0EFD24784D10B1A34257840@xelwa4.xelerated.com> References: <987E17118F2F994D92C0EFD24784D10B1A34257840@xelwa4.xelerated.com> Message-ID: <4B578212.7020907@gmail.com> On 21/01/2010 1:57 AM, Olof Rutgersson wrote: > The invalid handle error seems to be related to the fact that I'm not launching python.exe from a console but from another process, can it be related to issue 1124861 (http://bugs.python.org/issue1124861)? Do I need to create different stdin and stdout or spawn the child process in any other way from wexpect? Are there any other ways of solving this problem? The error is because there is no console, but wexpect is attempting to use one. The solution is to fix the code that assumes a console always exists - it doesn't. I think you need to talk to the wexpect guys and see if either (a) you are misusing wexpect or (b) it is a bug in wexpect. Cheers, Mark From Olof.Rutgersson at xelerated.com Thu Jan 21 11:46:58 2010 From: Olof.Rutgersson at xelerated.com (Olof Rutgersson) Date: Thu, 21 Jan 2010 11:46:58 +0100 Subject: [python-win32] wexpect and running without a console In-Reply-To: <4B578212.7020907@gmail.com> References: <987E17118F2F994D92C0EFD24784D10B1A34257840@xelwa4.xelerated.com> <4B578212.7020907@gmail.com> Message-ID: <987E17118F2F994D92C0EFD24784D10B1A342579F7@xelwa4.xelerated.com> Seems reasonable to me, I don't believe there is an error in my code since it works perfectly running from console and this error occurs instantly when NOT running from console. There is no way when accessing Wexpect to instruct it that Python is running without a console, and there should be no need to either (IMHO). Wexpect doesn't seem to have that much of a development going on, so I guess it's up to me to fix it (or run it on Linux/cygwin and use Pexpect instead). Thanks for the help! //Olof Rutgersson -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: den 20 januari 2010 23:22 To: Olof Rutgersson Cc: python-win32 at python.org Subject: Re: [python-win32] wexpect and running without a console On 21/01/2010 1:57 AM, Olof Rutgersson wrote: > The invalid handle error seems to be related to the fact that I'm not launching python.exe from a console but from another process, can it be related to issue 1124861 (http://bugs.python.org/issue1124861)? Do I need to create different stdin and stdout or spawn the child process in any other way from wexpect? Are there any other ways of solving this problem? The error is because there is no console, but wexpect is attempting to use one. The solution is to fix the code that assumes a console always exists - it doesn't. I think you need to talk to the wexpect guys and see if either (a) you are misusing wexpect or (b) it is a bug in wexpect. Cheers, Mark From planders at gmail.com Fri Jan 22 22:31:04 2010 From: planders at gmail.com (Preston Landers) Date: Fri, 22 Jan 2010 15:31:04 -0600 Subject: [python-win32] odbc module and Unicode string literals Message-ID: <796c415c1001221331m33cf932xd0fa26320af6a15f@mail.gmail.com> Hello all, I'm curious why the odbc module included in PyWin32 (version 214) is compiled without the Unicode flags/defines. This prevents you from using Unicode string literals in queries. By that I mean the Unicode literals are converted to the 8-bit codepage (cp1252) and any untranslatable characters are replaced with ?. Unicode works ok in bind variables, just not as literals in the main query. That is, unless I set the Unicode flag to True for odbc in PyWin32 setup.py around line 1441. Then the resulting odbc module seems to handle Unicode literals just fine. The test script included below should demonstrate that. The ADO module (adodbapi) doesn't have this issue - Unicode literals work ok. But it suffers from a few other problems, the most basic one is a performance gap of 25-30% compared to ODBC even after I generated the bindings with makepy. I assume this is due to general COM overhead. I can compile my own odbc module with the Unicode flag but I'm curious if there was a reason it was turned off to begin with. Maybe I'm missing something or would run into trouble later if I did that. thanks, -Preston # Note: the goal should be to get "unicode intact" twice. # First time is using a bind variable, second time is a string literal. # This assumes SQL Server backend - string literals are prefixed with N import odbc # Change to suit your server CONNSTR = "dsn/username/password" db = odbc.odbc(CONNSTR) cursor = db.cursor() # This has some extra-wide characters (surrogate pairs) testStr = u"\u0669(\u0361\u0e4f\u032f\u0361\u0e4f)\u06f6 .\U0002a5ab\U0001d122\U00024b00" def query(sql, params): cursor.execute(sql, params) recs = cursor.fetchall() print repr(sql), repr(params) print repr(recs) if recs[0][0] == testStr: print "unicode intact." else: print "unicode did not survive round trip" print return recs # Test as bind variable query1 = "select ? as 'test'" query(query1, [testStr]) # Test as straight Unicode literal query2 = "select N'%s' as 'test'" % (testStr,) query(query2, []) From whatyoulookin at yahoo.com Fri Jan 22 23:03:53 2010 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Fri, 22 Jan 2010 14:03:53 -0800 (PST) Subject: [python-win32] Problem accessing GetFontData in Windows API Message-ID: <225358.35751.qm@web112604.mail.gq1.yahoo.com> I'm trying to access the following function from the Windows API: http://msdn.microsoft.com/en-us/library/dd144885(VS.85).aspx I'm sure I'm drastically over simplifying, but I'm testing it like this: import win32api print win32api.GetFontData() This of course errors out with "AttributeError: function 'GetFontData' not found". Does anyone have any tips on how I might access this function? I need to resolve the font face name (for example, "Arial") as returned by wxPython, to the Windows filename (for example, c:\windows\fonts\arial.ttf) as required by the Image module, and it looks like GetFontData() from the Windows API is the solution. From planders at gmail.com Fri Jan 22 23:40:32 2010 From: planders at gmail.com (Preston Landers) Date: Fri, 22 Jan 2010 16:40:32 -0600 Subject: [python-win32] Problem accessing GetFontData in Windows API Message-ID: > I'm trying to access the following function from the Windows API: > > http://msdn.microsoft.com/en-us/library/dd144885(VS.85).aspx > > I'm sure I'm drastically over simplifying, but I'm testing it like this: > > import win32api > print win32api.GetFontData() > > This of course errors out with "AttributeError: function 'GetFontData' not found". I'm not 100% sure but I think you're going to need to use ctypes to call that. It's a little complicated but this may help: http://python.net/crew/theller/ctypes/tutorial.html >>> from ctypes import * >>> windll.gdi32 >>> windll.gdi32.GetFontData <_FuncPtr object at 0x000000000273B2B8> -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Jan 22 23:51:09 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 22 Jan 2010 14:51:09 -0800 Subject: [python-win32] Problem accessing GetFontData in Windows API In-Reply-To: <225358.35751.qm@web112604.mail.gq1.yahoo.com> References: <225358.35751.qm@web112604.mail.gq1.yahoo.com> Message-ID: <4B5A2BDD.1070909@probo.com> Alec Bennett wrote: > I'm trying to access the following function from the Windows API: > > http://msdn.microsoft.com/en-us/library/dd144885(VS.85).aspx > > I'm sure I'm drastically over simplifying, but I'm testing it like this: > > import win32api > print win32api.GetFontData() > > This of course errors out with "AttributeError: function 'GetFontData' not found". > > Does anyone have any tips on how I might access this function? I need to resolve the font face name (for example, "Arial") as returned by wxPython, to the Windows filename (for example, c:\windows\fonts\arial.ttf) as required by the Image module, and it looks like GetFontData() from the Windows API is the solution. > Although it IS possible to find this information using the API, it is quite tedious. You'd need to have a DC, create an HFONT, select it into the DC, then run GetOutlineTextMetrics, which is not a Python-friendly API. You get back a long structure where some members include the offset to the strings you need. A much better solution is to search through the registry values in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts. That maps each font name to its corresponding file name. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From whatyoulookin at yahoo.com Sat Jan 23 03:02:17 2010 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Fri, 22 Jan 2010 18:02:17 -0800 (PST) Subject: [python-win32] Problem accessing GetFontData in Windows API In-Reply-To: <4B5A2BDD.1070909@probo.com> Message-ID: <718852.22422.qm@web112608.mail.gq1.yahoo.com> > A much better solution is to search through the registry > values in HKLM\SOFTWARE\Microsoft\Windows Three things concern me with this method: 1) if I understand correctly, Windows appends the language to the font title. In other words, for German the Arial font is "arial german". Normally this wouldn't be the biggest issue in the world, but there are often multiple font names with the same string in them, one for bold, one for italic, etc., so its not simply a matter of returning any entry with the name "arial" in it. 2) under Vista 64-bit I've been getting permission denied errors when trying to read the registry using winreg. 3) its a kludge and bound to be inaccurate on some systems. But yeah, it looks like it might be my best option. From timr at probo.com Sat Jan 23 03:40:34 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 22 Jan 2010 18:40:34 -0800 Subject: [python-win32] Problem accessing GetFontData in Windows API In-Reply-To: <718852.22422.qm@web112608.mail.gq1.yahoo.com> References: <718852.22422.qm@web112608.mail.gq1.yahoo.com> Message-ID: <4B5A61A2.8020301@probo.com> Alec Bennett wrote: >> A much better solution is to search through the registry >> values in HKLM\SOFTWARE\Microsoft\Windows >> > > Three things concern me with this method: > > 1) if I understand correctly, Windows appends the language to the font title. In other words, for German the Arial font is "arial german". Normally this wouldn't be the biggest issue in the world, but there are often multiple font names with the same string in them, one for bold, one for italic, etc., so its not simply a matter of returning any entry with the name "arial" in it. > There is no "Arial German". That's the whole point of Unicode and TrueType. All language glyphs are in one file. You would have to deal with bold, italic, and bold italic, but those are in the listing. If you have antique raster fonts, it's possible you could come across this, but those are separate files, so I think that's what you want. > 2) under Vista 64-bit I've been getting permission denied errors when trying to read the registry using winreg. > Even if you set read-only? I thought HKEY_LOCAL_MACHINE was readable but not writable. > 3) its a kludge and bound to be inaccurate on some systems. > Not really -- this is the same database used by the system's font manager. That data is not simply decorative. It's no more kludgy than using OUTLINETEXTMETRICS -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From whatyoulookin at yahoo.com Sat Jan 23 04:19:41 2010 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Fri, 22 Jan 2010 19:19:41 -0800 (PST) Subject: [python-win32] Problem accessing GetFontData in Windows API In-Reply-To: <4B5A61A2.8020301@probo.com> Message-ID: <276251.93560.qm@web112603.mail.gq1.yahoo.com> Thanks for the tips. Using that method I'm able to obtain the filename for about 75% of the fonts in my Windows directory, but I can't resolve fonts with names such as this: - the font's name is Arno Pro. It shows up in font choosers with names like "Arno Pro", "Arno Pro Caption", "Arno Pro Display", etc. - however, no such names appear in the Windows font directory/registry. This font appears as, for example, "ArnoPro-Regular", "ArnoPro-Caption", "ArnoPro-Display". I don't imagine you can think of a way to obtain the file name for fonts with that sort of naming convention? I have to leave now but I can post a sample app later. From skippy.hammond at gmail.com Sun Jan 24 03:27:52 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sun, 24 Jan 2010 13:27:52 +1100 Subject: [python-win32] odbc module and Unicode string literals In-Reply-To: <796c415c1001221331m33cf932xd0fa26320af6a15f@mail.gmail.com> References: <796c415c1001221331m33cf932xd0fa26320af6a15f@mail.gmail.com> Message-ID: <4B5BB028.6040208@gmail.com> On 23/01/2010 8:31 AM, Preston Landers wrote: > Hello all, > > I'm curious why the odbc module included in PyWin32 (version 214) is > compiled without the Unicode flags/defines. No good reason I am aware of. If you submit a patch, it included some tests and no-one else who actually uses this module objects, I'll apply it. Cheers, Mark From lyeoh at pop.jaring.my Sun Jan 24 15:07:35 2010 From: lyeoh at pop.jaring.my (Lincoln Yeoh) Date: Sun, 24 Jan 2010 22:07:35 +0800 Subject: [python-win32] Getting a list of "task buttons" or tasks/windows in the "alt-tab" list? In-Reply-To: <201001131832.o0DIWJPw019549@vsmtp6.jaring.my> References: <201001131832.o0DIWJPw019549@vsmtp6.jaring.my> Message-ID: <201001241408.o0OE84YA044194@vsmtp3.jaring.my> Anyway to answer my own question :). Excel's main window has an "ITaskList_Deleted" window property if the dummy windows exist. Powerpoint behaves very similarly. And Kingsoft Office appears to do something like that except without the ITaskList_Deleted window property. Link. At 02:32 AM 1/14/2010, Lincoln Yeoh wrote: >Hi, > >With python win32 is there a way to get only the windows that are >represented by the buttons of the Windows taskbar (or the windows >listed in the "alt-tab" list)? > >I have found various ways of doing so, but I can't seem to get them >to work with Excel's windows. > > From what I observe (I may be wrong though), Excel by default > appears to have a main window and some "dummy windows" > (classname=MS-SDIb) representing the opened Excel documents. If you > click on those "dummy windows" the relevant excel document gets > foregrounded in the _main_ window (not the dummy windows). > >If three Excel documents are opened, there are four top level Excel >windows (or at least they appear to be top level to me) - the main, >and three MS-SDIb ones. But the taskbar and alt-tab list only show 3 >items. What logic should one use to create the same list? From lyeoh at pop.jaring.my Sun Jan 24 15:31:56 2010 From: lyeoh at pop.jaring.my (Lincoln Yeoh) Date: Sun, 24 Jan 2010 22:31:56 +0800 Subject: [python-win32] WMI troubles! In-Reply-To: <4B50D0AE.1060509@timgolden.me.uk> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B50B4F6.1040704@probo.com> <3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> <4B50D0AE.1060509@timgolden.me.uk> Message-ID: <201001241432.o0OEWIOF035248@vsmtp6.jaring.my> Hi, Coincidentally I'm using the hotkey code from Tim's url and it works quite well. But I'm not sure which is better: user32.GetMessageA or user32.GetMessageW (along with the corresponding user32.DispatchMessageA or user32.DispatchMessageW of course). Regards, Link. At 04:31 AM 1/16/2010, Tim Golden wrote: >On 15/01/2010 19:38, Alex Hall wrote: >>I do not want a single script because, eventually, the plan is to have a >>keystroke for core 1, a keystroke for core 2, a keystroke for percent of >>ram used, a keystroke for hard disk space, and so on. While I could >>write each function in its own script and put a hotkey on each one, it >>seems easier and faster to just make one script and run it once, >>avoiding the delay I always get when this script runs for the first time >>from happening each time I press a hotkey. > >I've got slightly lost in this thread (not helped, I'm >afraid Alex, by your habit of top-posting ;) ) but in >an effort to be helpful, can I suggest the following. >Instead of fiddling with pyHooks which are -- as Tim R >points out -- somewhat dark and messy, consider adapting >the following example instead: > >http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html > >This uses a straightforward Windows message loop to >provide to sort of global hotkeys I think you're after. >You might, for example, change the handle_win_f3 >function to start a wmi instance (or use an existing >one) and then produce the output you were after. > >TJG >_______________________________________________ >python-win32 mailing list >python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From timr at probo.com Mon Jan 25 18:01:13 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 25 Jan 2010 09:01:13 -0800 Subject: [python-win32] Problem accessing GetFontData in Windows API In-Reply-To: <276251.93560.qm@web112603.mail.gq1.yahoo.com> References: <276251.93560.qm@web112603.mail.gq1.yahoo.com> Message-ID: <4B5DCE59.4030401@probo.com> Alec Bennett wrote: > Thanks for the tips. > > Using that method I'm able to obtain the filename for about 75% of the fonts in my Windows directory, but I can't resolve fonts with names such as this: > > - the font's name is Arno Pro. It shows up in font choosers with names like "Arno Pro", "Arno Pro Caption", "Arno Pro Display", etc. > > - however, no such names appear in the Windows font directory/registry. This font appears as, for example, "ArnoPro-Regular", "ArnoPro-Caption", "ArnoPro-Display". > > I don't imagine you can think of a way to obtain the file name for fonts with that sort of naming convention? > Yecch. Yes, this is ugly. TrueType font have several names, including a "full name" and a "PostScript name", where the PostScript name must be ASCII and usually has no spaces. I'm not sure I have an answer for this problem. In the worst case, I suppose you could do like GIMP does, and scan through %SystemRoot%\Fonts on your own. You could cache the information so you only checked files that had changed. The alternative is to go through the trouble of constructing a ctypes wrapper for GetOutlineTextMetrics. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Mon Jan 25 19:06:52 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 25 Jan 2010 10:06:52 -0800 Subject: [python-win32] WMI troubles! In-Reply-To: <201001241432.o0OEWIOF035248@vsmtp6.jaring.my> References: <558CA385CC304B349F3FEB6D62A466DC@AlexPC> <4B50B4F6.1040704@probo.com> <3164DF6271584B1098783412B56698DB@AlexPC> <4B50C009.10300@probo.com> <4B50D0AE.1060509@timgolden.me.uk> <201001241432.o0OEWIOF035248@vsmtp6.jaring.my> Message-ID: <4B5DDDBC.5020403@probo.com> Lincoln Yeoh wrote: > Hi, > > Coincidentally I'm using the hotkey code from Tim's url and it works > quite well. > > But I'm not sure which is better: > > user32.GetMessageA or user32.GetMessageW (along with the corresponding > user32.DispatchMessageA or user32.DispatchMessageW of course). That depends on the messages you're handling. For some messages, WPARAM and LPARAM point to structures that contain strings. For those, you need to know the character type. If there are no strings, then it doesn't matter which one you choose. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From admin at genesisware.de Wed Jan 27 09:03:07 2010 From: admin at genesisware.de (Stefan George) Date: Wed, 27 Jan 2010 09:03:07 +0100 Subject: [python-win32] Visibility information Message-ID: <000e01ca9f27$2984cb30$7c8e6190$@de> Good morning PyWin32-users, I am using the PyWin32 package and I am wondering if there is any way to get visibility information of a button (I only know the handle). Is that possible and is there any code snippet, you could pass to me? I am looking for something like isVisible(hwnd) returns True or False. Thank you! Greetings from Germany, Stefan George -------------- next part -------------- An HTML attachment was scrubbed... URL: From efotinis at yahoo.com Wed Jan 27 09:49:36 2010 From: efotinis at yahoo.com (Elias Fotinis) Date: Wed, 27 Jan 2010 10:49:36 +0200 Subject: [python-win32] Visibility information In-Reply-To: <000e01ca9f27$2984cb30$7c8e6190$@de> References: <000e01ca9f27$2984cb30$7c8e6190$@de> Message-ID: <745659D81FA14AC894C51C132EBDDC78@efcore> From: Stefan George > I am using the PyWin32 package and I am wondering if there is any way to > get visibility information of a button (I only know the handle). > Is that possible and is there any code snippet, you could pass to me? > > I am looking for something like isVisible(hwnd) returns True or False. It's pretty simple: import win32gui button_handle = ... is_visible = win32gui.IsWindowVisible(button_handle) The win32gui contains all GUI related Windows API functions. PyWin32's help file is great for looking up Windows functions and their respective modules. Just switch to the Index tab, type the function name and you'll find a help page with the parameters, return type and containing module of each API function. From stef.mientki at gmail.com Wed Jan 27 15:12:37 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 27 Jan 2010 15:12:37 +0100 Subject: [python-win32] Maybe the wrong newsgroup to ask ? Message-ID: <4B6049D5.6050407@gmail.com> hello, I'm trying to kill processes, I started myself with subprocess.popen, under windows XP, Python 2.6 Why are the subprocess.Popen methods kill() and terminate () not working, while a simple suggestion from this newsgroup, shown below, works perfect ? thanks, Stef Mientki My_Process = subprocess.popen ( ...) handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, My_Process.PID) try: win32api.TerminateProcess(handle,0) win32api.CloseHandle(handle) except: #the process might already be closed by the user pass -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sunny.Carter at metaswitch.com Wed Jan 27 17:21:01 2010 From: Sunny.Carter at metaswitch.com (Sunny Carter) Date: Wed, 27 Jan 2010 16:21:01 +0000 Subject: [python-win32] Boolean type changed in Python 3.0? In-Reply-To: <4B42F11D.3010109@gmail.com> References: <44EE1E31095AE349AC6C3C0B69FFBF02932E0B3D6F@ENFIMBOX1.ad.datcon.co.uk> <4B42F11D.3010109@gmail.com> Message-ID: <44EE1E31095AE349AC6C3C0B69FFBF02932F2F7D43@ENFIMBOX1.ad.datcon.co.uk> Mark - just wondered if you had any update on this? I'm very happy to run some diagnostic tests for you on my setup, if this would help? If you need to send me debug versions or anything then please do, or let me know if I can provide any further info that would help to diagnose. I can do my best to net down the problem and promise not to just spam you with any output - I spend my days debugging various other problems so am pretty familiar with providing useful info. Thanks, appreciate it. Sunny -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: 05 January 2010 07:58 To: Sunny Carter Cc: python-win32 at python.org Subject: Re: [python-win32] Boolean type changed in Python 3.0? On 5/01/2010 3:51 AM, Sunny Carter wrote: > Hi all, > I'm trying my posting again with a different subject so that it is > more generic. > I am having problems calling across the win32 API using a Boolean > argument in Python 3.0 (False in my python script) which is not > recognised as a Boolean (The error I get back from setattr is 'Boolean > value expected'). > Has the way that a Boolean is represented changed in Python 3.0? This > worked fine in Python 2.6. I cannot get it to work and have tried > values of False,True,0 and 1, all to no avail. > It sounds like a bug in the win32com API for 3.0 to me. > Further details below. > Many thanks to anyone that can help, I expect something subtle is going on with boolean conversions in 3.x, but the test suite does have coverage of booleans, so I'm really not sure what the problem could be. I don't have photoshop so I'm unable to reproduce - I intend revisiting the tests to see if I can spot an edge case which isn't tested, but I'm yet to get to that after the holidays... Cheers, Mark From skippy.hammond at gmail.com Wed Jan 27 18:28:27 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 27 Jan 2010 09:28:27 -0800 Subject: [python-win32] Boolean type changed in Python 3.0? In-Reply-To: <44EE1E31095AE349AC6C3C0B69FFBF02932F2F7D43@ENFIMBOX1.ad.datcon.co.uk> References: <44EE1E31095AE349AC6C3C0B69FFBF02932E0B3D6F@ENFIMBOX1.ad.datcon.co.uk> <4B42F11D.3010109@gmail.com> <44EE1E31095AE349AC6C3C0B69FFBF02932F2F7D43@ENFIMBOX1.ad.datcon.co.uk> Message-ID: <4B6077BB.5020109@gmail.com> On 27/01/2010 8:21 AM, Sunny Carter wrote: > Mark - just wondered if you had any update on this? I believe Roger checked a fix in for this over the last few days. I'm not sure when a new binary build will be available though, but probably not within a few weeks... Cheers, Mark From Sunny.Carter at metaswitch.com Wed Jan 27 19:34:04 2010 From: Sunny.Carter at metaswitch.com (Sunny Carter) Date: Wed, 27 Jan 2010 18:34:04 +0000 Subject: [python-win32] Boolean type changed in Python 3.0? In-Reply-To: <4B6077BB.5020109@gmail.com> References: <44EE1E31095AE349AC6C3C0B69FFBF02932E0B3D6F@ENFIMBOX1.ad.datcon.co.uk> <4B42F11D.3010109@gmail.com> <44EE1E31095AE349AC6C3C0B69FFBF02932F2F7D43@ENFIMBOX1.ad.datcon.co.uk> <4B6077BB.5020109@gmail.com> Message-ID: <44EE1E31095AE349AC6C3C0B69FFBF02932F2F7EEB@ENFIMBOX1.ad.datcon.co.uk> Fabulous - thanks for the update. Sunny -----Original Message----- From: Mark Hammond [mailto:skippy.hammond at gmail.com] Sent: 27 January 2010 17:28 To: Sunny Carter Cc: python-win32 at python.org Subject: Re: [python-win32] Boolean type changed in Python 3.0? On 27/01/2010 8:21 AM, Sunny Carter wrote: > Mark - just wondered if you had any update on this? I believe Roger checked a fix in for this over the last few days. I'm not sure when a new binary build will be available though, but probably not within a few weeks... Cheers, Mark From timr at probo.com Wed Jan 27 20:07:57 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 27 Jan 2010 11:07:57 -0800 Subject: [python-win32] Maybe the wrong newsgroup to ask ? In-Reply-To: <4B6049D5.6050407@gmail.com> References: <4B6049D5.6050407@gmail.com> Message-ID: <4B608F0D.3010607@probo.com> Stef Mientki wrote: > > I'm trying to kill processes, > I started myself with subprocess.popen, > under windows XP, Python 2.6 > > Why are the subprocess.Popen methods kill() and terminate () not working, > while a simple suggestion from this newsgroup, shown below, works > perfect ? > ... > > My_Process = subprocess.popen ( ...) > handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, > My_Process.PID) > try: > win32api.TerminateProcess(handle,0) > win32api.CloseHandle(handle) > except: #the process might already be closed by the user > pass There shouldn't be any difference. If you look at the code in subprocess. it calls the same API. The handle returned from CreateProcess has all access rights, including PROCESS_TERMINATE. Can you show us your original code? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From stef.mientki at gmail.com Wed Jan 27 20:45:56 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 27 Jan 2010 20:45:56 +0100 Subject: [python-win32] Maybe the wrong newsgroup to ask ? In-Reply-To: <4B608F0D.3010607@probo.com> References: <4B6049D5.6050407@gmail.com> <4B608F0D.3010607@probo.com> Message-ID: <4B6097F4.8010003@gmail.com> On 27-01-2010 20:07, Tim Roberts wrote: > Stef Mientki wrote: > >> I'm trying to kill processes, >> I started myself with subprocess.popen, >> under windows XP, Python 2.6 >> >> Why are the subprocess.Popen methods kill() and terminate () not working, >> while a simple suggestion from this newsgroup, shown below, works >> perfect ? >> ... >> >> My_Process = subprocess.popen ( ...) >> handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, >> My_Process.PID) >> try: >> win32api.TerminateProcess(handle,0) >> win32api.CloseHandle(handle) >> except: #the process might already be closed by the user >> pass >> > There shouldn't be any difference. If you look at the code in > subprocess. it calls the same API. The handle returned from > CreateProcess has all access rights, including PROCESS_TERMINATE. > > Can you show us your original code? > > Good Question Tim. Showing the code is always difficult for me, because I encapsulate these complex things. The code I gave above doesn't work either :-) I use a kill method that also kills the children and seems to be the essential thing is this situation, (btw why are there children ?) thanks for the tip, cheers, Stef import os import subprocess import time if __name__ == '__main__': My_Path = os.path.split ( __file__ ) [0] cwd = os.path.join ( My_Path, '..', 'Pylab_Works', 'pylab_works_programs', 'PyJamas_Test') filename = os.path.join ( cwd, 'Een_Vraag_Test.py' ) Process = subprocess.Popen ( [ 'python', filename ], cwd = cwd , shell = ( os.name == 'nt') ) print Process.pid time.sleep ( 5 ) Process.kill () #Process.terminate () print 'Kill or terminate Doesnt succeed' time.sleep ( 2 ) import win32api import win32con handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, Process.pid) try: win32api.TerminateProcess(handle,0) win32api.CloseHandle(handle) #close api except: #the process might already be closed by the user pass print 'This still Doesnt works' time.sleep ( 2 ) PID = Process.pid Children = [] import win32com.client WMI = win32com.client.GetObject ( 'winmgmts:' ) processes = WMI.InstancesOf ( 'Win32_Process' ) for process in processes: pid = process.Properties_ ( 'ProcessID' ).Value parent = process.Properties_ ( 'ParentProcessId' ).Value if parent == PID : Children.append ( pid ) #Insert the parent at the top Children.insert ( 0, PID ) import win32api import win32con for PID in Children : handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, PID) try: win32api.TerminateProcess(handle,0) win32api.CloseHandle(handle) except: #the process might already be closed by the user pass print 'Finally this works' From twhitema at yahoo.com.au Wed Jan 27 23:05:45 2010 From: twhitema at yahoo.com.au (Todd Whiteman) Date: Wed, 27 Jan 2010 14:05:45 -0800 Subject: [python-win32] Maybe the wrong newsgroup to ask ? In-Reply-To: <4B6049D5.6050407@gmail.com> References: <4B6049D5.6050407@gmail.com> Message-ID: <4B60B8B9.5010303@yahoo.com.au> On 10-01-27 06:12 AM, Stef Mientki wrote: > hello, > > I'm trying to kill processes, > I started myself with subprocess.popen, > under windows XP, Python 2.6 > > Why are the subprocess.Popen methods kill() and terminate () not working, > while a simple suggestion from this newsgroup, shown below, works perfect ? Note that the kill method will not kill any child processes. If you want to be able to kill the launched process and all of it's child processes, see here: http://benjamin.smedbergs.us/blog/2006-12-11/killableprocesspy/ Cheers, Todd From timr at probo.com Thu Jan 28 00:08:18 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 27 Jan 2010 15:08:18 -0800 Subject: [python-win32] Maybe the wrong newsgroup to ask ? In-Reply-To: <4B6097F4.8010003@gmail.com> References: <4B6049D5.6050407@gmail.com> <4B608F0D.3010607@probo.com> <4B6097F4.8010003@gmail.com> Message-ID: <4B60C762.7080401@probo.com> Stef Mientki wrote: > > Showing the code is always difficult for me, because I encapsulate > these complex things. > The code I gave above doesn't work either :-) > I use a kill method that also kills the children and seems to be the > essential thing is this situation, > (btw why are there children ?) There are child processes because you are setting "shell" to true. Thus, subprocess actually launches cmd.exe, and cmd.exe launches Python. Is there a reason you need a subshell, or was that superstition? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From usfree74 at gmail.com Thu Jan 28 00:19:49 2010 From: usfree74 at gmail.com (Xin Zhao) Date: Wed, 27 Jan 2010 15:19:49 -0800 Subject: [python-win32] makepy or genpy issue: no get_accChildCount? Message-ID: Hey, I am trying to use pywin32 to do program automation. Basically, I need to get an IAccessible object and call functions on it. Here is what I did: x = pythoncom.AccessibleObjectFromWindow(3803742, 0, pythoncom.IID_IDispatch) (3803742 is the HWND of an internet explorer window) Then I do: z = win32com.client.gencache.EnsureDispatch(x) Now "z" is an IAccessiable object: win32com.gen_py.1EA4DBF0-3C3B-11CF-810C-00AA00389B71x0x1x1.IAccessible.IAccessible instance at 0x15279168 But when I did "dir(z)", I only see: ['CLSID', 'GetaccDefaultAction', 'GetaccDescription', 'GetaccHelp', 'GetaccHelpTopic', 'GetaccKeyboardShortcut', 'Getacc Name', 'GetaccRole', 'GetaccState', 'GetaccValue', 'SetaccName', 'SetaccValue', '_ApplyTypes_', '__doc__', '__eq__', '__ getattr__', '__init__', '__module__', '__ne__', '__repr__', '__setattr__', '_get_good_object_', '_get_good_single_object _', '_oleobj_', '_prop_map_get_', '_prop_map_put_', 'accChild', 'accDoDefaultAction', 'accHitTest', 'accLocation', 'accN avigate', 'accSelect', 'coclass_clsid'] Although MSDN lists function *get_accChildCount* as a function IAccessible must support, I don't see it in the method list of "z". Why? Please help! Thanks a lot! xin -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Thu Jan 28 00:23:10 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 28 Jan 2010 00:23:10 +0100 Subject: [python-win32] Maybe the wrong newsgroup to ask ? In-Reply-To: <4B60C762.7080401@probo.com> References: <4B6049D5.6050407@gmail.com> <4B608F0D.3010607@probo.com> <4B6097F4.8010003@gmail.com> <4B60C762.7080401@probo.com> Message-ID: <4B60CADE.4070908@gmail.com> On 28-01-2010 00:08, Tim Roberts wrote: > Stef Mientki wrote: > >> Showing the code is always difficult for me, because I encapsulate >> these complex things. >> The code I gave above doesn't work either :-) >> I use a kill method that also kills the children and seems to be the >> essential thing is this situation, >> (btw why are there children ?) >> > There are child processes because you are setting "shell" to true. > Thus, subprocess actually launches cmd.exe, and cmd.exe launches Python. > > Is there a reason you need a subshell, or was that superstition? > > thanks Tim, I set Shell = True, to get rid of that ugly black dos box, but on second thought pythonw and Shell=False is a better solution. cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From blazej.kaczorowski at gmail.com Thu Jan 28 12:30:57 2010 From: blazej.kaczorowski at gmail.com (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Thu, 28 Jan 2010 12:30:57 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells Message-ID: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> Hello, I use python on win to deal with Excels and stuff at work. I was trying to find proper documentation of fe. to Worksheets Worksheets.Range and Worksheets.Cells objects but all I found on google are some lame tutorials with how to write "Hello World" it is simply ok for beginning but I need something more (fe. how to freeze top row in sheet). Can any1 point a place of full documentation for excel stuff in win32com? I would be gratefull. BR, Blazej From timr at probo.com Thu Jan 28 20:36:05 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 28 Jan 2010 11:36:05 -0800 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> Message-ID: <4B61E725.8080100@probo.com> B?a?ej Kaczorowski wrote: > I use python on win to deal with Excels and stuff at work. I was > trying to find proper documentation of fe. to Worksheets > Worksheets.Range and Worksheets.Cells objects but all I found on > google are some lame tutorials with how to write "Hello World" it is > simply ok for beginning but I need something more (fe. how to freeze > top row in sheet). > > Can any1 point a place of full documentation for excel stuff in > win32com? I would be gratefull. > There is no "full documentation". Excel is just another COM object, so there's nothing in win32com that specifically supports Excel. It's just like all of the other COM objects. Microsoft has good documentation for the Excel object model, which describes the properties and methods that Excel offers, usually showing C++ or VBA code. You have to translate that into Python (which is not always easy). The task you have chosen is not particularly easy. To do the task you have chosen, you need to "split" the window into two panes, then set the size of the top pane to one row. xl = win32com.client.Dispatch("Excel.Application") xl.Visible = 1 w = xl.Application.ActiveWindow w.Split = 1 I'm not entirely sure how to set the size of the individual panes. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From waldemar.osuch at gmail.com Thu Jan 28 21:03:42 2010 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Thu, 28 Jan 2010 13:03:42 -0700 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <4B61E725.8080100@probo.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> Message-ID: <6fae95541001281203q1259f4e5w20475d94af4f0d75@mail.gmail.com> What Tim said but if you are generating Excel files from scratch consider using xlwt: http://pypi.python.org/pypi/xlwt The advantage is that the module is cross platform and you do not need to have Excel installed. In my experience it is also quicker to generate spreadsheets import xlwt values = list('Witamy %s' % i for i in range(100)) hst = xlwt.easyxf('font: bold on, height 260;') book = xlwt.Workbook(encoding='cp1252') sh = book.add_sheet('hello') sh.write(0, 0, 'Heading', hst) for rx, val in enumerate(values, 1): sh.write(rx, 0, val) # do the freeze sh.panes_frozen = True sh.horz_split_pos = 1 sh.remove_splits = True book.save('hello.xls') Waldemar From mrkaczor at interia.pl Thu Jan 28 21:18:30 2010 From: mrkaczor at interia.pl (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Thu, 28 Jan 2010 21:18:30 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <4B61E725.8080100@probo.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> Message-ID: <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> A ok, thx, I found it and it is as you are saying thx it worked! Blazej On 28 January 2010 20:36, Tim Roberts wrote: > B?a?ej Kaczorowski wrote: >> I use python on win to deal with Excels and stuff at work. I was >> trying to find proper documentation of fe. to Worksheets >> Worksheets.Range and Worksheets.Cells objects but all I found on >> google are some lame tutorials with how to write "Hello World" it is >> simply ok for beginning but I need something more (fe. how to freeze >> top row in sheet). >> >> Can any1 point a place of full documentation for excel stuff in >> win32com? I would be gratefull. >> > > There is no "full documentation". ?Excel is just another COM object, so > there's nothing in win32com that specifically supports Excel. ?It's just > like all of the other COM objects. > > Microsoft has good documentation for the Excel object model, which > describes the properties and methods that Excel offers, usually showing > C++ or VBA code. ?You have to translate that into Python (which is not > always easy). > > The task you have chosen is not particularly easy. ?To do the task you > have chosen, you need to "split" the window into two panes, then set the > size of the top pane to one row. > ? ?xl = win32com.client.Dispatch("Excel.Application") > ? ?xl.Visible = 1 > ? ?w = xl.Application.ActiveWindow > ? ?w.Split = 1 > > I'm not entirely sure how to set the size of the individual panes. > > -- > 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 mrkaczor at interia.pl Fri Jan 29 09:30:32 2010 From: mrkaczor at interia.pl (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Fri, 29 Jan 2010 09:30:32 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> Message-ID: <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> xlwt - yes, but I have python 3.1 in my company and cant downgrade it :( Blazej 2010/1/28 B?a?ej Kaczorowski : > A ok, thx, I found it and it is as you are saying thx it worked! > > Blazej > > On 28 January 2010 20:36, Tim Roberts wrote: >> B?a?ej Kaczorowski wrote: >>> I use python on win to deal with Excels and stuff at work. I was >>> trying to find proper documentation of fe. to Worksheets >>> Worksheets.Range and Worksheets.Cells objects but all I found on >>> google are some lame tutorials with how to write "Hello World" it is >>> simply ok for beginning but I need something more (fe. how to freeze >>> top row in sheet). >>> >>> Can any1 point a place of full documentation for excel stuff in >>> win32com? I would be gratefull. >>> >> >> There is no "full documentation". ?Excel is just another COM object, so >> there's nothing in win32com that specifically supports Excel. ?It's just >> like all of the other COM objects. >> >> Microsoft has good documentation for the Excel object model, which >> describes the properties and methods that Excel offers, usually showing >> C++ or VBA code. ?You have to translate that into Python (which is not >> always easy). >> >> The task you have chosen is not particularly easy. ?To do the task you >> have chosen, you need to "split" the window into two panes, then set the >> size of the top pane to one row. >> ? ?xl = win32com.client.Dispatch("Excel.Application") >> ? ?xl.Visible = 1 >> ? ?w = xl.Application.ActiveWindow >> ? ?w.Split = 1 >> >> I'm not entirely sure how to set the size of the individual panes. >> >> -- >> 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 mrkaczor at interia.pl Fri Jan 29 09:32:07 2010 From: mrkaczor at interia.pl (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Fri, 29 Jan 2010 09:32:07 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> Message-ID: <2865bc641001290032n23e75ed4j5190f8ff86311222@mail.gmail.com> o 0.7.2 looks like working, I will give a try thx Blazej 2010/1/29 B?a?ej Kaczorowski : > xlwt - yes, but I have python 3.1 in my company and cant downgrade it :( > > Blazej > > 2010/1/28 B?a?ej Kaczorowski : >> A ok, thx, I found it and it is as you are saying thx it worked! >> >> Blazej >> >> On 28 January 2010 20:36, Tim Roberts wrote: >>> B?a?ej Kaczorowski wrote: >>>> I use python on win to deal with Excels and stuff at work. I was >>>> trying to find proper documentation of fe. to Worksheets >>>> Worksheets.Range and Worksheets.Cells objects but all I found on >>>> google are some lame tutorials with how to write "Hello World" it is >>>> simply ok for beginning but I need something more (fe. how to freeze >>>> top row in sheet). >>>> >>>> Can any1 point a place of full documentation for excel stuff in >>>> win32com? I would be gratefull. >>>> >>> >>> There is no "full documentation". ?Excel is just another COM object, so >>> there's nothing in win32com that specifically supports Excel. ?It's just >>> like all of the other COM objects. >>> >>> Microsoft has good documentation for the Excel object model, which >>> describes the properties and methods that Excel offers, usually showing >>> C++ or VBA code. ?You have to translate that into Python (which is not >>> always easy). >>> >>> The task you have chosen is not particularly easy. ?To do the task you >>> have chosen, you need to "split" the window into two panes, then set the >>> size of the top pane to one row. >>> ? ?xl = win32com.client.Dispatch("Excel.Application") >>> ? ?xl.Visible = 1 >>> ? ?w = xl.Application.ActiveWindow >>> ? ?w.Split = 1 >>> >>> I'm not entirely sure how to set the size of the individual panes. >>> >>> -- >>> 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 mrkaczor at interia.pl Fri Jan 29 09:46:43 2010 From: mrkaczor at interia.pl (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Fri, 29 Jan 2010 09:46:43 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001290032n23e75ed4j5190f8ff86311222@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> <2865bc641001290032n23e75ed4j5190f8ff86311222@mail.gmail.com> Message-ID: <2865bc641001290046l539baaeh8780a6a825037442@mail.gmail.com> Not working, cant import library ... :( there is a way to run xlwt or similar on python 3.1? Blazej 2010/1/29 B?a?ej Kaczorowski : > o 0.7.2 looks like working, I will give a try thx > > Blazej > > 2010/1/29 B?a?ej Kaczorowski : >> xlwt - yes, but I have python 3.1 in my company and cant downgrade it :( >> >> Blazej >> >> 2010/1/28 B?a?ej Kaczorowski : >>> A ok, thx, I found it and it is as you are saying thx it worked! >>> >>> Blazej >>> >>> On 28 January 2010 20:36, Tim Roberts wrote: >>>> B?a?ej Kaczorowski wrote: >>>>> I use python on win to deal with Excels and stuff at work. I was >>>>> trying to find proper documentation of fe. to Worksheets >>>>> Worksheets.Range and Worksheets.Cells objects but all I found on >>>>> google are some lame tutorials with how to write "Hello World" it is >>>>> simply ok for beginning but I need something more (fe. how to freeze >>>>> top row in sheet). >>>>> >>>>> Can any1 point a place of full documentation for excel stuff in >>>>> win32com? I would be gratefull. >>>>> >>>> >>>> There is no "full documentation". ?Excel is just another COM object, so >>>> there's nothing in win32com that specifically supports Excel. ?It's just >>>> like all of the other COM objects. >>>> >>>> Microsoft has good documentation for the Excel object model, which >>>> describes the properties and methods that Excel offers, usually showing >>>> C++ or VBA code. ?You have to translate that into Python (which is not >>>> always easy). >>>> >>>> The task you have chosen is not particularly easy. ?To do the task you >>>> have chosen, you need to "split" the window into two panes, then set the >>>> size of the top pane to one row. >>>> ? ?xl = win32com.client.Dispatch("Excel.Application") >>>> ? ?xl.Visible = 1 >>>> ? ?w = xl.Application.ActiveWindow >>>> ? ?w.Split = 1 >>>> >>>> I'm not entirely sure how to set the size of the individual panes. >>>> >>>> -- >>>> 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 mail at timgolden.me.uk Fri Jan 29 10:05:45 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 29 Jan 2010 09:05:45 +0000 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001290046l539baaeh8780a6a825037442@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> <2865bc641001290032n23e75ed4j5190f8ff86311222@mail.gmail.com> <2865bc641001290046l539baaeh8780a6a825037442@mail.gmail.com> Message-ID: <4B62A4E9.4090703@timgolden.me.uk> On 29/01/2010 08:46, B?a?ej Kaczorowski wrote: > Not working, cant import library ... :( there is a way to run xlwt or > similar on python 3.1? If you haven't already, you really want to look over here: http://www.python-excel.org/ and in particular at the mailing list referred to at the bottom of the page. TJG From mrkaczor at interia.pl Fri Jan 29 10:48:27 2010 From: mrkaczor at interia.pl (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Fri, 29 Jan 2010 10:48:27 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <4B62A4E9.4090703@timgolden.me.uk> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> <2865bc641001290032n23e75ed4j5190f8ff86311222@mail.gmail.com> <2865bc641001290046l539baaeh8780a6a825037442@mail.gmail.com> <4B62A4E9.4090703@timgolden.me.uk> Message-ID: <2865bc641001290148k7e9fbe6ekf7d8272fc5c7e5f4@mail.gmail.com> non works in 3.1 :/ Blazej 2010/1/29 Tim Golden : > On 29/01/2010 08:46, B?a?ej Kaczorowski wrote: >> >> Not working, cant import library ... :( there is a way to run xlwt or >> similar on python 3.1? > > If you haven't already, you really want to look over here: > > ?http://www.python-excel.org/ > > and in particular at the mailing list referred to at the bottom > of the page. > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From waldemar.osuch at gmail.com Fri Jan 29 18:02:36 2010 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Fri, 29 Jan 2010 10:02:36 -0700 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001290148k7e9fbe6ekf7d8272fc5c7e5f4@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> <2865bc641001290032n23e75ed4j5190f8ff86311222@mail.gmail.com> <2865bc641001290046l539baaeh8780a6a825037442@mail.gmail.com> <4B62A4E9.4090703@timgolden.me.uk> <2865bc641001290148k7e9fbe6ekf7d8272fc5c7e5f4@mail.gmail.com> Message-ID: <6fae95541001290902s6e753571y4f4f9b3347fbb316@mail.gmail.com> 2010/1/29 B?a?ej Kaczorowski : > non works in 3.1 :/ > The maintainer of xlwt, John Machin is thinking about the port to python 3.x http://groups.google.com/group/python-excel/browse_thread/thread/e3fe92bd08aa1cdd# but I do not think he is in a rush. From timr at probo.com Fri Jan 29 18:39:05 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 29 Jan 2010 09:39:05 -0800 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> Message-ID: <4B631D39.3040207@probo.com> B?a?ej Kaczorowski wrote: > xlwt - yes, but I have python 3.1 in my company and cant downgrade it :( > That is an amazing statement. I can't imagine any company going mission-critical with Python 3 yet. There are just too many third-party modules that have not been ported. However, you don't have to downgrade. Python 2 and Python 3 are able to coexist on a single computer without any problems. Just install them both. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Jan 29 19:33:13 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 29 Jan 2010 10:33:13 -0800 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <2865bc641001291019q7adcaff5q176d42b7c829aa61@mail.gmail.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> <4B631D39.3040207@probo.com> <2865bc641001291019q7adcaff5q176d42b7c829aa61@mail.gmail.com> Message-ID: <4B6329E9.3070005@probo.com> B?a?ej Kaczorowski wrote: > I know, but I have app that runs with python3 .. and I would need to > rewrite it to python2 to use xlwt and still win32com works ok (but > slower) I probably wait for port ... > OK, that's fine. Just for your information, with appropriate use of "from __future__" statements, most Python 3 code will run in Python 2.6 (or later). -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mrkaczor at interia.pl Fri Jan 29 19:40:28 2010 From: mrkaczor at interia.pl (=?ISO-8859-2?Q?B=B3a=BFej_Kaczorowski?=) Date: Fri, 29 Jan 2010 19:40:28 +0100 Subject: [python-win32] Documentation for win32com for Worksheets Worksheets.Range and Worksheets.Cells In-Reply-To: <4B6329E9.3070005@probo.com> References: <2865bc641001280330h6a3cd799j3c286a50c7f5b16d@mail.gmail.com> <4B61E725.8080100@probo.com> <2865bc641001281218t1d3a3a8erd09c7d3f15cd09b4@mail.gmail.com> <2865bc641001290030q4644b61h1fe9729682b1c68a@mail.gmail.com> <4B631D39.3040207@probo.com> <2865bc641001291019q7adcaff5q176d42b7c829aa61@mail.gmail.com> <4B6329E9.3070005@probo.com> Message-ID: <2865bc641001291040r75528c2cye112b6543caa7963@mail.gmail.com> probably yes, maybe I will check that in monday :) thx Blazej 2010/1/29 Tim Roberts : > B?a?ej Kaczorowski wrote: >> I know, but I have app that runs with python3 .. and I would need to >> rewrite it to python2 to use xlwt and still win32com works ok (but >> slower) I probably wait for port ... >> > > OK, that's fine. ?Just for your information, with appropriate use of > "from __future__" statements, most Python 3 code will run in Python 2.6 > (or later). > > -- > 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 stef.mientki at gmail.com Sun Jan 31 00:35:33 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 31 Jan 2010 00:35:33 +0100 Subject: [python-win32] How to fetch windows messages from another application ? Message-ID: <4B64C245.4000104@gmail.com> hello, I've a foreign application (written in Delphi), which I can dock in my wxPython application, and I'm able to send message from the wxPython application to the foreign application. So I'm able to send my own handle to the foreign application. Now the last part is receiving messages from the foreign application in the main wxPython application. How do I fetch a windows message from the foreign application ? thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From chef at ghum.de Sun Jan 31 10:15:51 2010 From: chef at ghum.de (Massa, Harald Armin) Date: Sun, 31 Jan 2010 10:15:51 +0100 Subject: [python-win32] How to fetch windows messages from another application ? In-Reply-To: <4B64C245.4000104@gmail.com> References: <4B64C245.4000104@gmail.com> Message-ID: Stef, I do not have a readymade solution. But some words to help your googling: what you are looking for is called "hooks" and "intercepting". So please google for "intercept windows messages" or "Windows message hooks" and "windows event hooks". (As the message "mouse entered window" is also called "event") Also have a look at tools like auto-it and pywinauto. Best wishes, Harald -- GHUM Harald Massa persuadere et programmare Harald Armin Massa Spielberger Stra?e 49 70435 Stuttgart 0173/9409607 no fx, no carrier pigeon - %s is too gigantic of an industry to bend to the whims of reality -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Sun Jan 31 14:36:31 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 31 Jan 2010 14:36:31 +0100 Subject: [python-win32] How to fetch windows messages from another application ? In-Reply-To: References: <4B64C245.4000104@gmail.com> Message-ID: <4B65875F.9080202@gmail.com> Thanks Harald, Although "message" is a crime to search on google, with you search words I found a workable solution If others are interested: http://blog.csdn.net/dahubaobao/archive/2009/09/10/4539324.aspx cheers, Stef On 31-01-2010 10:15, Massa, Harald Armin wrote: > Stef, > > I do not have a readymade solution. But some words to help your > googling: what you are looking for is called "hooks" and "intercepting". > > So please google for "intercept windows messages" or "Windows message > hooks" and "windows event hooks". > > (As the message "mouse entered window" is also called "event") > > Also have a look at tools like auto-it and pywinauto. > > Best wishes, > > Harald > > > -- > GHUM Harald Massa > persuadere et programmare > Harald Armin Massa > Spielberger Stra?e 49 > 70435 Stuttgart > 0173/9409607 > no fx, no carrier pigeon > - > %s is too gigantic of an industry to bend to the whims of reality