1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| from Tkinter import*
import os
from tkFileDialog import askopenfilename
class MenuBar(Frame):
def __init__(self, boss):
Frame.__init__(self, borderwidth=2)
self.E_1=Entry(self, textvariable=boss.fichname)
self.E_1.pack(pady=10)
self.E_2=Entry(self, textvariable=boss.filename)
self.E_2.pack(pady=11)
#self.lab=Label(self, text='MeshFile',bg='red', font=('Comic Sans MS',11)
#self.lab.pack(padx=1)
self.E_3=Entry(self, textvariable=boss.timemax)
self.E_3.pack(pady=12)
self.E_4=Entry(self, textvariable=boss.steptime)
self.E_4.pack(pady=13)
#menu #
fileMenu = Menubutton(self , text = 'Files')
fileMenu.pack(side=LEFT,padx='2')
edeting = Menubutton(self , text='Edetind')
edeting.pack(side=LEFT,padx='4')
executing = Menubutton(self , text = 'executing')
executing.pack(side=RIGHT,padx='6')
me1= Menu(fileMenu)
me1.add_command(label ='Open', underline =0, command = boss.ouvrir)
me1.add_command(label ='Test', underline =0, command = boss.test)
me2=Menu(edeting)
#me2.add_command(label='Copy', underline =0, command = boss.copier)
#me2.add_command(label='Paste', underline =0, command = boss.coller)
#m2.add_command(label='Selection', underline =0, command = boss.selectionner)
me3= Menu(executing)
me3.add_command(label='Run', underline =0, command = boss.run)
#me1.add_command(label ='Run', underline =0, command = boss.run)
#me1.add_command(label = 'Close', underline =0, command = boss.quit)
fileMenu.configure(menu = me1)
edeting.configure(menu=me2)
executing.configure(menu=me3)
class Application(Frame):
def __init__(self, boss =None):
Frame.__init__(self)
self.master.title('resolution exercice 4')
self.filename = StringVar()
self.fichname=StringVar()
self.timemax=StringVar()
self.steptime=StringVar()
self.mBar = MenuBar(self)
self.mBar.pack()
self.can = Canvas(self, bg='grey40',height=190, width=250, borderwidth= 2)
self.can.pack()
self.pack()
def ouvrir(self):
name = askopenfilename(filetypes = [("All", "*"),("ex4","*.m;*.c;*.txt")])
# si l'utilisateur a bien selectionner un fichier
if name:
try:
fichier = open(name, "r")
self.filename.set(name)
except IOError:
#text1=Label(self, text='Error, this file can not be opened!', fg='red')
print "Error,this file can not be opened !"
else:
#text2=Label(self, text=' this file can be opened!', fg='red')
print " This file can be opened"
fichier.close()
# si l'utilisateur à cliquer sur annuler
else:
print "No file selected !"
def test(self) :
#fichier=self.mBar.E_1.get()
#E_1.pack(pady=2)
#fichier =E_1.get()
#taille = os.stat(fichier).st_size
fichier=self.filename.get()
taille=len(fichier)
print(fichier)
fich = open('%s'%(fichier),'r')
#fich=open(fichier,"r")
if str(fich.readline()) != '#MESH!\n' :
print "Error,this file is not a mesh file !"
entree.delete(0,taille)
else :
print "You can execute"
fich.close()
def run(self) :
name=self.fichname.get()
file = open("%s"%(name),'w')
file.write('#PARAM!\n')
file.write('Proj %s\n'%(name))
meshfile = self.filename.get()
file.write('MeshFile /python24/projet/ex4/%s\n'%(meshfile))
maxtime = str(self.timemax.get())
file.write('MaxTime %s\n'%(maxtime))
timestep = str(self.steptime.get())
file.write('TimeStep %s\n'%(timestep))
file.write('EOF\n')
file.close()
#fichier = self.filename.get()
os.system(("C:/python24/projet/%s/ex4 C:/python24/projet/ofeli/bin/ex4/%s"%(name,name)))
if __name__ == '__main__':
app = Application()
app.mainloop() |
Partager