[PyQt] Testing a standalone dialog widget
andre.roberge at gmail.com
Mon Dec 29 22:05:28 GMT 2014
On Mon, Dec 29, 2014 at 3:30 PM, Jones, Bryan <bjones at ece.msstate.edu>
> Have you read through http://johnnado.com/pyqt-qtest-example/? That shows
> testing a dialog box (no threads necessary).
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.
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.
> On Sun, Dec 28, 2014 at 7:19 AM, Andre Roberge <andre.roberge at gmail.com>
>> 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,
>> if ok:
>> return text
>> if __name__ == '__main__':
>> print(get_string()) # normal blocking mode
>> app2 = QtGui.QApplication()
>> # perhaps start a delayed thread here, using QTest
>> 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
> 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...
More information about the PyQt