odd problem with watsup and VB6 application with modal dialog

G

Grumman

For various reasons, I've found myself in the position of needing to
automate the operation of a small VB6 application from an external
process. After a bit of searching, I found watsup, and it has fit the
bill nicely, except for one problem.

Roughly, I have a script that fills in a field, sets a combobox, then
clicks a button via clickButton. At this point, the python interpreter
hangs. The only thing I've been able to identify as different about this
form is that it is set as dialog-modal.

I've managed to work around this by adding a second python script that
contains just enough code to click the offending button. I call it via
os.system('start other.py') and it starts in a different process, clicks
the button then hangs.

But the main script continues on to fill in the following form, and
click another button. When the VB app returns to its starting form,
destroying the other form instances, the hung interpreter ends.

This works, but it is quite the ugly kludge isn't it?

Is this a normal behaviour for watsup with modal windows? Is there a
saner way around it?

I should point out I spend my days in the midrange world, so I'm largely
ignorant of the vagaries of the windows API and such.
 
R

Rob Williscroft

Grumman wrote in in comp.lang.python:

[snip]
Roughly, I have a script that fills in a field, sets a combobox, then
clicks a button via clickButton. At this point, the python interpreter
hangs. The only thing I've been able to identify as different about
this form is that it is set as dialog-modal.

I've managed to work around this by adding a second python script that
contains just enough code to click the offending button. I call it via
os.system('start other.py') and it starts in a different process,
clicks the button then hangs.

But the main script continues on to fill in the following form, and
click another button. When the VB app returns to its starting form,
destroying the other form instances, the hung interpreter ends.

This works, but it is quite the ugly kludge isn't it?

Is this a normal behaviour for watsup with modal windows? Is there a
saner way around it?

AFAICT the problem is that the clickButton() function calls
the internal windows API function SendMessage(), which waits
for the buttons event handler to return something.

There is an alternative PostMessage(), which returns as soon as
the message is put in the target windows message queue.

A potential proplen with this is that it will return immediately
so the caller will need to wait (time.sleep) until the button
handler has recieved the message and done something about it.

Here's a rewrite of the winGuiAuto.clickButton function,
post_clickButton() that uses PostMessage:

def post_clickButton( hwnd ):
'''All code here adapted from winGuiAuto.py
see http://www.tizmoi.net/watsup/intro.html
'''

def _buildWinLong(high, low):
'''Build a windows long parameter from high and low words.

See http://support.microsoft.com/support/kb/articles/q189/1/70.asp
'''
return int( 0xFFFFFFFF & ( (high << 16) | (low & 0xFFFF) ) )

def _postNotifyMessage(hwnd, notifyMessage):
'''Post a notify message to a control.'''
import win32gui
import win32con
import win32api

win32gui.PostMessage(
win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(
notifyMessage, win32api.GetWindowLong(hwnd, win32con.GWL_ID)
),
hwnd
)

import win32con
_postNotifyMessage( hwnd, win32con.STN_CLICKED )

if __name__=='__main__':

'''Just here to show how it works, this code won't actually
work unless you have a sutible GUI programme running.
'''

from watsup.winGuiAuto import \
findControl,setEditText, \
findTopWindow,clickButton
from time import sleep

def main():

form=findTopWindow(wantedText='Main_Form')
button=findControl(form,wantedText='Open')

print 'clicking button to open dialog...'
post_clickButton(button)

sleep( 0.5 )

form=findTopWindow(wantedText='Dialog_Form')
button=findControl(form,wantedText='Close')

print "clicking close button"
post_clickButton(button)

main()

Rob.
 
I

ina

At my work we had the same problem. We found that the best solution
was to use a thread with the code to handle the model dialog. This
worked best for us because the only models in our product are the error
messages, and using a thread gave us the ability to check and see if
the modal dialog was found.

In this post there is some example code. I will post up a more
complete solution when I get to work on monday.

http://groups.google.com/group/comp...q=findtopwindow&rnum=1&hl=en#ee7ec7cf2d12801d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top