我有以下代码:
def run(self):
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".inp")
if filename == "":
pass
elif filename != "":
nfile = open(filename, 'w')
self.pixmap1 = QtGui.QPixmap('yellow.jpg')
self.canvas1.setPixmap(self.pixmap1)
self.cursor.movePosition(self.cursor.Start, self.cursor.MoveAnchor)
self.cursor.movePosition(self.cursor.End, self.cursor.KeepAnchor)
text = self.cursor.selection()
text1 = text.toPlainText()
nfile.write(text1)
nfile.close()
fileInfo = QtCore.QFileInfo(filename)
name = fileInfo.baseName()
import os
os.system("rungms {}.inp 13-64 {} {} {}.out".format(name, self.cores_val, self.clusters_val, name))
from itertools import islice
import sys
with open("{}.out".format(name)) as searchfile:
for line in searchfile:
if 'TERMINATED NORMALLY' in line:
self.pixmap1 = QtGui.QPixmap('green.jpg')
self.canvas1.setPixmap(self.pixmap1)
elif 'job aborted' in line:
self.pixmap1 = QtGui.QPixmap('red.jpg')
self.canvas1.setPixmap(self.pixmap1)
else:
pass
else:
pass
我的问题是保存文件后没有读取涉及QPixmap('yellow.jpg')
的两行。但是,如果我在代码的第一行和第二行之间移动这两行(即在filename = QtGui ...之前),那么它们就可以工作。
有人可以向我解释为什么会这样吗?