Skip to content

Commit

Permalink
Added syntax error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
spavlick committed Nov 6, 2014
1 parent ce3fa33 commit 2463df3
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 33 deletions.
11 changes: 0 additions & 11 deletions error.log
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1473, in __call__
return self.func(*args)
File "gui.py", line 472, in generate_netlist_errors
self.generate_netlist()
File "gui.py", line 349, in generate_netlist
self.getImpe()
File "gui.py", line 305, in getImpe
A=cmath.exp(-Psi*h[i1])
TypeError: 'int' object has no attribute '__getitem__'
31 changes: 31 additions & 0 deletions error_handling.py
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
#make sample interface and try adding two functions to button like it says on StackOverflow

import tkinter as tk
import time

class ButtonTimer:
def __init__(self, root):
self.master = root
self.button = tk.Button(self.master, text="press me") # Notice I haven't assigned the button a command - we're going to bind mouse events instead of using the built in command callback.
self.button.bind('<ButtonPress>', self.press) # call 'press' method when the button is pressed
self.button.configure(command=
self.button.bind('<ButtonRelease>', self.release) # call 'release' method when the button is released
self.label = tk.Label(self.master)
self.startTime = time.time()
self.endTime = self.startTime

self.button.grid(row=1, column=1)
self.label.grid(row=2, column=1)

def message(self):
tk.tkMessageBox(message='HI!!!!')

def press(self, *args):
self.startTime = time.time()

def release(self, *args):
self.endTime = time.time()
self.label.config(text="Time pressed: "+str(round(self.endTime - self.startTime, 2))+" seconds")

root = tk.Tk()
b = ButtonTimer(root)
root.mainloop()
1 change: 1 addition & 0 deletions error_handling.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#make sample interface and try adding two functions to button like it says on StackOverflow
94 changes: 84 additions & 10 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,78 @@ def resetgeom(self):
self.entries[key].delete(0,END)

def checkgeom(self):
self.syntaxCheck()
self.valueCheck()

def syntaxCheck(self):
try:
literal_eval(self.h.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for h')
try:
literal_eval(self.w.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for w')
try:
literal_eval(self.s.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for s')
try:
literal_eval(self.m.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for m')
try:
literal_eval(self.wstyle.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for wstyle')
try:
literal_eval(self.lindex.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for lindex')
try:
float(self.sigma.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for sigma. Please enter float value')
try:
float(self.mur.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for mur. Please enter float value')
try:
int(self.nlayer.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for nlayer. Please enter integer value')
try:
int(self.nwinding.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for nwinding. Please enter integer value')
try:
float(self.gt.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for gt. Please enter float value')
try:
float(self.gb.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for gb. Please enter float value')
try:
float(self.Ae.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for Ae. Please enter float value')
try:
float(self.le.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for le. Please enter float value')
try:
float(self.nc.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for nc. Please enter float value')
try:
float(self.c.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for c. Please enter float value')

def valueCheck(self):
nwinding=int(self.nwinding.get())
nlayer=int(self.nlayer.get())

if nwinding!= max(literal_eval(self.lindex.get())):
tkMessageBox.showerror(message='nwinding mismatch with lindex, please retry')
elif nwinding!= len(literal_eval(self.wstyle.get())):
Expand Down Expand Up @@ -276,7 +345,9 @@ def createbuttons(self):
Button(buttonframe,text='Reset Geometry',command=self.resetgeom).pack(side=LEFT,padx=5)
buttonframe.grid(row=0, columnspan=5)
Button(self,text='Check Geometry Status',command=self.checkgeom).grid(row=18,columnspan=5)
Button(self,text='Generate Netlist',command=self.generate_netlist_errors).grid(row=20,columnspan=5)
netlist_button=Button(self,text='Generate Netlist',command=self.generate_netlist_errors)
netlist_button.grid(row=20,columnspan=5)
#netlist_button.configure(command=self.generate_netlist_errors)

def getImpe(self):
sigma=float(self.sigma.get())
Expand Down Expand Up @@ -469,19 +540,22 @@ def generate_netlist(self):
tkMessageBox.showinfo(message='Successfully Generated Netlist')

def generate_netlist_errors(self):
self.generate_netlist()

tkMessageBox.showerror(message='Netlist not successfully generated')
#errorfile=open('error.log','r')
#for line in errorfile:
# tkMessageBox.showerror(message=line)
#errorfile.close()
try:
self.generate_netlist()
except Exception:
tkMessageBox.showerror(message='Netlist not successfully generated')
'''if os.path.getsize('error.log') > 0:
tkMessageBox.showerror(message='Netlist not successfully generated')
errorfile=open('error.log','r')
for line in errorfile:
tkMessageBox.showerror(message=line)
errorfile.close()'''

class ScrollbarFrame(Frame):
def __init__(self, root):

Frame.__init__(self, root)
self.canvas = Canvas(root, borderwidth=0, background="#ffffff")
self.canvas = Canvas(root, borderwidth=0)
self.frame = GUI(root)
self.hsb = Scrollbar(root, orient="horizontal", command=self.canvas.xview)
self.vsb = Scrollbar(root, orient="vertical", command=self.canvas.yview)
Expand Down
81 changes: 75 additions & 6 deletions gui.py~
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,71 @@ class GUI(Frame):
nwinding=int(self.nwinding.get())
nlayer=int(self.nlayer.get())

try:
literal_eval(self.h.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for h')
try:
literal_eval(self.w.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for w')
try:
literal_eval(self.s.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for s')
try:
literal_eval(self.m.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for m')
try:
literal_eval(self.wstyle.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for wstyle')
try:
literal_eval(self.lindex.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for lindex')
try:
float(self.sigma.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for sigma. Please enter float value')
try:
float(self.mur.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for mur. Please enter float value')
try:
int(self.nlayer.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for nlayer. Please enter integer value')
try:
int(self.nwinding.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for nwinding. Please enter integer value')
try:
float(self.gt.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for gt. Please enter float value')
try:
float(self.gb.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for gb. Please enter float value')
try:
float(self.Ae.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for Ae. Please enter float value')
try:
float(self.le.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for le. Please enter float value')
try:
float(self.nc.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for nc. Please enter float value')
try:
float(self.c.get())
except SyntaxError:
tkMessageBox.showerror(message='incorrect entry format for c. Please enter float value')

if nwinding!= max(literal_eval(self.lindex.get())):
tkMessageBox.showerror(message='nwinding mismatch with lindex, please retry')
elif nwinding!= len(literal_eval(self.wstyle.get())):
Expand Down Expand Up @@ -276,7 +341,9 @@ class GUI(Frame):
Button(buttonframe,text='Reset Geometry',command=self.resetgeom).pack(side=LEFT,padx=5)
buttonframe.grid(row=0, columnspan=5)
Button(self,text='Check Geometry Status',command=self.checkgeom).grid(row=18,columnspan=5)
Button(self,text='Generate Netlist',command=self.generate_netlist_errors).grid(row=20,columnspan=5)
netlist_button=Button(self,text='Generate Netlist',command=self.generate_netlist_errors)
netlist_button.grid(row=20,columnspan=5)
#netlist_button.configure(command=self.generate_netlist_errors)

def getImpe(self):
sigma=float(self.sigma.get())
Expand Down Expand Up @@ -473,16 +540,18 @@ class GUI(Frame):
self.generate_netlist()
except Exception:
tkMessageBox.showerror(message='Netlist not successfully generated')
#errorfile=open('error.log','r')
#for line in errorfile:
# tkMessageBox.showerror(message=line)
#errorfile.close()
'''if os.path.getsize('error.log') > 0:
tkMessageBox.showerror(message='Netlist not successfully generated')
errorfile=open('error.log','r')
for line in errorfile:
tkMessageBox.showerror(message=line)
errorfile.close()'''

class ScrollbarFrame(Frame):
def __init__(self, root):

Frame.__init__(self, root)
self.canvas = Canvas(root, borderwidth=0, background="#ffffff")
self.canvas = Canvas(root, borderwidth=0)
self.frame = GUI(root)
self.hsb = Scrollbar(root, orient="horizontal", command=self.canvas.xview)
self.vsb = Scrollbar(root, orient="vertical", command=self.canvas.yview)
Expand Down
7 changes: 4 additions & 3 deletions stderr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from ast import literal_eval

'''fsock=open('error.log','w')
sys.stderr=fsock'''

fsock=open('error.log','w')
sys.stderr=fsock
frg
8 changes: 5 additions & 3 deletions stderr.py~
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
from ast import literal_eval

fsock=open('error.log','w')
sys.stderr=fsock
raise Exception, 'this error will be logged'
'''fsock=open('error.log','w')
sys.stderr=fsock'''
s=literal_eval('6 2')
print s

0 comments on commit 2463df3

Please sign in to comment.