1

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

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.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Pawankumar Dubey
  • 387
  • 1
  • 6
  • 21

1 Answers1

1

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: 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()
Community
  • 1
  • 1
ukrkyi
  • 38
  • 7
  • The syntax for signal connection provided in the PyQt5 example also works for PyQt4 since version 4.5. It is very unlikely anyone is using a version of PyQt4 older than 4.5 (v4.5 was released over 7 years ago!). The "new style" syntax is thus preferred for PyQt4 examples as well! See [here](http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html) for more details. – three_pineapples Nov 23 '16 at 10:48
  • @three_pineapples, thank you for clarification, I'm using Qt and Python separately so I didn't know that... – ukrkyi Nov 23 '16 at 11:01
  • Thanks for the respone, i getting Encountered "exec" at line 176, column 14. Was expecting: ... at loop.exec() – Pawankumar Dubey Nov 23 '16 at 11:16
  • Okay, its loop._exec() – Pawankumar Dubey Nov 23 '16 at 11:20
  • @PawankumarDubey, heh, sorry – ukrkyi Nov 23 '16 at 11:25
  • It worked like charm, i just have to call _exec() in for loop. Thanks i am not able to write you name. :) – Pawankumar Dubey Nov 23 '16 at 12:15
  • @ukrkyi Stuck with this, do you have any answer for http://stackoverflow.com/questions/40804580/unable-to-click-on-qradiobutton-after-linking-it-with-qtcore-qeventloop – Pawankumar Dubey Nov 25 '16 at 12:20