473,757 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4040
bi*********@cle ar.net.nz (bill ramsay) wrote in message news:<a1******* *************** ****@posting.go ogle.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.GetWindow Text().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.SendMess age( BM_SETSTATE, 1, 0 )
sleep( Delay ) # Window should show up at least for half a second.

# Simulate button press to confirm window
idButton = Button.GetDlgCt rlID()
hButton = Button.GetSafeH wnd()
Caption = Window.GetWindo wText()
Window.SendMess age( 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
14205
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 use Zope and I'm not really interested in installing it just for this minor detail. Is there another way? Thanks! --Daniel Orner
15
2699
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 this?
3
465
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.. Does nmap is available on every systems? I tried on my linux fc4 machine in user previleage. it was not working. Does this just belongs to superuser...
2
1992
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 Python environment variables. Does anyone know how to use _winreg to get path information (location of install) for all versions of Python installed (and also which is the
18
9566
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 letting Python handle the line endings. Is the following safe and sane : text = open('test.txt', 'rb').read()
7
3594
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 could just try to list root on each letter of the alphabet for windows and see if it works, but that seems crude; besides, I want to know what kind of drive each drive/partition is (i.e. is it local and is it a harddrive or optical drive). Thanks,
4
20712
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 something that does the same thing as getch() and kbhit(). I can't use those because their windows only, and I'm running Linux. Someone suggested using curses, but that does crazy things with my output, and leaves the terminal unusable after...
2
4502
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 boxes (please see associated source code below): 1) Win32 API with context ("btnWin32WithContext_Click") 2) .NET Framework with context ("btnFrameworkWithContext_Click") 3) Win32 API withOUT context ("btnWin32WithOUTContext_Click")
4
4560
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 GTK application that needs to adapt itself to be a Hildon application if run on devices like the N800. I have been searching around for an answer to this, and did find some messages on a lists that suggested the use of sys.platform to detect
0
9297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.