等待循环直到 QRadioButton 每次都被检查? [英] Waiting in for loop until QRadioButton get checked everytime?

查看:39
本文介绍了等待循环直到 QRadioButton 每次都被检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我需要从测试人员那里获取 PySide GUI 中每个测试步骤的通过/失败信息.现在我在 for 循环中运行 testsuite 的数据并尝试在 for 循环中获取 QRadioButton 的当前选中/未选中状态,我将根据它进行进一步的代码处理.我的代码是:-

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()):

    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

我希望 for 循环一直等到测试人员提供了输入,并且除非显示方便的方法,否则我不想休眠或以任何方式使用线程.此代码运行完整循环,无需等待输入.

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.

推荐答案

如果我没理解错的话,你想等到一个按钮(fail_radiopass_radio)在 if self.ui.pass_radio.isChecked(): 行之前检查.

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.

在 Qt 中,您可以使用 QEventLoop 实现这一点,如下所示:等待信号,您想要等待的信号被点击.在执行之前,您需要将两个按钮的信号连接到 quit 插槽.对于 PyQt 中的信号/插槽连接,您可以在这里查看:http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html

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: http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html

所以你需要写一些类似的东西:

So you need to write something like:

loop = QtCore.QEventLoop()
self.ui.fail_radio.clicked.connect(loop.quit)
self.ui.pass_radio.clicked.connect(loop.quit)
loop._exec()

这篇关于等待循环直到 QRadioButton 每次都被检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆