-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixer.py
288 lines (272 loc) · 11.3 KB
/
mixer.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
import speech_recognition as sr
from tkinter import*
from tkinter.messagebox import*
import pyttsx3
import math
engine = pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
def speak(audi):
engine.say(audi)
engine.runAndWait()
def command():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Speak anything:')
r.dynamic_energy_threshold = 100
r.pause_threshold = 2
audio = r.listen(source)
try:
print('recognising....')
text = r.recognize_google(audio)
print('you said : {}'.format(text))
except:
print('sorry i cant listen')
return ""
return text
# active function to make operaion
def clck(event):
print('button clicked......',event)
if event == '<==':
fetc = textfield.get()
fet = fetc[:-1]
print(fet)
#textfield.delete(0, END)
textfield.insert(0, fet)
return
if event == 'AC':
textfield.delete(0, END)
return
if event == 'x':
textfield.insert(END, '*')
return
if event == '=':
try:
fetch = textfield.get()
textfield.insert(END,'=')
if '^' in fetch:
k = fetch.replace('^', '**')
ans=eval(k)
textfield.insert(END, ans)
speak(k)
return
ans = eval(fetch)
print(ans)
#textfield.delete(0, END)
textfield.insert(END, ans)
except Exception as e:
print('Error is', e)
showerror('Error is:', e)
return
textfield.insert(END, event)
def rut():
k=textfield.get()
k=eval(k)
k=math.sqrt(k)
#textfield.delete(0, END)
textfield.insert(END,'=')
textfield.insert(END, k)
speak(k)
def crut():
k=textfield.get()
k=eval(k)
k=k**(1/3)
#textfield.delete(0, END)
textfield.insert(END, '=')
textfield.insert(END,k)
speak(k)
def lo():
k = textfield.get()
k = eval(k)
k = math.log(k,2)
#textfield.delete(0, END)
textfield.insert(END, '=')
textfield.insert(END, k)
speak(k)
def exp():
k = textfield.get()
k = eval(k)
k = math.exp(k)
#textfield.delete(0, END)
textfield.insert(END, '=')
textfield.insert(END, k)
speak(k)
# fetching tokens from the text command
def extract_from_text(text):
l = []
for t in text.split(' '):
l = []
for t in text.split(' '):
try:
l.append(float(t))
except ValueError:
pass
return l
# Operations - performed on the basis of text tokens
operations = {'ADD': '+', 'PLUS': '+', 'SUM': '+', 'ADDITION': '+', 'JOD': '+','+':'+','CUBE ROOT':'3√',
'ROOT':'√','SUB': '-', 'SUBTRACT': '-', 'MINUS': '-','-':'-','MOD':'%','MODULAS':'%',
'DIFFERENCE': '-', 'GHATAO': '-','POWER':'^','^':'^','LOG':'log',
'E':'e','CUBE':'3√',
'PRODUCT': '*', 'GUNA': '*', 'MULTIPLY': '*','X':'*', 'MULTIPLICATION': '*','into':'*',
'DIVISION': '/', 'BHAG': '/','DIVIDE':'/'}
if __name__ == "__main__":
print('I am your personal calculator')
speak('I am your personal calculator')
print('would you like my graphical interface or you use audio version')
speak('would you like my graphical interface or you use audio version')
t = command().lower()
if 'audio' in t:
while(True):
k = command().lower()
print(k)
symbol = []
if 'shutdown' in k:
print('have a nice day boss')
break
text = k
for word in text.split(' '):
if word.upper() in operations.keys():
try:
print(word)
l = extract_from_text(text)
symbol.append(operations[word.upper()])
print(symbol)
print(l)
except:
print('something went wrong going plz enter again !!')
window = Tk()
window.title('my calculator')
window.maxsize(width=690, height=550) # widthxheight
window.minsize(width=690, height=550)
# picture label
fon = ('Algerian', 10, 'bold underline')
pic = PhotoImage(file='img/cal2.png')
headlabel = Label(window, image=pic) # text = 'my label'
headlabel.pack(side=TOP, pady=6)
headlabel = Label(window, text='MY CALCULATOR', font=fon)
headlabel.pack(side=TOP)
fan = ('Algerian', 28, 'bold ')
# for text field
textfield = Entry(window, font=fan, justify=RIGHT)
textfield.pack(side=TOP, pady=6, fill=X, padx=10)
# for making frame of buttons
buttonFrame = Frame(window)
buttonFrame.pack(side=TOP)
k = 1
for i in range(3):
for j in range(3):
btn = Button(buttonFrame, text=k, font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btn.grid(row=i, column=j, pady=3, padx=3)
btn.bind('<Button-1>', clck)
k += 1
btn1 = Button(buttonFrame, text='.', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btn1.grid(row=3, column=0, pady=3, padx=3)
btn2 = Button(buttonFrame, text=0, font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btn2.grid(row=3, column=1, pady=3, padx=3)
btn3 = Button(buttonFrame, text='=', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btn3.grid(row=3, column=2, pady=3, padx=3)
btnplus = Button(buttonFrame, text='+', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btnplus.grid(row=0, column=3, pady=3, padx=3)
btnminus = Button(buttonFrame, text='-', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btnminus.grid(row=1, column=3, pady=3, padx=3)
btnmul = Button(buttonFrame, text='x', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btnmul.grid(row=2, column=3, pady=3, padx=3)
btndiv = Button(buttonFrame, text='/', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
btndiv.grid(row=3, column=3, pady=3, padx=3)
dele = Button(buttonFrame, text='<==', font=fan, width=9, relief='raised', activebackground='black',
activeforeground='red')
dele.grid(row=4, column=0, pady=3, padx=3, columnspan=2)
allclear = Button(buttonFrame, text='AC', font=fan, width=9, relief='raised', activebackground='black',
activeforeground='red')
allclear.grid(row=4, column=2, pady=3, padx=3, columnspan=2)
mod = Button(buttonFrame, text='%', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
mod.grid(row=0, column=4, pady=3, padx=3)
root = Button(buttonFrame, text=' √', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
root.grid(row=1, column=4, pady=3, padx=3)
croot = Button(buttonFrame, text='3√', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
croot.grid(row=2, column=4, pady=3, padx=3)
power = Button(buttonFrame, text='^', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
power.grid(row=3, column=4, pady=3, padx=3)
power.bind('<Button-1>', clck)
log = Button(buttonFrame, text='log', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
log.grid(row=4, column=4, pady=3, padx=3)
expo = Button(buttonFrame, text='e', font=('Baveuse', 21, 'bold'), width=4, relief='raised',
activebackground='black', activeforeground='red')
expo.grid(row=0, column=5, pady=3, padx=3)
rob = Button(buttonFrame, text='(', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
rob.grid(row=1, column=5, pady=3, padx=3)
lob = Button(buttonFrame, text=')', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
lob.grid(row=2, column=5, pady=3, padx=3)
ze = Button(buttonFrame, text='00', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
ze.grid(row=3, column=5, pady=3, padx=3)
zee = Button(buttonFrame, text='000', font=fan, width=4, relief='raised', activebackground='black',
activeforeground='red')
zee.grid(row=4, column=5, pady=3, padx=3)
mod.bind('<Button-1>', clck)
power.bind('<Button-1>', clck)
rob.bind('<Button-1>', clck)
lob.bind('<Button-1>', clck)
ze.bind('<Button-1>', clck)
zee.bind('<Button-1>', clck)
btn1.bind('<Button-1>', clck)
btn2.bind('<Button-1>', clck)
btn3.bind('<Button-1>', clck)
btnplus.bind('<Button-1>', clck)
btnminus.bind('<Button-1>', clck)
btnmul.bind('<Button-1>', clck)
btndiv.bind('<Button-1>', clck)
dele.bind('<Button-1>', clck)
allclear.bind('<Button-1>', clck)
try:
x=len(l)
print(x)
y=len(symbol)
if y>1 or x>1:
t=0
j=0
for i in range(x+y):
if i==0 or i%2==0:
clck(l[t])
t+=1
else:
clck(symbol[j])
j+=1
clck('=')
else:
for i in range(x):
clck(l[i])
if symbol[i] == '√':
rut()
break
if symbol[i] == '3√':
crut()
break
if symbol[i] == 'log':
lo()
break
if symbol[i] == 'e':
exp()
break
if i>=x-1:break
except Exception:
print()
window.mainloop() # this function used to show window again and again\
else:
speak('okk sir')
import cal1