<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>