Show a window before calling a terminal command in python
-
Hey i am a newbie in in python and qt so forgive me if my question is silly.In the following code i have a single window with exit and execute button from the class example. When i click the execute button i try to create a new window from the class newwin and then execute some terminal commands. In this case i execute three simple commands. The problem is that the commands is executed first and the window shows up after the commands ended . How i can fix that?
@
import sys
import os
from PyQt4 import QtCore, QtGuiclass newwin(QtGui.QWidget):
def cancel(self):
self.close()
def init(self,parent=None):
QtGui.QWidget.init(self, parent)self.resize(320, 128) self.setWindowTitle('Waiting') self.label = QtGui.QLabel('Pleace wait. This may take a while', self) self.label.setGeometry(60, 30, 225, 31)
self.label.show()
self.quit=QtGui.QPushButton('Cancel', self)
self.quit.setGeometry(190, 90, 88, 27)
self.quit.show()
self.quit.clicked.connect(self.cancel)class Example(QtGui.QWidget):
def __init__(self, parent=None):
self.Window2 = newwin()
QtGui.QWidget.init(self, parent)
self.initUI()def initUI(self): self.pushButton_4 = QtGui.QPushButton("Execute",self) self.pushButton_4.setGeometry(QtCore.QRect(20, 300, 88, 27)) self.pushButton_5 = QtGui.QPushButton("Exit",self) self.pushButton_5.setGeometry(QtCore.QRect(270, 300, 88, 27)) self.pushButton_5.clicked.connect(QtCore.QCoreApplication.instance().quit) self.pushButton_4.clicked.connect(self.execute) self.resize(394, 345) self.setWindowTitle('QtSimple') self.show() def execute(self,state):
self.Window2.show()
os.system("sleep 2s")
os.system("echo the window is not appeared yet")
os.system("sleep 2s")def main():
app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
if name == 'main':
main()
@