Today I came across an interesting situation when a line below is executed before the line proceeding it (line above). A simple version of the situation is posted below. A brief description: There are three QGroupBox() connected to the same window: groupboxA, groupboxB and groupboxC.
Groupbox B is hidden. Clicking the Ok button unhides a second groupBox B and hides first groupBox A. A repetitive clicking continues this sequence of hide/unhide events.
The very last line is calling calcA() method processing of which takes around 2-3 seconds to compete.
An issue: Even while a call for calcA() is on a last line it is being executed before QGroupBoxes visibilities are changed for which the code written above is responsible. I would like to know why it is happening and how to get around it.

from PyQt4 import QtGui, QtCore
class MyApp(object):
def __init__(self):
super(MyApp, self).__init__()
app = QtGui.QApplication(sys.argv)
self.mainWidget = QtGui.QWidget()
self.mainLayout = QtGui.QVBoxLayout()
self.mainWidget.setLayout(self.mainLayout)
# A
self.groupboxA = QtGui.QGroupBox()
self.layoutA = QtGui.QVBoxLayout()
self.groupboxA.setLayout(self.layoutA)
lineA = QtGui.QTextEdit('This is QGroupBox A')
self.layoutA.addWidget(lineA)
# B
self.groupboxB = QtGui.QGroupBox()
self.layoutB = QtGui.QVBoxLayout()
self.groupboxB.setLayout(self.layoutB)
self.groupboxB.setHidden(True)
labelB = QtGui.QLabel('This is QGroupBox B')
self.layoutB.addWidget(labelB)
# C
self.groupboxC = QtGui.QGroupBox()
self.layoutC = QtGui.QVBoxLayout()
self.groupboxC.setLayout(self.layoutC)
okButton = QtGui.QPushButton('OK')
okButton.clicked.connect(self.OK)
self.layoutC.addWidget(okButton)
self.mainLayout.addWidget(self.groupboxA)
self.mainLayout.addWidget(self.groupboxB)
self.mainLayout.addWidget(self.groupboxC)
self.mainWidget.show()
sys.exit(app.exec_())
def calcA(arg=None):
print "Task started..."
for i in range(5000000):
pass
print '...task completed.'
def OK(self):
if self.groupboxA.isHidden(): self.groupboxA.setHidden(False)
else: self.groupboxA.setHidden(True)
if self.groupboxB.isHidden(): self.groupboxB.setHidden(False)
else: self.groupboxB.setHidden(True)
self.calcA()
if __name__ == '__main__':
MyApp()