<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 29, 2014 at 3:30 PM, Jones, Bryan <span dir="ltr"><<a href="mailto:bjones@ece.msstate.edu" target="_blank">bjones@ece.msstate.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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></div></blockquote><div><br></div><div>Yes, I had looked at that example. Quite possibly because of my lack of competence, I can not see how I can use the same approach in my case. The widgets I build are encapsulated inside a function; they are local to that function. When that function is called, it effectively stops the program execution as the event loop is waiting for some interaction. I do not see how to bypass that other than trying to start a delayed thread just before calling the function and attempt to use QTest to interact with the widget in that separate thread.</div><div><br></div><div>However, I have not programmed with threads very much before and thought it might be wise to ask on this list for more experienced people as to what would be the best way to proceed.</div><div><br></div><div>André</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>Bryan</div><div class="gmail_extra"><div><div class="h5"><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></div></div>-- <br><div>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 <a href="tel:662-325-3149" value="+16623253149" target="_blank">662-325-3149</a><br>fax <a href="tel:662-325-2298" value="+16623252298" target="_blank">662-325-2298</a><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>
</blockquote></div><br></div></div>