473,387 Members | 3,821 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,387 software developers and data experts.

detecting boxes in windows using python

Dear all.

I am using an existing hodge-podge of an application that runs on top
of an Access database. This application dials up customer equipment,
handshakes then downloads/uploads various bits of information in the
access database.

The original application is designed for some poor sod to sit there
for hours and manually do the necessary.

I have automated various processes by 'back filling' the access
database, thereby fooling the application into doing what I want.

The problem that I have is that if the application comes across a busy
signal, or if the call fails for what ever reason, it displays an
error dialog box on the pc. If there are a lot of these, it causes
the app to hang.

The underlying log files in the access database are still updated.

Is there a way in python to detect these dialog boxes, then
effectively close them? either by pressing the boxes own close
button, or the little cross thingy on the top right corner (i don't
know what it is called).

The OS is win2k, latest service pack.

Any help that any of you can offer will be most greatfully received.

Kind regards

Bill
Jul 18 '05 #1
1 3929
bi*********@clear.net.nz (bill ramsay) wrote in message news:<a1**************************@posting.google. com>...
I just wrote a comfortable solution for this purpose,
including logging to stdout.
The main functionality is in function ConfirmDialog()

Just copy code below to a python file and edit the PopupNames global
variable.

Prerequisite: You will have to install python windows extensions from
http://starship.python.net/crew/mhammond/

<code>
"""
Automatical confirmation of popup windows.
"""

from win32con import *
from win32api import *
from win32ui import *
from win32gui import GetClassName
from win32event import *
from time import time, ctime, sleep
import sys

# Captions (titles) of popup windows to confirm
# EDIT THIS
PopupNames = (
'Error',
'Information',
'Install Dialler', # You better delete this line :-)
)

def GetWindowText( Window ):
"""
Get text of all 'Static' elements of windows and return
concatenated.
"""
Child, Text = None, ''
while 1:
try: Child = FindWindowEx( Window, Child, 'Static', None )
except: break
Text += '\n\t'.join( Child.GetWindowText().split( '\r' ) )
return Text

def FindControl( Window, CName = 'OK', CType = 'Button' ):
"""
Find control with name CName in Window

@arg Window: Top level window
@type Window: PyCWnd
@arg CName: Control Name
@type CName: string
@arg CType: Control class
@type CType: string
@return Control
@rtype: PyCwnd
"""
return FindWindowEx( Window, None, CType, CName )
def ConfirmDialog( Window, BName = None, Delay = 0.5 ):
"""
Find button with name BName in Window and simulate a button
activation.

@arg WName: Window Name
@type WName: string
@arg BName: Button Name
@type BName: string
@return: Button in case of success, negative error code else
@rtype: PyCWnd
"""
# Find Button
Button = FindControl( Window, BName )
Button.SendMessage( BM_SETSTATE, 1, 0 )
sleep( Delay ) # Window should show up at least for half a second.

# Simulate button press to confirm window
idButton = Button.GetDlgCtrlID()
hButton = Button.GetSafeHwnd()
Caption = Window.GetWindowText()
Window.SendMessage( WM_COMMAND, MAKELONG( idButton, BN_CLICKED ),
hButton )

print ctime( time() ), "Confirmed '%s'" %Caption
return Button
if __name__ == '__main__':
# Program parameters and options
ConfDelay = 0.5
if '-i' in sys.argv:
ConfDelay = 0

print ctime( time() ), "%s started" %sys.argv[ 0 ]

while 1:
for Name in PopupNames:
try: Window = FindWindow( None, Name )
except: continue

# Extract text information from Popup (for logging).
Message = GetWindowText( Window ) # Get message text before
window disappears

ConfirmDialog( Window, 'OK', ConfDelay )

if Message: print '\t' + Message
break
sleep( 1 )
</code>

Regards
Stefan
Dear all.

I am using an existing hodge-podge of an application that runs on top
of an Access database. This application dials up customer equipment,
handshakes then downloads/uploads various bits of information in the
access database.

The original application is designed for some poor sod to sit there
for hours and manually do the necessary.

I have automated various processes by 'back filling' the access
database, thereby fooling the application into doing what I want.

The problem that I have is that if the application comes across a busy
signal, or if the call fails for what ever reason, it displays an
error dialog box on the pc. If there are a lot of these, it causes
the app to hang.

The underlying log files in the access database are still updated.

Is there a way in python to detect these dialog boxes, then
effectively close them? either by pressing the boxes own close
button, or the little cross thingy on the top right corner (i don't
know what it is called).

The OS is win2k, latest service pack.

Any help that any of you can offer will be most greatfully received.

Kind regards

Bill

Jul 18 '05 #2

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

Similar topics

4
by: Daniel Orner | last post by:
Does anyone know of a simple way to have a Python script find out what browser is accessing it? After a web search the only thing I found to do this is Zope, but the system I'm programming doesn't...
15
by: Jay | last post by:
I'm sure this is a really dumb question, but how do you detect a variable type in Python? For example, I want to know if the variable "a" is a list of strings or a single string. How do I do...
3
by: Sandeep Arya | last post by:
Thanks linuxfreak and sybren for positive comments My application will be running on Linux. How to send ICMP ECHO as broadcast packets. I do not know this. Please tell me how to? Sybren.....
2
by: Fuzzyman | last post by:
Hello all, I'm creating a py2exe program (for Windows) that needs to detect all version of Python installed on the machine. Because it is running under py2exe it doesn't have access to the...
18
by: Fuzzyman | last post by:
Hello all, I'm trying to detect line endings used in text files. I *might* be decoding the files into unicode first (which may be encoded using multi-byte encodings) - which is why I'm not...
7
by: BWill | last post by:
Hi, I'm writing a file browser, but I'm not sure how I could go about detecting the drives available on windows and linux systems (preferably using the standard modules if possible). I guess I...
4
by: tylertacky | last post by:
Ok, I'm pretty new to python, so this might be a stupid question. I'm trying to write a simple text-based pong clone, and I can't figure out how to read key presses to move the paddles. I just need...
2
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, I am wondering why the .NET Framework is quite different from Win32 API when it comes to displaying system modal message boxes. Consider the four following types of system modal message...
4
by: Devraj | last post by:
Hi everyone, My Python program needs reliably detect which Operating System its being run on, infact it even needs to know which distribution of say Linux its running on. The reason being its a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.