给刘老师热电的计算程序加了个qt的GUI,核心程序是用Fortran写的。原本是打算把代码编译成pyd,结果f2py模块各种问题,最后无奈,用qt把参数保存成文件作为输入。鉴于版权问题,刘老师的热电源程序就不给出来了。
PS:由于matplotlib读取文件有些麻烦,所以,就没整绘图的部分。
#coding=utf-8
import os
import matplotlib.pyplot as mp
from PyQt4 import QtGui,QtCore
import sys
class Window(QtGui.QWidget):
def __init__(self):
super(Window,self).__init__()
self.setWindowTitle(u"热电计算")
self.resize(300,400)
self.gridlayout = QtGui.QGridLayout()
self.L=QtGui.QLabel(u"透射点数:")
self.Ways=QtGui.QLabel(u"扫描方式:")
self.W_s=QtGui.QLabel(u"起始数据:")
self.W_e=QtGui.QLabel(u"终止数据:")
self.W_ss=QtGui.QLabel(u"步长:")
self.D=QtGui.QLabel(u"定值:")
self.calButton=QtGui.QPushButton("计算")
#self.playButton=QtGui.QPushButton("绘图")
self.textL=QtGui.QLineEdit("201")
self.QboxWays=QtGui.QComboBox()
self.QboxWays.addItem(u"温度")
self.QboxWays.addItem(u"能量")
self.textW_s=QtGui.QLineEdit("1")
self.textW_e=QtGui.QLineEdit("500")
self.textW_ss=QtGui.QLineEdit("5")
self.textD=QtGui.QLineEdit("0.0")
self.gridlayout.addWidget( self.L , 0, 0)
self.gridlayout.addWidget( self.textL , 0, 1)
self.gridlayout.addWidget( self.Ways , 1, 0)
self.gridlayout.addWidget( self.QboxWays , 1, 1)
self.gridlayout.addWidget( self.W_s , 2, 0)
self.gridlayout.addWidget( self.textW_s , 2, 1)
self.gridlayout.addWidget( self.W_e , 3, 0)
self.gridlayout.addWidget( self.textW_e, 3, 1)
self.gridlayout.addWidget( self.W_ss , 4, 0)
self.gridlayout.addWidget( self.textW_ss , 4, 1)
self.gridlayout.addWidget( self.D , 5, 0)
self.gridlayout.addWidget( self.textD , 5, 1)
self.gridlayout.addWidget( self.calButton , 6, 1)
#self.gridlayout.addWidget( self.playButton , 7, 1)
self.connect( self.calButton, QtCore.SIGNAL( 'clicked()' ), self.cal )
#self.connect( self.playButton, QtCore.SIGNAL( 'clicked()' ), self.play )
self.setLayout(self.gridlayout)
def cal(self):
f=open("commond.dat","w")
if self.QboxWays.currentText()=="能量":
s=self.textL.text()+"\t"+"1\t"+self.textW_s.text()+"\t"+self.textW_e.text()+"\t"+self.textW_ss.text()+"\t"+self.textD.text()
f.write(s)
else:
s=self.textL.text()+"\t0\t"+self.textW_s.text()+"\t"+self.textW_e.text()+"\t"+self.textW_ss.text()+"\t"+self.textD.text()
f.write(s)
os.system("M.exe")
def play(self):
return
app = QtGui.QApplication( sys.argv )
demo = Window()
demo.show()
app.exec_()
保存成Main.py文件后,可以利用cx_freeze打包成exe,打包好的程序就在dist目录下,别忘了把编译好的M.exe放进去。
cxfreeze Main.py --target-dir dist --base-name=win32gui
写的很不错,很详细全面