-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.py
More file actions
257 lines (199 loc) · 12.8 KB
/
View.py
File metadata and controls
257 lines (199 loc) · 12.8 KB
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
from EvolvingRegExGen.EvolvingRegExGeneratorController import EvolvingRegExGeneratorController
from LLMRegExGen.LLMRegExGeneratorController import LLMRegExGeneratorController
from ParallelRegExGen.parallelController import ParallelController
from CheckRegExController import CheckRegExController
from tkinter import *
evolvingRegExGenController: EvolvingRegExGeneratorController = EvolvingRegExGeneratorController()
llmRegExGeneratorController: LLMRegExGeneratorController= LLMRegExGeneratorController()
checkRegExController: CheckRegExController = CheckRegExController()
parallelController: ParallelController = ParallelController()
window = Tk()
window.rowconfigure(0,weight=1)
window.columnconfigure(0,weight=1)
window.geometry("1366x768")
window.title('RegEx Generator')
mainPage= Frame(window)
davidPage=Frame(window)
jannesPage=Frame(window)
mattiPage=Frame(window)
checkPage=Frame(window)
for frame in (mainPage,davidPage,jannesPage,mattiPage,checkPage):
frame.grid(row=0, column=0, sticky='nsew')
def show_frame(frame):
global current_frame
current_frame = frame
frame.tkraise()
show_frame(mainPage)
current_frame = None
#-------- colors and fonts --------
label_font = ("fixedsys", 16, "bold")
higlight_blue = '#0184FF'
frame_background = '#050A37'
secondary_background = '#063A6B'
#----------------------------------
copy_image = PhotoImage(file='copy_button.png')
copy_image_label = Label(image=copy_image)
preset_text="Enter your string input(s). You may provide multiple strings. \nIf the inputs share a common pattern, a regular expression (regex) \nwill be generated when you press the 'Generate' button"
results = ['hallo@gmail.com']
checkPage_input = []
checkPage_input_regex: str
regex_output = ''
def get_text_and_source():
global current_frame, regex_output
if current_frame == davidPage:
text = davidPage_textfield.get("1.0", "end-1c").strip()
results = text.splitlines()
test = llmRegExGeneratorController.generateRegExFromStringList(results)
regex_output = test
davidPage_output.configure(text=regex_output)
print("Frame: DavidPage")
print("Output: "+test+" "+regex_output)
print("Button: RegEx Check (DavidPage)")
elif current_frame == jannesPage:
text = jannesPage_textfield.get("1.0", "end-1c").strip()
results = text.splitlines()
test = evolvingRegExGenController.generateRegExFromStringList(results)
regex_output = test
jannesPage_output.configure(text=regex_output)
print("Frame: JannesPage")
print("Output: "+test+".."+regex_output)
print("Button: RegEx Check (JannesPage)")
elif current_frame == mattiPage:
text = mattiPage_textfield.get("1.0", "end-1c").strip()
results = text.splitlines()
test = parallelController.generate_regex_from_strings(results)
regex_output = test
mattiPage_output.configure(text=regex_output)
print("Frame: MattiPage")
print("Output: "+" "+regex_output)
print("Button: RegEx Check (MattiPage)")
else:
print("Kein unterstützter Frame aktiv.")
return
print("Results (Liste von Strings):", results)
def get_text_from_checkpage():
global checkPage_input,checkPage_input_regex
text = checkPage_textfield_one.get("1.0", "end-1c").strip()
checkPage_input = text.splitlines()
checkPage_input_regex = checkPage_textfield_two.get("1.0",'end-1c')
print(checkPage_input)
print(checkPage_input_regex +' \n\n')
info = checkRegExController.check_for_match(checkPage_input_regex,checkPage_input)
if info == False:
checkPage_checkButton.configure(bg='#D85456',fg='white')
else:
checkPage_checkButton.configure(bg='#7AB495',fg='white')
def copy_to_clipboard(page, output):
page.clipboard_clear()
page.clipboard_append(output.cget("text"))
page.update()
def clear_text_on_focus(event, widget):
if widget.get("1.0", "end-1c") == preset_text:
widget.delete("1.0", "end")
widget.config(fg="black",font=("Helvetica", 14))
widget.unbind("<Button-1>")
#-----------menu page ----------------
mainPage_canvas = Canvas( mainPage,bg = frame_background,height = 768,width = 1366,bd = 0,highlightthickness = 0,relief = "ridge")
mainPage_canvas.place(x = 0, y = 0)
mainPage_canvas.create_rectangle(15.0,16.0,890.0,752.0,fill=secondary_background,outline="")
mainPage_canvas.create_text(175,300,anchor="nw",text="RegEx Generator",fill="white",font=("Cooper Black", 64 * -1))
mainPage_choose = Label(mainPage,text='Choose your model',anchor='center',background=higlight_blue,font=('fixedsys',20),fg='white')
mainPage_choose.place(x=115,y=380,width=675,height=100)
mainPage_davidButton= Button(mainPage,text='LLM-Model',font=label_font,bg=higlight_blue,fg='white',command=lambda: show_frame(davidPage))
mainPage_davidButton.place(x=947, y=175, width=360, height=80)
mainPage_jannesButton= Button(mainPage,text='Evolving-Model',width=50,font=label_font,height=5,bg=higlight_blue,fg='white',command=lambda: show_frame(jannesPage))
mainPage_jannesButton.place(x=947,y=294, width=360, height=80)
mainPage_mattiButton= Button(mainPage,text='Iterative-Model',width=50,height=5,font=label_font,bg=higlight_blue,fg='white',command=lambda: show_frame(mattiPage))
mainPage_mattiButton.place(x=947,y=413, width=360, height=80)
mainPage_checkButton= Button(mainPage, text='RegEx Check',width=30,height=2,bg='#0056A7',fg='white',font='fixedsys',command=lambda: show_frame(checkPage))
mainPage_checkButton.place(x=1000,y=580)
#-----------david page ----------------
davidPage_canvas = Canvas(davidPage,bg = frame_background,height = 768,width = 1366,bd = 0,highlightthickness = 0,relief = "ridge")
davidPage_canvas.place(x = 0, y = 0)
davidPage_canvas.create_rectangle(15.0,16.0,890.0,752.0,fill=secondary_background,outline="")
davidPage_textfield = Text(davidPage, wrap=WORD, font=("Helvetica", 14,'italic'),fg='lightgrey')
davidPage_textfield.place(x=26, y=40, height=470, width=850)
davidPage_textfield.insert('1.0',preset_text)
davidPage_textfield.bind("<Button-1>", lambda event: clear_text_on_focus(event, davidPage_textfield))
davidPage_generateButton= Button(davidPage, text='Generate',bg=higlight_blue,fg='white',font=label_font,command=get_text_and_source)
davidPage_generateButton.place(x=26,y=515,width=850,height=70)
davidPage_output= Label(davidPage,text=regex_output,anchor='center',background=secondary_background,font=20,fg='white')
davidPage_output.place(x=25,y=625,width=750,height=75)
davidPage_copy= Button(davidPage,text='c',image = copy_image,command= lambda:copy_to_clipboard(davidPage,davidPage_output), borderwidth=0)
davidPage_copy.place(x=800,y=635,width=50,height=50)
davidPage_menuButton = Button(davidPage,text='RegEx Generator',background=higlight_blue,fg='white',command=lambda: show_frame(mainPage))
davidPage_menuButton.place(x=1055,y=660,width=150,height=30)
davidPage_model= Label(davidPage,text='AI-Model',anchor='center',background=higlight_blue,font=('fixedsys',20),fg='white')
davidPage_model.place(x=944,y=82,width=375,height=75)
davidPage_loremlabel = Label(davidPage,wraplength=300, justify="left", font=("Helvetica", 20 ), anchor=('n'),fg='white',bg=secondary_background,
text=(
'This approach utilizes the Gemini API to send a request to the large language model "Gemini-1.5-pro." Its goal is to derive a valid regular expression based on the provided input.'
)
)
davidPage_loremlabel.place(x=944,y=165,width=375,height=465)
#-----------jannes page ----------------
jannesPage_canvas = Canvas(jannesPage,bg = frame_background,height = 768,width = 1366,bd = 0,highlightthickness = 0,relief = "ridge")
jannesPage_canvas.place(x = 0, y = 0)
jannesPage_canvas.create_rectangle(15.0,16.0,890.0,752.0,fill=secondary_background,outline="")
jannesPage_textfield = Text(jannesPage, wrap=WORD, font=("Helvetica", 14,'italic'),fg='lightgrey')
jannesPage_textfield.place(x=26, y=40, height=470, width=850)
jannesPage_textfield.insert('1.0',preset_text)
jannesPage_textfield.bind("<Button-1>", lambda event: clear_text_on_focus(event, jannesPage_textfield))
jannesPage_generateButton= Button(jannesPage, text='Generate',bg=higlight_blue,fg='white',font=label_font,command=get_text_and_source)
jannesPage_generateButton.place(x=26,y=515,width=850,height=70)
jannesPage_output= Label(jannesPage,text=regex_output,anchor='center',background=secondary_background,font=20,fg='white')
jannesPage_output.place(x=25,y=625,width=750,height=75)
jannesPage_copy= Button(jannesPage,text='c',image = copy_image,borderwidth=0,command=lambda: copy_to_clipboard(jannesPage,jannesPage_output))
jannesPage_copy.place(x=800,y=635,width=50,height=50)
jannesPage_menuButton = Button(jannesPage,text='RegEx Generator',background=higlight_blue,fg='white',command=lambda: show_frame(mainPage))
jannesPage_menuButton.place(x=1055,y=660,width=150,height=30)
jannesPage_model= Label(jannesPage,text='Evolving-Model',anchor='center',background=higlight_blue,font=('fixedsys',20),fg='white')
jannesPage_model.place(x=944,y=82,width=375,height=75)
jannesPage_loremlabel = Label(jannesPage,wraplength=300, justify="left", font=("Helvetica", 20 ), anchor=('n'),fg='white',bg=secondary_background,
text=("This approach utilies an object oriented approach.It generates a regular expression for a single string and expands it to fit multiple strings."
)
)
jannesPage_loremlabel.place(x=944,y=165,width=375,height=465)
#-----------matti page ----------------
mattiPage_canvas = Canvas(mattiPage,bg = frame_background,height = 768,width = 1366,bd = 0,highlightthickness = 0,relief = "ridge")
mattiPage_canvas.place(x = 0, y = 0)
mattiPage_canvas.create_rectangle(15.0,16.0,890.0,752.0,fill=secondary_background,outline="")
mattiPage_textfield = Text(mattiPage, wrap=WORD, font=("Helvetica", 14,'italic'),fg='lightgrey')
mattiPage_textfield.place(x=26, y=40, height=470, width=850)
mattiPage_textfield.insert('1.0',preset_text)
mattiPage_textfield.bind("<Button-1>", lambda event: clear_text_on_focus(event, mattiPage_textfield))
mattiPage_generateButton= Button(mattiPage, text='Generate',bg=higlight_blue,fg='white',font=label_font,command=get_text_and_source)
mattiPage_generateButton.place(x=26,y=515,width=850,height=70)
mattiPage_output= Label(mattiPage,text=regex_output,anchor='center',background=secondary_background,font=20,fg='white')
mattiPage_output.place(x=25,y=625,width=750,height=75)
mattiPage_copy= Button(mattiPage,text='c',image = copy_image,borderwidth=0,command=lambda: copy_to_clipboard(jannesPage,jannesPage_output))
mattiPage_copy.place(x=800,y=635,width=50,height=50)
mattiPage_menuButton = Button(mattiPage,text='RegEx Generator',background=higlight_blue,fg='white',command=lambda: show_frame(mainPage))
mattiPage_menuButton.place(x=1055,y=660,width=150,height=30)
mattiPage_model= Label(mattiPage,text='Parallel-Model',anchor='center',background=higlight_blue,font=('fixedsys',20),fg='white')
mattiPage_model.place(x=944,y=82,width=375,height=75)
mattiPage_loremlabel = Label(mattiPage,wraplength=300, justify="left", font=("Helvetica", 20 ), anchor=('n'),fg='white',bg=secondary_background,
text=(
"The iterative algorithm starts by splitting the strings into characters. These characters are then iteratively encoded and their amount per group is quantified. After the patterns of the encoded strings have been successfully compared, they are put together to form the regular expression. "
)
)
mattiPage_loremlabel.place(x=944,y=165,width=375,height=465)
#-----------check page ----------------
checkPage_canvas = Canvas(checkPage,bg = frame_background,height = 768,width = 1366,bd = 0,highlightthickness = 0,relief = "ridge")
checkPage_canvas.place(x = 0, y = 0)
checkPage_canvas.create_rectangle(15.0,16.0,890.0,752.0,fill=secondary_background,outline="")
checkPage_textfield_one = Text(checkPage,font=25,wrap=WORD)
checkPage_textfield_one.place(x=26,y=40,height=275,width=850)
checkPage_textfield_two = Text(checkPage,font=25,wrap=WORD)
checkPage_textfield_two.place(x=26,y=320,height=275,width=850)
checkPage_checkButton= Button(checkPage, text='RegEx Check',bg='#555A5E',fg='white',font=label_font,command=get_text_from_checkpage)
checkPage_checkButton.place(x=219,width=455,height=80,y=645)
checkPage_menuButton = Button(checkPage,text='RegEx Generator',background=higlight_blue,fg='white',command=lambda: show_frame(mainPage))
checkPage_menuButton.place(x=1055,y=660,width=150,height=30)
checkPage_model= Label(checkPage,text='Function',anchor='center',background=higlight_blue,font=('fixedsys',20),fg='white')
checkPage_model.place(x=944,y=82,width=375,height=75)
checkPage_loremlabel = Label(checkPage,wraplength=300, justify="left", font=("Helvetica", 20 ), anchor=('n'),fg='white',bg=secondary_background,
text=("This function checks if the given RegEx and the given Inputs matches. ")
)
checkPage_loremlabel.place(x=944,y=165,width=375,height=465)
window.mainloop()