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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
| from Tkinter import*
import os
#import urllib2, httplib
#import win32clipboard as w
#import Win32con
from tkFileDialog import askopenfilename
class MenuBar(Frame):
def __init__(self, boss):
Frame.__init__(self, borderwidth=2)
#menu #
fileMenu = Menubutton(self , text = 'File')
fileMenu.pack(side=LEFT)
self.edit = Menubutton(self , text='Edit')
self.edit.pack(side=LEFT,padx='4')
self.execute = Menubutton(self , text = 'Execute')
self.execute.pack(side=LEFT,padx='4')
self.help = Menubutton(self , text = 'Help')
self.help.pack(side=LEFT,padx='4')
#edit = Menubutton(self , text='Edit')
#self.edit.pack(side=LEFT,padx='3')
#execute = Menubutton(self , text = 'Execute')
#self.execute.pack(side=LEFT,padx='3')
#help = Menubutton(self , text = 'Help')
#self.help.pack(side=LEFT,padx='4')
#partie deroulante
me1= Menu(fileMenu)
me1.add_command(label ='New', underline =0,command = boss.nouveau)
me1.add_command(label ='Open', underline =0, command = boss.ouvrir)
me1.add_command(label ='Test', underline =0, command = boss.test)
me1.add_command(label ='Save', underline =0,command = boss.save)
me1=Menu(self.edit)
me1.add_command(label='Copy', underline =0, command = boss.copier)
me1.add_command(label='Paste', underline =0, command = boss.coller)
#me2.add_command(label='Cancel',underline=0,command=boss.annuler)
#me2.add_command(label='restor',underline=0,command=boss.retablir)
#m2.add_command(label='Selection', underline =0, command = boss.selectionner)
me1= Menu(self.execute)
me1.add_command(label='Run', underline =0, command = boss.save)
me1=Menu(self.help)
me1.add_command(label='Online documentation' , underline =0, command = boss.doc)
fileMenu.configure(menu = me1)
self.edit.configure(menu=me1)
self.execute.configure(menu=me1)
self.help.configure(menu=me1)
#creation des champs d'entree
self.lab=Label(self, text='Proj',fg='red',font=('Comic Sans MS',11))
self.lab.pack(padx=1,pady=1)
self.E_1=Entry(self, textvariable=boss.fichname)
self.E_1.pack(pady=1)
self.lab=Label(self, text='Output',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=2,pady=2)
self.E_2=Entry(self, textvariable=boss.output1)
self.E_2.pack(pady=2)
self.lab=Label(self, text='Plot',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=3,pady=3)
self.E_3=Entry(self, textvariable=boss.plot1)
self.E_3.pack(pady=3)
self.lab=Label(self, text='Intpar',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=4,pady=5)
self.E_4=Entry(self, textvariable=boss.intpar1)
self.E_4.pack(pady=4)
self.lab=Label(self, text='Doublepar',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=5,pady=6)
self.E_5=Entry(self, textvariable=boss.doublepar1)
self.E_5.pack(pady=5)
self.lab=Label(self, text='ComplexparRe',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=6,pady=7)
self.E_6=Entry(self, textvariable=boss.complexpar1)
self.E_6.pack(pady=6)
self.lab=Label(self, text='ComplexparIm',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=7,pady=8)
self.E_7=Entry(self, textvariable=boss.complexpar2)
self.E_7.pack(pady=7)
self.lab=Label(self, text='Meshfile',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=9,pady=10)
self.E_8=Entry(self, textvariable=boss.meshfile1)
self.E_8.pack(pady=7)
self.lab=Label(self, text='Auxfile',fg='red', font=('Comic Sans MS',11))
self.lab.pack(padx=9,pady=10)
self.E_9=Entry(self, textvariable=boss.auxfile1)
self.E_9.pack(pady=9)
#creation des boutons
self.bou1=Button(self, text='Run',command=boss.save)
self.bou1.pack(side=LEFT,padx='20',pady='20')
self.bou2=Button(self, text='Fill',command=boss.ouvrir)
self.bou2.pack(side=LEFT,padx='25',pady='25')
self.bou3=Button(self, text='Close', command = boss.destroy)
self.bou3.pack(side=LEFT,padx='30',pady='30')
class Application(Frame):
def __init__(self, boss =None):
Frame.__init__(self,)
self.master.title('Resolution of EC2D')
#self.text_defaut="aucun fichier ouvert!"
#self.lab_fichier = Label(self)
#self.lab_fichier.pack(padx=5, pady=5)
self.fichname = StringVar()
self.output1=StringVar()
self.plot1=StringVar()
self.intpar1=StringVar()
self.doublepar1=StringVar()
self.complexpar1=StringVar()
self.complexpar2=StringVar()
self.meshfile1=StringVar()
self.auxfile1=StringVar()
self.mBar = MenuBar(self)
self.mBar.pack()
self.can = Text(self,state=DISABLED,height=2,fg='black');
self.can.pack()
self.pack()
#def ouvrir(self):
#name = askopenfilenames(filetypes = [("All", "*"),("ofeli","*.m;*.dat;*.c;*.txt")])
# si l'utilisateur a bien selectionner un fichier
#if name:
#try:
#fichier = open(name, "r")
#fichier = open(name1,"r")
#self.meshfile1.set(name)
#self.auxfile1.set(name1)
#except IOError:
#text1=Label(self, text='Error, this file can not be opened!', fg='red')
#lab_fichier.config(text= "Error,this file can not be opened !")
#print "Error, this file can not be opened!"
#else:
#text2=Label(self, text=' this file can be opened!', fg='red')
#lab_fichier.config(text= " This file can be opened")
#print "this file can be opened!!"
#fichier.close()
# si l'utilisateur à cliquer sur annuler
#else:
#lab_fichier.config(text="no file selected")
#print "no file selected"
def ouvrir(self):
name = askopenfilename(filetypes = [("all","*"),("ofeli","*.dat")])
if name:
try:
fichier = open(name,"r")
except IOError:
self.message("Error this file can not be opened\n")
else:
#obtenir le contenu du fichier sous forme d'une liste de lignes
L=fichier.readlines()
#on ferme le fichier
fichier.close()
#print L
#print
#on retir les caracters de fin de ligne'\r' et/ou '\n'
L=[x.rstrip('\r\n') for x in L]
#print L
#print
#on transforme chaque ligne en sous -liste[clé, valeur]
L=[x.split() for x in L]
#print L
#print
#elimine la premiere et derniere ligne
L=L[1:-1]
#print L
#print
#elimine les lignes de commentaires
L=[x for x in L if x[0]!="#"]
print L
a= L[0][1]
self.fichname.set(a)
b=L[1][1]
self.output1.set(b)
c=L[2][1]
self.plot1.set(c)
d=L[3][1]
self.intpar1.set(d)
e=L[4][1]
self.doublepar1.set(e)
f=L[5][1]
self.complexpar1.set(f)
i=L[5][2]
self.complexpar2.set(i)
g=L[6][1]
self.meshfile1.set(g)
h=L[7][1]
self.auxfile1.set(h)
#print a
else:
print "no file selected!"
def test(self) :
fichier1=self.fichname.get()
taille1=len(fichier1)
fichier2=self.meshfile1.get()
taille2=len(fichier2)
fichier3=self.auxfile1.get()
taille3=len(fichier3)
#self.message("test\n")
if fichier1:
try:
fich1 = open('%s'%(fichier1),'r')
except IOError:
self.message("error1\n")
else:
if (str(fich1.readline())) != '#PARAM!\n' :
self.message("Error, the written name isn't a datafile\n")
self.E_1.delete(0,taille1)
fich1.close()
else:
try:
fich2 = open('%s'%(fichier2),'r')
except IOError:
self.message("error2\n")
else:
if (str(fich2.readline())) != '#MESH!\n' :
self.message("Error, the written name isn't a meshfile\n")
self.E_8.delete(0,taille2)
#fich2.close()
else:
try:
fich3 = open('%s'%(fichier3),'r')
except IOError:
self.message("error3\n")
else:
if (str(fich3.readline())) != '#NODE_FIELD!\n' :
self.message("Error, the written name isn't a auxfile\n")
self.E_9.delete(0,taille3)
#fich3.close()
else:
self.message("ok\n")
#fich2.close()
#fich3.close()
def message(self, text):
self.can.config(state=NORMAL)
self.can.insert(END,text)
self.can.config(state=DISABLED)
def nouveau(self):
a=" project"
self.fichname.set(a)
b=1
self.output1.set(b)
c=1
self.plot1.set(c)
d=1
self.intpar1.set(d)
e=10
self.doublepar1.set(e)
f=10
self.complexpar1.set(f)
i=0
self.complexpar2.set(i)
g="project.m"
self.meshfile1.set(g)
h="project.aux"
self.auxfile1.set(h)
def doc(self):
httplib.HTTPConnection.debuglevel = 1
request = urllib2.Request('http://www.ofeli.net')
opener = urllib2.build_opener()
f = opener.open(request)
def copier(self):
w.openClipboard()
d=GetClipboardData(win32con.CF_TEXT)
w.CloseClipboard()
return d
def coller(self):
w.openclipboard()
w.EmptyClipboard()
w.SetClipboardData(aType,aString)
w.closeClipboard()
#def annuler(self):
#def retablir(self):
#def seletionner(self):
def save(self) :
name=self.fichname.get()
file = open("%s"%(name),'w')
file.write('#PARAM!\n')
file.write('Proj %s\n'%(name))
output = self.output1.get()
file.write('Output %s\n'%(output))
plot = str(self.plot1.get())
file.write('Plot %s\n'%(plot))
file.write('#Voltage flag\n')
intpar = str(self.intpar1.get())
file.write('IntPar %s\n'%(intpar))
file.write('#Angular frenquency\n')
doublepar = str(self.doublepar1.get())
file.write('DoublePar %s\n'%(doublepar))
file.write('#Voltage\n')
complexparre= str(self.complexpar1.get())
complexparim= str(self.complexpar2.get())
file.write('ComplexPar %s %s\n'%(complexparre,complexparim))
meshfile = self.meshfile1.get()
file.write('MeshFile %s\n'%(meshfile))
auxfile = self.auxfile1.get()
file.write('AuxFile %s\n'%(auxfile))
file.write('EOF\n')
file.close()
def run(self) :
name=self.fichname.get()
file = open("%s"%(name),'w')
os.system((" C:/python24/projet/ofeli/bin/ec2d1 C:/python24/projet/ofeli/tests/demos/electromagnetics/eddycurrent2d-1/%s.dat"%(name)))
if __name__ == '__main__':
app = Application()
app.mainloop() |