我有一种情况,我需要在PySide GUI的每个测试步骤中从测试仪获得通过/失败。现在testuite的数据我正在运行for循环并尝试在for循环中获取当前检查/未检查的QRadioButton状态,我将进行进一步的代码处理。 我的代码是: -
for i in range(self.ui.hlfDataset_sa_lst.count()):
self.ui.pass_radio.setChecked(False)
self.ui.fail_radio.setChecked(False)
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"
testerComment.text=str(self.ui.testercomment_txt.text())
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)
self.ui.pass_radio.setChecked(False)
self.ui.fail_radio.setChecked(False)
else:
print "TC failed "
testcasestepno.text = str(i+1)
testresult.text = "FAIL"
testerComment.text = str(self.ui.testercomment_txt.text())
#Save Live Image when failed
我想让循环等到测试者提供输入并且我不想放入睡眠或者无论如何都要使用线程,除非显示方便的方法。 此代码运行完整循环,无需等待输入。
答案 0 :(得分:1)
如果我理解正确,您需要等到fail_radio
行之前检查其中一个按钮(pass_radio
或if self.ui.pass_radio.isChecked():
)。
在Qt中,您可以使用QEventLoop实现此目的,如下所示:
waiting for a signal,您要等待的信号是clicked
。在执行之前,您需要将两个按钮的信号连接到quit
插槽。对于PyQt中的信号/插槽连接,您可以在这里查看:
http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html
所以你需要写一些像:
loop = QtCore.QEventLoop()
self.ui.fail_radio.clicked.connect(loop.quit)
self.ui.pass_radio.clicked.connect(loop.quit)
loop._exec()