473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Windows dialog box removal

I've written a Python script that runs a MS Windows program using popen.
However, at the end of the Windows program, a dialog box appears and
asks for the user to click on OK.

Is there a way to have Python set focus on the dialog box and click OK
so my script can continue?

Does anyone have an example?
Jul 18 '05 #1
3 7459
On Thursday 25 September 2003 06:18 am, SectorUnknown wrote:
I've written a Python script that runs a MS Windows program using popen.
However, at the end of the Windows program, a dialog box appears and
asks for the user to click on OK.

Is there a way to have Python set focus on the dialog box and click OK
so my script can continue?

Does anyone have an example?


I wouldn't be surprised if there's an easier or more correct way to do this,
but if you can reliably know the title of the window then the code below
should work (assuming you have ctypes installed):

from ctypes import *
user32 = windll.user32

EnumWindowsProc = WINFUNCTYPE(c_int, c_int, c_int)

def GetHandles(title, parent=None):
'Returns handles to windows with matching titles'
hwnds = []
def EnumCB(hwnd, lparam, match=title.lower(), hwnds=hwnds):
title = c_buffer(' ' * 256)
user32.GetWindowTextA(hwnd, title, 255)
if title.value.lower() == match:
hwnds.append(hwnd)

if parent is not None:
user32.EnumChildWindows(parent, EnumWindowsProc(EnumCB), 0)
else:
user32.EnumWindows(EnumWindowsProc(EnumCB), 0)
return hwnds

Here's an example of calling it to click the Ok button on any window that has
the title "Downloads properties" (most likely there are 0 or 1 such windows):

for handle in GetHandles('Downloads properties'):
for childHandle in GetHandles('ok', handle):
user32.SendMessageA(childHandle, 0x00F5, 0, 0) # 0x00F5 = BM_CLICK

-Dave

Jul 18 '05 #2
Dave Brueck <da**@pythonapocrypha.com> writes:
On Thursday 25 September 2003 06:18 am, SectorUnknown wrote:
I've written a Python script that runs a MS Windows program using popen.
However, at the end of the Windows program, a dialog box appears and
asks for the user to click on OK.

Is there a way to have Python set focus on the dialog box and click OK
so my script can continue?

Does anyone have an example?


I wouldn't be surprised if there's an easier or more correct way to do this,
but if you can reliably know the title of the window then the code below
should work (assuming you have ctypes installed):

[example snipped]

I've added this example to the ctypes wiki, so it will not be lost. Hope
that's ok ;-)

<http://starship.python.net/crew/theller/moin.cgi/CtypesLinks>

Thomas
Jul 18 '05 #3
That works great.

Thanks!!!

In article <ma*********************************@python.org> ,
da**@pythonapocrypha.com says...
On Thursday 25 September 2003 06:18 am, SectorUnknown wrote:
I've written a Python script that runs a MS Windows program using popen.
However, at the end of the Windows program, a dialog box appears and
asks for the user to click on OK.

Is there a way to have Python set focus on the dialog box and click OK
so my script can continue?

Does anyone have an example?


I wouldn't be surprised if there's an easier or more correct way to do this,
but if you can reliably know the title of the window then the code below
should work (assuming you have ctypes installed):

from ctypes import *
user32 = windll.user32

EnumWindowsProc = WINFUNCTYPE(c_int, c_int, c_int)

def GetHandles(title, parent=None):
'Returns handles to windows with matching titles'
hwnds = []
def EnumCB(hwnd, lparam, match=title.lower(), hwnds=hwnds):
title = c_buffer(' ' * 256)
user32.GetWindowTextA(hwnd, title, 255)
if title.value.lower() == match:
hwnds.append(hwnd)

if parent is not None:
user32.EnumChildWindows(parent, EnumWindowsProc(EnumCB), 0)
else:
user32.EnumWindows(EnumWindowsProc(EnumCB), 0)
return hwnds

Here's an example of calling it to click the Ok button on any window that has
the title "Downloads properties" (most likely there are 0 or 1 such windows):

for handle in GetHandles('Downloads properties'):
for childHandle in GetHandles('ok', handle):
user32.SendMessageA(childHandle, 0x00F5, 0, 0) # 0x00F5 = BM_CLICK

-Dave

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Christian Wilcox | last post by:
Does anyone know of any existing Python implementations of an XForms viewer? Christian
5
by: Fred | last post by:
Hi, I'd like to turn a command-line script into a Windows GUI app using the native widgets so as to reduce the size of the binary (ie. no QT, wxWidgets, et al.) I came up with the following...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
5
by: Richard Lionheart | last post by:
Hi All, I tried creating a C# Form using Petzold's "Programming MS Windows with C#" guidance. He recommended using the namespace System.Windows.Forms. However, VS.NET claims "the type or...
2
by: Matt Hamilton | last post by:
I have an application page with a datagrid with a checkbox on each row. The user should check the rows they want to modify and then click a button. When the button is clicked, I have a Click...
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
3
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The...
5
by: Stefano Tonello | last post by:
Hi all, I need to call windows' "open with" dialog from my C# windows form application. After the user selects application, control must return to me (I have to launch directly the process). I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.