Pawankumar Dubey Pawankumar Dubey - 8 months ago 45
Python Question

Waiting in for loop until QRadioButton get checked everytime?

I have a situation where i need to get Pass/Fail from tester for every test step in PySide GUI. Now the data of testsuite i am running in for loop and trying to get current checked/unchecked state of QRadioButton in for loop based on which i will do further code processing.
My code is :-

for i in range(self.ui.hlfDataset_sa_lst.count()):


print "command ", str(self.ui.hlfDataset_sa_lst.item(i).text())
print "Run ", str(i)+" is here"
self.telnetThread = TelnetThread.SocketTunnel("localhost",2000)
returnCommand = self.telnetThread.communicateSock(str(self.ui.hlfDataset_sa_lst.item(i).text()))
print "returnCommand ",returnCommand
##XML Data structure
result = ET.SubElement(results,"result")
testcasestepno = ET.SubElement(result,"testcasestepno")
testerComment = ET.SubElement(result,"testerComment")
testresult = ET.SubElement(result,"testresult")
mguImage = ET.SubElement(result,"mguImage")

if self.ui.pass_radio.isChecked():
print "TC passed "
testcasestepno.text = str(i+1)
testresult.text = "PASS"
mguImage.text = "NA"
elif self.ui.fail_radio.isChecked():
if not str(self.ui.testercomment_txt.text()):
QtGui.QMessageBox.critical(self, 'Tester Comment ', 'Tester Comment is desired ', QtGui.QMessageBox.Ok)
print "TC failed "
testcasestepno.text = str(i+1)
testresult.text = "FAIL"
testerComment.text = str(self.ui.testercomment_txt.text())
#Save Live Image when failed

I want for loop to wait until tester has provided the input and i don't want to put sleep or in anyway to use thread unless convenient way is shown.
This code runs complete loop without waiting for input.

Answer Source

If I understood you correctly, you want to wait until one of buttons (fail_radio or pass_radio) is checked before if self.ui.pass_radio.isChecked(): line.

In Qt, you can achieve this using QEventLoop like here: waiting for a signal, where signal you want to wait for is clicked. You need to connect both buttons' signals to quit slot before executing it. For signal/slot connecting in PyQt you can look here:

So you need to write something like:

loop = QtCore.QEventLoop()