我是PyQt4的新手,正在学习如何在后端将它与我的Python代码集成。我做的方式,前端看起来很好,并采取我需要的所有输入。处理开始时,即后端脚本运行时,窗口消失,并在我的所有后端脚本完成后重新出现。该窗口应该显示正在进行的进程的状态(在后端)。 请帮帮我。
Win2上的一个按钮使其切换到Win4,即Win4消失后,所有后端处理完成后重新出现。
代码段:
class Win2(QtGui.QMainWindow, w2):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.move(500,200)
self.window1 = None
self.window4 = None
self.window5 = None
self.window6 = None
self.pushButton_2.clicked.connect(self.showWin4)
self.pushButton_9.clicked.connect(self.showWin5)
self.pushButton_5.clicked.connect(self.showWin6)
self.pushButton_8.clicked.connect(self.openIP)
self.pushButton_7.clicked.connect(self.opencred)
self.pushButton_6.clicked.connect(self.showWin1)
def openIP(self):
self.filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
#print filename
self.label_7.setText(self.filename)
def from_alldevicesrun(self):
#print check_port.all_ips
with open(self.filename, "rb") as csvfile:
iprow = csv.reader(csvfile, delimiter='\n')
for [ip] in iprow:
#print ip
from_alldevices.ips.append(ip)
csvfile.close()
from_alldevices.main()
def opencred(self):
self.filename1 = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
#print filename1
self.label_9.setText(self.filename1)
def see_cred(self):
'''
import __builtin__
__builtin__.x = self.filename1
import check_credentials_both
'''
cmd = ['python', 'c.py' ]
cmd_out = subprocess.Popen( cmd , stdout=subprocess.PIPE).communicate()[0]
def showWin4(self):
self.close()
if self.window4 is None:
self.window4 = Win4()
self.window4.show()
self.window4.set_status_7('Ongoing')
self.from_alldevicesrun()
self.window4.set_status_7('Done')
self.window4.set_status_13('Ongoing')
self.see_cred()
self.window4.set_status_13('Done')
self.window4.set_status_8('Ongoing')
self.window4.get_data_from_server()
self.window4.set_status_8('Done')
self.window4.set_status_9('Ongoing')
self.window4.SSH_into_nw()
self.window4.set_status_9('Done')
self.window4.set_status_10('Ongoing')
self.window4.extract_mac()
self.window4.extract_lldp()
self.window4.port_channel_change()
self.window4.final_algo()
self.window4.set_status_10('Done')
self.window4.showWin10()
def showWin5(self):
if self.window5 is None:
self.window5 = Win5(self)
self.window5.show()
def showWin6(self):
if self.window6 is None:
self.window6 = Win6(self)
self.window6.show()
def showWin1(self):
self.close()
if self.window1 is None:
self.window1 = Win1(self)
self.window1.show()
class Win4(QtGui.QDialog, w4):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.move(500,200)
self.window10 = None
self.pushButton.clicked.connect(self.show_graphandWin8)
self.pushButton_2.clicked.connect(self.showWin10)
self.window8 = None
def show_graphandWin8(self):
#self.close()
if self.window8 is None:
self.window8 = Win8(self)
self.window8.show()
cmd = ['python', 'dc.py' ]
cmd_out = subprocess.Popen( cmd , stdout=subprocess.PIPE).communicate()[0]
def set_status_7(self,text):
self.label_7.setText(text)
def set_status_8(self,text):
self.label_8.setText(text)
def set_status_9(self,text):
self.label_9.setText(text)
def set_status_10(self,text):
self.label_10.setText(text)
def set_status_13(self,text):
self.label_13.setText(text)
def get_data_from_server(self):
get_data_from_servers.main()
def SSH_into_nw(self):
import SSH_and_telnet_nw
SSH_and_telnet_nw.main()
def extract_mac(self):
cmd = ['python', '123.py' ]
cmd_out = subprocess.Popen( cmd , stdout=subprocess.PIPE).communicate()[0]
def extract_lldp(self):
cmd = ['python', 'qwe.py' ]
cmd_out = subprocess.Popen( cmd , stdout=subprocess.PIPE).communicate()[0]
def port_channel_change(self):
import change_to_port_channel
change_to_port_channel.main()
def final_algo(self):
cmd = ['python', 'abc.py' ]
cmd_out = subprocess.Popen( cmd , stdout=subprocess.PIPE).communicate()[0]
def showWin10(self):
if self.window10 is None:
self.window10 = Win10(self)
self.window10.show()
def main():
app = QtGui.QApplication(sys.argv)
form = Win2()
form.show()
sys.exit(app.exec_())
提前谢谢。