Skip to content

Commit 6c5c39f

Browse files
Update Elements.py
1 parent 173b6c2 commit 6c5c39f

File tree

1 file changed

+79
-45
lines changed

1 file changed

+79
-45
lines changed

Elements.py

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import urllib ## for checking connection status
3434
import keyboard ## for simulating keyboard actions
3535
import math ## for mathematical operations with shapes
36+
from pocketsphinx import LiveSpeech ## pocketsphinx lib for offline voice detection
3637

3738
############################################################### Class ####################################################################
3839
#Hover button Class
@@ -64,28 +65,38 @@ def on_leave(self, e):
6465
canvas.pack()
6566

6667
#check connection Status
68+
first_time = True
6769
def connection():
70+
global first_time
71+
global internet_access
6872
canvasstatus = Canvas(canvas, bg ="#0d0d0d", bd="0", borderwidth = "0", highlightthickness = "0" )
6973
canvasstatus.place(x="900", y="734", relwidth="0.3", relheight="0.45")
7074
#check status
7175
host='http://google.com'
7276
try:
7377
urllib.request.urlopen(host)
7478
print("connected")
75-
connectionLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="Connection Established")
76-
connectionLabel.pack()
77-
closingLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="voice enabled")
78-
closingLabel.pack()
79-
canvasstatus.after(10000, canvasstatus.destroy)
79+
if first_time == True:
80+
connectionLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="Connection Established")
81+
connectionLabel.pack()
82+
closingLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="voice enabled")
83+
closingLabel.pack()
84+
canvasstatus.after(10000, canvasstatus.destroy)
85+
first_time = False
86+
internet_access = True
87+
8088
except:
8189
print("not_connected")
82-
connectionLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="NoConnection Err: 404")
83-
connectionLabel.pack()
84-
closingLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="quit to close/ continue without voice")
85-
closingLabel.pack()
86-
quitButton=Button(canvasstatus,bg="#0d0d0d",fg="white",text="Quit",command=lambda: mainwin.destroy())
87-
quitButton.pack()
88-
canvasstatus.after(10000, canvasstatus.destroy)
90+
if first_time == True:
91+
connectionLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="NoConnection Err: 404")
92+
connectionLabel.pack()
93+
closingLabel=Label(canvasstatus,bg="#0d0d0d",fg="white",text="quit to close/ continue without voice")
94+
closingLabel.pack()
95+
quitButton=Button(canvasstatus,bg="#0d0d0d",fg="white",text="Quit",command=lambda: mainwin.destroy())
96+
quitButton.pack()
97+
canvasstatus.after(10000, canvasstatus.destroy)
98+
first_time = False
99+
internet_access = False
89100

90101
#logo Button FunctionS
91102
def logobtn_clicked():
@@ -137,6 +148,7 @@ def import_options():
137148
import_win.geometry("900x500+400+200")
138149
import_win.maxsize(900,500)
139150
import_win.config(bg="#1c1c1c")
151+
import_win.grab_set() ## prevent duplication of same window and block main window
140152

141153
## Import Image / fresh start in new banner
142154
imp_label=Label(import_win,fg="white",bg="#1c1c1c",text="IMPORT/CREATE BOARD",font=("Courier", 35))
@@ -542,6 +554,7 @@ def crop_clicked():
542554
lower = height - upper
543555
print (lower)
544556
#print("New size of image is", width, height)
557+
print("on progress")
545558

546559
area = (left, upper, right, lower)
547560
image = current_img.crop(area)
@@ -774,7 +787,7 @@ def filter_clicked():
774787

775788
#add Text button
776789
def addtext_clicked():
777-
print("error")
790+
print("on progress")
778791

779792
#add text function
780793
img_addtext = Image.open(r"elements2.0Images\assets\addtext.png")
@@ -800,7 +813,7 @@ def contrast_clicked():
800813
#return current_img
801814

802815
#contrast button
803-
img_contrast = Image.open(r"elements2.0Images\assets\contrast.png")
816+
img_contrast = Image.open(r"elements2.0Images\contrast.png")
804817
img_contrast = img_contrast.resize((35,35), Image.ANTIALIAS)
805818
img_contrast1 = ImageTk.PhotoImage(img_contrast)
806819
button_contrast = HoverButton(canvastoolbar, bg = "#0d0d0d", bd="0", image=img_contrast1, text = "Contrast", compound= "left",fg ="gray",command=lambda: contrast_clicked())
@@ -839,23 +852,23 @@ def flip_clicked():
839852
canvasflip.place(x="950", y="380", relwidth="0.123", relheight="0.1")
840853
canvasflip.after(2000, canvasflip.destroy)
841854
#flip rigth - left button
842-
flipright = Image.open(r"elements2.0Images\assets\undo.png")
855+
flipright = Image.open(r"elements2.0Images\undo.png")
843856
flipright = flipright.resize((40,40), Image.ANTIALIAS)
844857
flipright1 = ImageTk.PhotoImage(flipright)
845858
flipright1.image=flipright1
846859
button_flipright = HoverButton(canvasflip, bg = "#0d0d0d", bd="0", image=flipright1, text = "Flip Right", compound= "left",fg ="gray", command=lambda: flip_right_clicked())
847860
button_flipright.place(x="30", y="0")
848861

849862
#flip top- botton
850-
fliptop = Image.open(r"elements2.0Images\assets\redo.png")
863+
fliptop = Image.open(r"elements2.0Images\redo.png")
851864
fliptop = fliptop.resize((40,40), Image.ANTIALIAS)
852865
fliptop1 = ImageTk.PhotoImage(fliptop)
853866
fliptop1.image=fliptop1
854867
button_fliptop = HoverButton(canvasflip, bg = "#0d0d0d", bd="0", image=fliptop1, text = "Flip top ", compound= "left",fg ="gray", command=lambda: flip_top_clicked())
855868
button_fliptop.place(x="30", y="40")
856869

857870
#flip button
858-
img_flip = Image.open(r"elements2.0Images\assets\flip.png")
871+
img_flip = Image.open(r"elements2.0Images\flip.png")
859872
img_flip = img_flip.resize((35,35), Image.ANTIALIAS)
860873
img_flip1 = ImageTk.PhotoImage(img_flip)
861874
button_flip = HoverButton(canvastoolbar, bg = "#0d0d0d", bd="0", image=img_flip1, text = "Flip", compound= "left",fg ="gray",command=lambda: flip_clicked())
@@ -878,7 +891,7 @@ def saturation_clicked():
878891
#return current_img
879892

880893
#Saturation button
881-
img_saturation = Image.open(r"elements2.0Images\assets\saturation.png")
894+
img_saturation = Image.open(r"elements2.0Images\saturation.png")
882895
img_saturation = img_saturation.resize((37,37), Image.ANTIALIAS)
883896
img_saturation1 = ImageTk.PhotoImage(img_saturation)
884897
button_saturation = HoverButton(canvastoolbar, bg = "#0d0d0d", bd="0", image=img_saturation1, text = "Saturation", compound= "left",fg ="gray",command=lambda: saturation_clicked() )
@@ -912,7 +925,7 @@ def undo_clicked():
912925
pass
913926

914927
#undo button
915-
img_undo = Image.open(r"elements2.0Images\assets\undo.png")
928+
img_undo = Image.open(r"elements2.0Images\undo.png")
916929
img_undo = img_undo.resize((40,40), Image.ANTIALIAS)
917930
img_undo1 = ImageTk.PhotoImage(img_undo)
918931
button_undo = HoverButton(canvastoolbar, bg = "#0d0d0d", bd="0", image=img_undo1, text = "Undo", compound= "left",fg ="gray",command= undo_clicked)
@@ -938,7 +951,7 @@ def redo_clicked():
938951
pass
939952

940953
#redo button
941-
img_redo = Image.open(r"elements2.0Images\assets\redo.png")
954+
img_redo = Image.open(r"elements2.0Images\redo.png")
942955
img_redo = img_redo.resize((40,40), Image.ANTIALIAS)
943956
img_redo1 = ImageTk.PhotoImage(img_redo)
944957
button_redo = HoverButton(canvastoolbar, bg = "#0d0d0d", bd="0", image=img_redo1, text = "Redo", compound= "left",fg ="gray", command=redo_clicked)
@@ -948,18 +961,28 @@ def redo_clicked():
948961

949962
#listen function captures voice
950963
def listenit():
951-
r = speech_recognition.Recognizer()
952-
#label_mic_active1 = Label(canvas,text="Listening...", bg="#3b271b" , fg= "white", bd=".5")
953-
#label_mic_active1.place(x="700", y="705", relwidth=".3", relheight="0.065")
954-
with speech_recognition.Microphone() as source:
955-
#label_mic_active = Label(canvas,text="Listening...", bg="#3b271b" , fg= "white", bd=".5",)
956-
#label_mic_active.place(x="125", y="705", relwidth=".3", relheight="0.065")
957-
print("Listening : ") #debug
958-
#r.adjust_for_ambient_noise(source)
959-
audio = r.listen(source, timeout= 3)
960-
value = r.recognize_google(audio)
961-
#label_mic_active1 = Label(canvas,text=value, bg="#0d0d0d" , fg= "white", bd=".5")
962-
#label_mic_active1.place(x="700", y="705", relwidth=".3", relheight="0.065")
964+
connection()
965+
if internet_access == True:
966+
r = speech_recognition.Recognizer()
967+
#label_mic_active1 = Label(canvas,text="Listening...", bg="#3b271b" , fg= "white", bd=".5")
968+
#label_mic_active1.place(x="700", y="705", relwidth=".3", relheight="0.065")
969+
with speech_recognition.Microphone() as source:
970+
#label_mic_active = Label(canvas,text="Listening...", bg="#3b271b" , fg= "white", bd=".5",)
971+
#label_mic_active.place(x="125", y="705", relwidth=".3", relheight="0.065")
972+
print("using google recogniser")
973+
print("Listening : ") #debug
974+
#r.adjust_for_ambient_noise(source)
975+
audio = r.listen(source, timeout= 3)
976+
value = r.recognize_google(audio)
977+
#label_mic_active1 = Label(canvas,text=value, bg="#0d0d0d" , fg= "white", bd=".5")
978+
#label_mic_active1.place(x="700", y="705", relwidth=".3", relheight="0.065")
979+
elif internet_access == False:
980+
print("using pocketsphinx")
981+
print("Listening : ")
982+
for phrase in LiveSpeech():
983+
print (phrase)
984+
value = (str(phrase))
985+
break
963986
return value
964987

965988
# keywords
@@ -1165,6 +1188,7 @@ def save():
11651188
save_win.geometry("800x400+400+200")
11661189
save_win.maxsize(800,400)
11671190
save_win.config(bg="#1c1c1c")
1191+
save_win.grab_set() ## prevent aditional save window opening
11681192

11691193
##preview_text
11701194
prv_label=Label(save_win,fg="white",bg="#1c1c1c",text="PREVIEW",font=("Courier", 35))
@@ -1381,8 +1405,19 @@ def on_closing():
13811405
if messagebox.askokcancel("Quit", "Do you want to Stop Editing?"):
13821406
mainwin.destroy()
13831407

1408+
#listen for do!
1409+
def do():
1410+
for phrase in LiveSpeech():
1411+
print(phrase)
1412+
print ("on progress")
1413+
1414+
# share on social Media
1415+
def share():
1416+
print("on progress")
1417+
13841418
#clossing protocol
13851419
mainwin.protocol("WM_DELETE_WINDOW", on_closing)
1420+
13861421
#main loop
13871422
mainwin.mainloop()
13881423

@@ -1391,23 +1426,23 @@ def on_closing():
13911426

13921427
"""
13931428
### Error ###
1394-
none
1429+
board size not right
1430+
improve offline editing improve accuracy
13951431
13961432
### to add ###
1397-
independent value getting over voice
1433+
threaded voice recognition
1434+
independent value/parameter fetching over voice
13981435
crop
13991436
add text
1400-
Voiced File browser #### goes next
1401-
Share to fb, Insta, Gmail, Twitter
1437+
Voiced File browser
1438+
Social share
14021439
Auto gama correction
1403-
import options
1404-
merge images
1405-
histogram
1440+
merge images/ add images
1441+
histogram
1442+
do recognition
14061443
"""
14071444

1408-
######################################################## Here By Elements Version 2.0 is Finished ############## 14_April_2020 #############################
1409-
1410-
######################################################## Next Version Elements Version 2.1 aapproved for development #######################################
1445+
########################################################### 29_April_2020 ###################################################
14111446

14121447
##############################################################cerdits #######################################################
14131448
##########################################################Congratulations####################################################
@@ -1421,9 +1456,8 @@ def on_closing():
14211456
#############################################################################################################################
14221457
#############################################################################################################################
14231458

1424-
########### Notice ############
1459+
#######################
14251460
############################################################################################################################################################
1426-
#################### !!!!!! any duplication or tampering of product without the notice of the team is strictly Prohibitted !!!!!!! ########################
14271461
############################################################################################################################################################
14281462

1429-
################################################################ © Elements® Private Limited 2020 ##########################################################
1463+
################################################################ © Elements® Private Limited 2020 ##########################################################

0 commit comments

Comments
 (0)