/
main.py
59 lines (53 loc) · 1.57 KB
/
main.py
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
import Tkinter as tk
from Tkinter import Menu
import ScrolledText
import sys
import threading
from parser import parse, error, ParserError,start
from interpreter import interpret
from lex import get_tokens
class StdoutRedirector(object):
def __init__(self,text_widget):
self.text_space = text_widget
def write(self,string):
self.text_space.insert('end', string)
self.text_space.see('end')
# http://knowpapa.com/text-editor/
root = tk.Tk(className="Best Language Ever")
textPad = ScrolledText.ScrolledText(root, width=300, height=30)
textPad.pack() # creates text area
textWidget = tk.Text(root,width=300, height=40,bg='black',fg='green',highlightcolor='yellow')
textWidget.pack()
sys.stdout = StdoutRedirector(textWidget)
# create a menu
def run():
global dictionary, code
# console.start()
code = textPad.get("1.0",tk.END+'-1c')
# print code
filename = 'test.vote'
newfile = open(filename,'w')
newfile.write(code )
newfile.close()
dictionary = get_tokens(filename)
if (dictionary):
try:
start()
except ParserError as e:
error(e,code)
return
interpret()
print 'done'
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Run", command=run)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=run)
helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=run)
# end of menu creation
# textPad.pack()
root.mainloop()