You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.4 KiB

2 years ago
from tkinter import Tk, Button, Label, StringVar, Entry
from misc.parser import *
from misc.tokenizer import *
2 years ago
from lib.File import File_chaine as File
class Window(Tk):
def __init__(self):
Tk.__init__(self)
self.title("test")
2 years ago
self.geometry("500x600")
self.resizable(False, False)
self.layout()
def layout(self):
#TEXT
self.text = StringVar(value="")
2 years ago
self.label = Label(textvariable=self.text, background="#eaeaea", font=("Arial", 20))
self.label.pack(fill="x")
self.input = Entry(textvariable=self.text)
self.input.pack(fill="x")
Label(text="Pensez aux parenthèses et à utiliser des espaces avec EVAL_NPI", font=("Arial", 11)).pack(fill='x')
#BOUTTONS
2 years ago
bouttons = ["1", "2", "3", "+", "-", "4", "5", "6", "*", "/", "7", "8", "9", "^", "sqrt", "EVAL", "0", "DEL", "CLEAR", "exp", "(", ")", ".", "sin", "cos", "EVAL_NPI", "ESPACE"]
col = 0
row = 0
for b in bouttons:
if col == 5:
col = 0
row += 1
cmd = None
if b == "EVAL":
cmd = self.evalue
elif b == "DEL":
cmd = self.delete
elif b == "CLEAR":
cmd = self.clear
2 years ago
elif b == "EVAL_NPI":
cmd = self.evalue_npi
elif b == "ESPACE":
cmd = lambda: self.write(" ")
else:
cmd = lambda text = b: self.write(str(text))
2 years ago
Button(self, text=b, width=6, height=1, command=cmd).place(x=10+100*col, y=100+40*row)
col += 1
def write(self, text):
current = self.text.get()
self.text.set(current + text)
def delete(self):
current = self.text.get()
self.text.set(current[:-1])
def clear(self):
self.text.set("")
2 years ago
def evalue_npi(self):
try:
tokens = tokenize(self.text.get())
file = File()
for token in tokens:
file.enfiler(token)
exp = npi2tree(file)
self.text.set(exp.evalue())
except:
self.text.set("Erreur NPI")
def evalue(self):
try:
exp = npi2tree(shutting_yard(tokenize(self.text.get())))
self.text.set(exp.evalue())
except:
self.text.set("Erreur")