[PyQt] Testing a standalone dialog widget

Jones, Bryan bjones at ece.msstate.edu
Mon Dec 29 19:30:57 GMT 2014


Andre,

Have you read through http://johnnado.com/pyqt-qtest-example/? That shows
testing a dialog box (no threads necessary).

Bryan

On Sun, Dec 28, 2014 at 7:19 AM, Andre Roberge <andre.roberge at gmail.com>
wrote:

>  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:
>
>  ->>> name = input("What is your name? )
>
>  I could write
>
>  ->>> name = get_string("What is your name? )
>
>  and a dialog would pop up, inviting the user to enter the response.
>
>  I would like to set up some automatic testing of these widgets.  I tried
> with a third-party module
> (pyautogui) which interacts with GUI programs, but the result is not
> totally reliable.
> I would prefer to use QTest but do not know how to connect with the
> dialog; I suspect I may have
> to use threading (as I had to do with the pyautogui solution) as the
> dialog is effectively blocking the execution of the program.
>
>  Here is a simple implementation of get_string() mentioned above:
>
>  from PyQt4 import QtGui
>
>  def get_string(prompt="What is your name? ", title="Title",
>                default_response="PyQt4", app=None):
>     """GUI equivalent of input()."""
>
>      if app is None:
>         app = QtGui.QApplication([])
>     app.dialog = QtGui.QInputDialog()
>     text, ok = app.dialog.getText(None, title, prompt,
>                                   QtGui.QLineEdit.Normal,
>                                   default_response)
>     app.quit()
>     if ok:
>         return text
>
>  if __name__ == '__main__':
>     print(get_string())  # normal blocking mode
>     app2 = QtGui.QApplication([])
>         # perhaps start a delayed thread here, using QTest
>     print(get_string(app=app2))
>
>
>  =======
> Any help would be appreciated.
>
>  André Roberge
>



-- 
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298

Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141229/8c9058a7/attachment.html>


More information about the PyQt mailing list