-
Notifications
You must be signed in to change notification settings - Fork 1
/
LogicExpander1.7.py
362 lines (323 loc) · 10.2 KB
/
LogicExpander1.7.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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
"""
GUI for Logical expander
Created on Apr 29, 2021
Version 1.7
latest update: May 5, 2021
author: David Wiser
"""
from tkinter import *
from tkinter import ttk
import tkinter.font as tkFont
from LogicConverter import *
from re import sub
''' initiallize'''
root = Tk()
root.title("First Order Logic Expander")
fontTitle = tkFont.Font(family="Lucida Grande", size=36)
fontLabels = tkFont.Font(family="Lucida Grande", size=16)
Welcome = Label(root, text='Welcome to the logic expander', font=fontTitle)
''' Variables'''
global expression
global UD
global expDisplay
out = ""
expression = ""
UD = ""
expDisplay = ""
'''textbox'''
global labelExp2
global labelUD2
textbox = Frame(root, height=200, width=200)
labelUD = ttk.Label(textbox, text="UD: ", font=fontLabels).grid(column=0,row=0)
labelUD2 = ttk.Label(textbox, text=UD, font=fontLabels).grid(column=0,row=1)
labelExp = ttk.Label(textbox, text='Expression:', font=fontLabels).grid(column=0,row=2)
labelExp2 = ttk.Label(textbox, text=expression, font=fontLabels).grid(column=0,row=3)
''' output display'''
output = Frame(root)
labelOUT = ttk.Label(output, text="output: ", font=fontLabels).grid(column=0,row=0)
'''functions'''
#convertion function
def conv_str2Log(string):
outputstr = string
outputstr = sub('&',u'\u2227',outputstr)
#outputstr = sub('|',u'\u2228',outputstr)
#outputstr = sub('$',u'\u2192',outputstr)
outputstr = sub('%',u'\u2294',outputstr)
outputstr = sub('~',u'\u00AC',outputstr)
outputstr = sub('@',u'\u2200',outputstr)
#outputstr = sub('\\',u'\u2203',outputstr)
return outputstr
#functions for the different button commands
def and_bt():
"""adds an and (&) to the expression"""
temp = '&'
global expression
global expDisplay
expDisplay += u'\u2227'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def or_bt():
"""adds an or (|) to the expression"""
temp = '|'
global expression
global expDisplay
expDisplay += u'\u2228'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def exists_bt():
"""adds an exisits (\\) to the expression"""
temp = '\\'
global expression
global expDisplay
expDisplay += u'\u2203'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def forall_bt():
"""adds a forall (@) to the expression"""
temp = '@'
global expression
global expDisplay
expDisplay += u'\u2200'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def leftpar_bt():
"""adds a ( to the expression"""
temp = '('
global expression
global expDisplay
expDisplay += temp
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def rightpar_bt():
"""adds a ) to the expression"""
temp = ')'
global expression
global expDisplay
expDisplay += temp
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def if_bt():
"""adds an if ($) to the expression"""
temp = '$'
global expression
global expDisplay
expDisplay += u'\u2192'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def iff_bt():
"""adds an iff (%) to the expression"""
temp = '%'
global expression
global expDisplay
expDisplay += u'\u2194'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def neg_bt():
"""adds a negaion (~) to the expression"""
temp = '~'
global expression
global expDisplay
expDisplay += u'\u00AC'
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def x_bt():
"""adds a x to the expression"""
temp = 'x'
global expression
global expDisplay
expDisplay += temp
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def y_bt():
"""adds a y to the expression"""
temp = 'y'
global expression
global expDisplay
expDisplay += temp
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def z_bt():
"""adds a z to the expression"""
temp = 'z'
global expression
global expDisplay
expDisplay += temp
expression += temp
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
#backspace buttons
def bsUD_bt():
global UD
if (len(UD) >= 1):
UD = UD[0:-1]
labelUD2 = ttk.Label(textbox, text=UD, font=fontLabels).grid(column=0,row=1)
return None
def bsExp_bt():
global expression
global expDisplay
if (len(expression) >= 1):
expression = expression[0:-1]
expDisplay = expDisplay[0:-1]
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
#other important button commands
def run():
"""
Performs the conversion drom a FOL expression into the expansion method format.
Utilizes the Logic Converter file for the input checker and converter functions
Returns None.
"""
global out
global expression
if inputChecker(expression):
out = converter(expression, UD)
out2= conv_str2Log(out)
labelOUT2 = ttk.Label(output, text=out2, font=fontLabels).grid(column=0,row=1)
else :
labelOUT2 = ttk.Label(output, text='invalid input', font=fontLabels).grid(column=0,row=1)
return None
def reset():
global expression
global UD
global expDisplay
global labelExp2
global labelUD2
# expression = ""
# expDisplay = ""
# UD = ""
temp = " "
temp2 =" "
for i in range(len(expression)):
bsExp_bt()
temp += " "
for j in range(len(UD)):
bsUD_bt()
temp2 += " "
labelExp2 = ttk.Label(textbox, text=temp*2, font=fontLabels).grid(column=0,row=3)
labelUD2 = ttk.Label(textbox, text=temp2*2, font=fontLabels).grid(column=0,row=1)
labelOUT2 = ttk.Label(output, text=temp*10, font=fontLabels).grid(column=0,row=1)
return None
#shortcut functions
def pressand(event):
and_bt()
return None
def pressor(event):
or_bt()
return None
def pressexists(event):
exists_bt()
return None
def pressforall(event):
forall_bt()
return None
return None
def pressif(event):
if_bt()
return None
def pressiff(event):
iff_bt()
return None
def pressneg(event):
neg_bt()
return None
#entry boxes
def enterS(event):
global expression
global expDisplay
txt = inputS.get()
expression += txt
txt2 = conv_str2Log(txt)
expDisplay += txt2
inputS.delete(0,'end')
labelExp2 = ttk.Label(textbox, text=expDisplay, font=fontLabels).grid(column=0,row=3)
return None
def enterUD(event):
global UD
txt = inputUD.get()
UD += txt
inputUD.delete(0,'end')
labelUD2 = ttk.Label(textbox, text=UD, font=fontLabels).grid(column=0,row=1)
return None
'''Keyboard'''
#create the buttons
keys = Frame(root, height=200, width=200)
ab = ttk.Button(keys, text=u'\u2227', command=and_bt)
ob = ttk.Button(keys, text=u'\u2228', command=or_bt)
Eb = ttk.Button(keys, text=u'\u2203', command=exists_bt)
Ab = ttk.Button(keys, text=u'\u2200', command=forall_bt)
lpb = ttk.Button(keys, text='(', command=leftpar_bt)
rpb = ttk.Button(keys, text=')', command=rightpar_bt)
ib = ttk.Button(keys, text=u'\u2192', command=if_bt)
bb = ttk.Button(keys, text=u'\u2194', command=iff_bt)
nb = ttk.Button(keys, text=u'\u00AC', command=neg_bt)
xb = ttk.Button(keys, text='x', command=x_bt)
yb = ttk.Button(keys, text='y', command=y_bt)
zb = ttk.Button(keys, text='z', command=z_bt)
#format layout
ab.grid(column=0,row=0)
ob.grid(column=1,row=0)
Eb.grid(column=0,row=1)
Ab.grid(column=1,row=1)
lpb.grid(column=0,row=2)
rpb.grid(column=1,row=2)
ib.grid(column=2,row=1)
bb.grid(column=2,row=2)
nb.grid(column=2,row=0)
xb.grid(column=0,row=3)
yb.grid(column=1,row=3)
zb.grid(column=2,row=3)
#shortcuts
root.bind("&", pressand)
root.bind("|", pressor)
root.bind("\\", pressexists)
root.bind("@", pressforall)
root.bind("$", pressif)
root.bind("%", pressiff)
root.bind("~", pressneg)
'''Other aspects of interface'''
other = Frame(root)
#run btn
ttk.Button(other, text='run', command=run).grid(column=0,row=5)
#entry for expression
inputS = ttk.Entry(other)
inputS.grid(column=1, row=1, columnspan=2)
inputS.bind("<Return>", enterS)
#entry for UD
inputUD = ttk.Entry(other)
inputUD.grid(column=1, row=3, columnspan=2)
inputUD.bind("<Return>", enterUD)
#Reset button
ttk.Button(other, text='reset', command=reset).grid(column=1,row=5)
#backspace buttons
ttk.Button(other, text='backspace UD', command=bsUD_bt).grid(column=0,row=6)
ttk.Button(other, text='backspace expression', command=bsExp_bt).grid(column=1,row=6)
#formatting
Label(other, text="").grid(column=0,row=0, columnspan=2)
Label(other, text="").grid(column=0,row=2, columnspan=2)
Label(other, text="").grid(column=0,row=4, columnspan=2)
LExp = Label(other, text="EXP:").grid(column=0, row=1)
LUD = Label(other, text="UD:").grid(column=0, row=3)
'''final grid'''
#set window
#mainframe = ttk.Frame(root, padding="3 3 12 12")
#mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
#root.columnconfigure(0, weight=1)
#root.rowconfigure(0, weight=1)
root.geometry("1000x600")
Welcome.grid(column=0, row=0, columnspan=2)
keys.grid(column=0, row=1)
textbox.grid(column=1, row=1)
other.grid(column=0, row=2, columnspan=2)
output.grid(column=0, row=3, columnspan=2)
root.mainloop()