<div dir="ltr"><div>Andre,<br><br></div>Have you read through <a href="http://johnnado.com/pyqt-qtest-example/" target="_blank">http://johnnado.com/pyqt-qtest-example/</a>? That shows testing a dialog box (no threads necessary).<br><br>Bryan</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 28, 2014 at 7:19 AM, Andre Roberge <span dir="ltr"><<a href="mailto:andre.roberge@gmail.com" target="_blank">andre.roberge@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div dir="ltr">I'm creating a series of "standalone widgets" that can be used in procedural programs; the original idea is from the easygui project. To give a concrete idea of their use, instead of writing:
<div><br>
</div>
<div>->>> name = input("What is your name? )</div>
<div><br>
</div>
<div>I could write</div>
<div><br>
</div>
<div>->>> name = get_string("What is your name? )</div>
<div><br>
</div>
<div>and a dialog would pop up, inviting the user to enter the response.</div>
<div><br>
</div>
<div>I would like to set up some automatic testing of these widgets. I tried with a third-party module</div>
<div>(pyautogui) which interacts with GUI programs, but the result is not totally reliable.</div>
<div>I would prefer to use QTest but do not know how to connect with the dialog; I suspect I may have</div>
<div>to use threading (as I had to do with the pyautogui solution) as the dialog is effectively blocking the execution of the program.</div>
<div><br>
</div>
<div>Here is a simple implementation of get_string() mentioned above:</div>
<div><br>
</div>
<div>
<div>from PyQt4 import QtGui</div>
<div><br>
</div>
<div>def get_string(prompt="What is your name? ", title="Title",</div>
<div> default_response="PyQt4", app=None):</div>
<div> """GUI equivalent of input()."""</div>
<div><br>
</div>
<div> if app is None:</div>
<div> app = QtGui.QApplication([])</div>
<div> app.dialog = QtGui.QInputDialog()</div>
<div> text, ok = app.dialog.getText(None, title, prompt,</div>
<div> QtGui.QLineEdit.Normal,</div>
<div> default_response)</div>
<div> app.quit()</div>
<div> if ok:</div>
<div> return text</div>
<div><br>
</div>
<div>if __name__ == '__main__':</div>
<div> print(get_string()) # normal blocking mode</div>
<div> app2 = QtGui.QApplication([])</div>
<div> # perhaps start a delayed thread here, using QTest</div>
<div> print(get_string(app=app2))</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>=======</div>
<div>Any help would be appreciated.</div>
<div><br>
</div>
<div>André Roberge</div>
</div>
</div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Bryan A. Jones, Ph.D.<br>Associate Professor<br>Department of Electrical and Computer Engineering<br>231 Simrall / PO Box 9571<br>Mississippi State University<br>Mississippi state, MS 39762<br><a href="http://www.ece.msstate.edu/~bjones" target="_blank">http://www.ece.msstate.edu/~bjones</a><br>bjones AT ece DOT msstate DOT edu<br>voice 662-325-3149<br>fax 662-325-2298<br><br>Our Master, Jesus Christ, is on his way. He'll show up right on<br>time, his arrival guaranteed by the Blessed and Undisputed Ruler,<br>High King, High God.<br>- 1 Tim. 6:14b-15 (The Message)<br></div>
</div>