By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,942 Members | 1,788 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,942 IT Pros & Developers. It's quick & easy.

odd problem with watsup and VB6 application with modal dialog

P: n/a
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.
Nov 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Grumman wrote in news:JN**************@newsfe03.lga 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.../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.
--
http://www.victim-prime.dsl.pipex.com/
Nov 11 '06 #2

P: n/a
Rob Williscroft wrote:
Here's a rewrite of the winGuiAuto.clickButton function,
post_clickButton() that uses PostMessage:
Thanks for the info, I'll give it a try.
Nov 12 '06 #3

P: n/a
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....7ec7cf2d12801d

Nov 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.