-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynthui.py
96 lines (76 loc) · 3.35 KB
/
synthui.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
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
import tkinter as tk
from tkinter import messagebox
import os
from synthesis import synthesis as synth
import idlelib.colorizer as ic
import idlelib.percolator as ip
import re
def run():
root = tk.Tk()
root.title("pysynth")
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
frame = tk.Frame(root)
frame.grid(row=0, column=0, padx=5, pady=2, sticky="news")
frame.rowconfigure(4, weight=1)
frame.columnconfigure(0, weight=1)
implementation = tk.Entry(frame, width=50)
implementation.insert(0, "write your specifications")
implementation.grid(row=0, column=0, sticky="news", pady=2)
example = tk.Entry(frame)
example.insert(0, "examples/")
example.grid(row=1, column=0, sticky="news")
synthesiseResult = tk.StringVar()
def clicked():
try:
lines = synth.import_from(example.get())
except IOError:
messagebox.showerror('pysynth error', "No file or directory for example code.")
return
if len(lines) == 0:
for (dirpath, dirnames, filenames) in os.walk(example.get()):
for file in filenames:
path = os.path.join(dirpath, file)
if "venv" not in path:
lines += synth.import_from(path)
if len(lines) == 0:
messagebox.showerror('pysynth error', 'No example code found.')
return
try:
code = synth.synthesize(implementation.get(), lines, 1,
verbose=False,
show_known=False,
single_output=False,
rename_after_each_step=True,
show_remaining=True)[0]
except Exception as e:
messagebox.showerror('pysynth error', str(e))
return
#code = code.replace("def solution", "def solution")
text.delete('1.0', tk.END)
text.insert(tk.END, code)
tk.Button(frame, text= "Synthesize", command=clicked).grid(row=2, column=0, sticky="news", pady=5)
resultFrame = tk.Frame(frame, pady=5)
resultFrame.grid(row=3, column=0, sticky="news")
resultFrame.rowconfigure(0, weight=1)
resultFrame.columnconfigure(2, weight=1)
# Add a Scrollbar(horizontal)
scroll = tk.Scrollbar(resultFrame, orient='vertical')
scroll.grid(row=0, column=1, sticky="news")
# Add a text widget
text = tk.Text(resultFrame, yscrollcommand=scroll.set)
cdg = ic.ColorDelegator()
cdg.prog = re.compile(r'\b(?P<MYGROUP>tkinter)\b|' + ic.make_pat(), re.S)
cdg.idprog = re.compile(r'\s+(\w+)', re.S)
cdg.tagdefs['MYGROUP'] = {'foreground': '#7F7F7F', 'background': '#FFFFFF'}
# These five lines are optional. If omitted, default colours are used.
cdg.tagdefs['COMMENT'] = {'foreground': '#FF0000', 'background': '#FFFFFF'}
cdg.tagdefs['KEYWORD'] = {'foreground': '#007F00', 'background': '#FFFFFF'}
cdg.tagdefs['BUILTIN'] = {'foreground': '#7F7F00', 'background': '#FFFFFF'}
cdg.tagdefs['STRING'] = {'foreground': '#7F3F00', 'background': '#FFFFFF'}
cdg.tagdefs['DEFINITION'] = {'foreground': '#007F7F', 'background': '#FFFFFF'}
ip.Percolator(text).insertfilter(cdg)
scroll.config(command=text.yview)
text.grid(row=0, column=0, sticky="news")
root.mainloop()
run()