Re: [python-win32] I/O error
On 22/03/2010 21:22, travel europe wrote: I am getting the following error "ValueError: I/O operation on closed file" when running a module to pull data from the Windows registry. import csv from winsys import registry key = r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" fields = ["DisplayName", "Comments", "InstallDate"] # add to as required uninstall = registry.registry (key) with open ("installed.txt", "wb") as f: writer = csv.writer (f) writer.writerow (fields) for subkey in uninstall: info = dict (subkey.values ()) writer.writerow ([info.get (field) for field in fields]) The indentation's wrong. The line starting "for subkey in..." should be indented to the same level as the line above, placing it within context of the "with open (...):" from a few lines above. I've just checked the email I sent with that in, and it looks ok (on my email client) so I can only imagine that one of the various email clients / servers between us has munged the indentation. TJG ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Win API call to display a BMP/PNG file as a splash screen for a console app?
Hi Malcolm On 1:59 PM, pyt...@bdurham.com wrote: Is there a Windows API call I can use to display a BMP or a PNG file in a window centered on a user's display? This function would be called from a console app to display a splash screen. Motivation: I would like some of our customer facing Python console utilities to display a splash screen. I don't need the complexity of a full GUI framework like wxPython or pyQT and hopefully I can avoid the need to use a full library like PIL. Thank you, Malcolm There are ways to significantly reduce the wxPython footprint in your py2exe binary. Ask on the mailing list. Steven Sproat was talking about some methods last month and I think he said he had an exe that was 5 or 7 MB when he was done. -- *Mike Driscoll* Blog: http://blog.pythonlibrary.org ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] (no subject)
Hello! Can anyone give me some hint please? I'm trying to make a log file which keep track of a specific application. For example, I need to punch the time et date where an application, such as Firefox, is opened and when it's closed. I also need to detect when the application goes to idle and when it's re-activate again. (I hope my question it's clear enough.) Thank you! (\ (\ (°-°) (")(") P _ Live connected with Messenger on your phone http://go.microsoft.com/?linkid=9712958___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Help calling a windows function in user32
Hey guys im having a little difficulty sending data to my C application through python. I have my test.exe that has a input box in a window. I am trying to populate the edit box with input i send to it through python. This is a far as I have been able to get so far. any help would be much appreciated. import os,sys,subprocess,win32con from subprocess import * from os import * from ctypes import * from ctypes.wintypes import * appPath=r'"C:\Dev-Cpp\windowsapp.exe"' p = subprocess.Popen(appPath) user32 = windll.user32 user32.SetDlgItemTextA(need to put the hwnd handle here i think??? not sure how this is done, 1, "some text") // this is a user32 function that sends text to my inputbox. C code below for reference CreateWindow( "edit", "", WS_VISIBLE|WS_CHILD|WS_BORDER|ES_AUTOHSCROLL|ES_AUTOVSCROLL, 0, 0, 300, 20, hwnd, (HMENU)1, hThisInstance, NULL); SetDlgItemTextA(hwnd, 1, "some text") _ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. https://signup.live.com/signup.aspx?id=60969___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Win API call to display a BMP/PNG file as a splash screen for a console app?
Malcolm: I used to have exactly what you need. Unfortunately, when I checked just now, I find that I failed to "lift" a copy of the source code when I left the place where I wrote it. "It" was a command line utility which accepted as arguments the name of a .jpg file and the number of seconds to display it before exiting. As it happens, mine was written in wxPython. Any of the previous suggestions would be a good start. The point is that you have your console program run the splash as a separate (non-console) program -- using a "Run and don't wait" OS call -- so that the GUI stuff is not complicating your console code. My application displayed a cartoon of a human skeleton looking at a computer display which said "Please Wait." It was placed at the beginning of a long and complicated automatic login script for a dedicated workstation and displayed for 20 seconds. It completely eliminated anxious users trying to poke at the workstation before it was ready. Yes, the extra .exe and the .jpg will add a little weight to your distribution, but storage is cheap these days, and user satisfaction is worth it, IMHO. -- Vernon > > On 1:59 PM, pyt...@bdurham.com wrote: > > Is there a Windows API call I can use to display a BMP or a PNG file in a > window centered on a user's display? This function would be called from a > console app to display a splash screen. > > Motivation: I would like some of our customer facing Python console > utilities to display a splash screen. I don't need the complexity of a full > GUI framework like wxPython or pyQT and hopefully I can avoid the need to > use a full library like PIL. > > Thank you, > Malcolm > > ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help calling a windows function in user32
You wrote: > >Hey guys im having a little difficulty sending data to my C application >through python. I have my test.exe that has a input box in a window. I >am trying to populate the edit box with input i send to it through >python. This is a far as I have been able to get so far. any help >would be much appreciated. > >import os,sys,subprocess,win32con > >from subprocess import * >from os import * You don't need those two lines. In fact, they are a bad idea. Just say "subprocess.Popen" (which is what you are actually doing). >from ctypes import * >from ctypes.wintypes import * > >appPath=r'"C:\Dev-Cpp\windowsapp.exe"' You don't need two sets of quotes here. The file name does not actually have quotes. >p = subprocess.Popen(appPath) > >user32 = windll.user32 > >user32.SetDlgItemTextA(need to put the hwnd handle here i think??? not sure >how this is done, 1, "some text") // this is a user32 function that sends text >to my inputbox. Yes, you need to find the window handle of your dialog. You can use the FindWindow API to do that. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Win API call to display a BMP/PNG file as a splash screen for a console app?
Andrew MacIntyre wrote: Is it possible to draw directly to the desktop? I vaguely recall reading somewhere that that is how some splash screens are done to avoid the overhead of a window... Somehow I doubt that. I have a hard time imagining that displaying a splash screen could be a serious performance bottleneck! Not the window-creation part of it, anyway. Although if by "overhead" you mean that some programmer was too lazy to write the necessary code, I could probably believe that... -- Greg ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help calling a windows function in user32
Richard Leahy wrote: > Hi, thank you for your reply. I have tried the FindWindow which works > great how ever It cant find the window i am after. > ... > test = windll.user32.FindWindowA(None, "Windows App") // find the > first window perfectly > > if not test: > print "[*] cant find window" > > test = windll.user32.FindWindowA("edit", None) // cant find the edit > box window. any ideas? You don't NEED this second call. The number you get from the first call is the handle to the dialog. Just pass that to SetDlgItemText along with the control ID (1). The reason is fails is that FindWindow only returns top-level windows, not child windows. It IS possible to use FindWindowEx to search child windows, but you don't want that. What you NEED is the top-level dialog (which you have) and the control ID (which you also have). -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] (no subject)
Phung Thuy Vuong wrote: > > Can anyone give me some hint please? I'm trying to make a log file > which keep track of a specific application. For example, I need to > punch the time et date where an application, such as Firefox, is > opened and when it's closed. I also need to detect when the > application goes to idle and when it's re-activate again. (I hope my > question it's clear enough.) Thank you! What you ask is complicated. You need to install a "window hook" to intercept the activate and deactivate messages going to all of the top-level windows in the system. The reason it's complicated is because of the way window hooks work. Your code must live in a DLL, and that DLL is injected into every process in the system. Thus, such a thing cannot be written in Python. You could certainly have a simple hook DLL that reports statistics back to some Python server "mother ship". There are several web articles on writing window hooks. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] (no subject)
David Hutto wrote: > On Tue, Mar 23, 2010 at 6:11 PM, Tim Roberts wrote: > >> Phung Thuy Vuong wrote: >> >>> Can anyone give me some hint please? I'm trying to make a log file >>> which keep track of a specific application. For example, I need to >>> punch the time et date where an application, such as Firefox, is >>> opened and when it's closed. I also need to detect when the >>> application goes to idle and when it's re-activate again. (I hope my >>> question it's clear enough.) Thank you! >>> >> What you ask is complicated. You need to install a "window hook" to >> intercept the activate and deactivate messages going to all of the >> top-level windows in the system. ... >> > > I'm new so excuse the ignorance, and the simplicity of the idea, if > it is, but couldn't you just monitor the process id's and then match > the running/sleep/active usage instead of the dll's. You would only > have to monitor the single system monitor. If I'm thinking about this > correctly. > Perhaps so -- the original poster will have to judge whether that's sufficient. On Linux, I think you could do that rather easily. On Windows, the sentence "just monitor the process ids" is not as trivial as it sounds. It's possible to use ToolHelp to run through the list of processes, and the list of threads for those processes, then use GetThreadTimes to get the CPU time. That doesn't necessarily tell you when an application gains and loses focus. It all depends on what the OP really needs to know. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Help calling a windows function in user32
Richard Leahy wrote: > So basically your saying that if i just use this > > test = windll.user32.FindWindowA(None, "Windows App") > > if not test: > print "[*] cant find window" > > print test // which returns 7471154 the handle > > windll.user32.SetDlgItemTextA(test,1,"test") > > this doesn't seem to set my edit box with the value of test sorry if i > am not making sense and thank you for your help. It shouldn't be any more complicated than that. I was under the impression that SetDlgItemText marshaled the string pointer so it would work between processes, but perhaps I am mistaken. SetDlgItemInt should CERTAINLY work -- perhaps you should try that first. BTW, you don't need to use ctypes for this. FindWindow, SetDlgItemText and SetDlgItemInt are all exported from win32gui. import win32gui t = win32gui.FindWindow( None, "Windows App" ) win32gui.SetDlgItemInt( t, 1, 37 ) -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32