This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
/
main.py
154 lines (131 loc) · 4.4 KB
/
main.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
import voice_recognition as vr
import adb
from callinfo import CallInfo
from memory import CommandQueue
from time import sleep
import itertools, glob
import time
from system_tray_lib import *
import Tkinter
import sys
from Tkinter import *
from PIL import Image, ImageTk
import urllib
import requests
import threading
import tkFont
import tkMessageBox
import subprocess
import speech_recognition as sr
listening = False
microphone_check = False
def startSystemTray():
global device
icons = itertools.cycle(glob.glob('images/*.ico'))
hover_text = "Smartphone Voice"
menu_options = (('Show',None,Remake),
('Start/Stop', None, microphoneAction),)
SysTrayIcon(icons.next(), hover_text, menu_options, on_quit=Terminate, default_menu_index=1)
def onClosing():
global top
top.destroy()
def Terminate():
sys.exit()
def Remake():
main()
def microphoneAction():
global microphone_check
global microphone
global device
global listening
microphone_check = not microphone_check
if microphone_check:
image = ImageTk.PhotoImage(Image.open('images/button_activated.gif'))
microphone.config(image=image, background = "white", bd = 0)
microphone.image = image
listening = True
threading.Thread(target=listen_and_do).start()
else:
image = ImageTk.PhotoImage(Image.open('images/1.png'))
microphone.config(image=image, background = "white", bd = 0)
microphone.image = image
listening = False
def listen_and_do():
mem = CommandQueue()
global listening
while listening:
print listening
usr_input = vr.get_mic_input()
print usr_input
real_commands = vr.extract_possible_commands(usr_input)
mem = adb.run(real_commands, mem, usr_input)
sleep(1)
def gui():
global top
top = Tkinter.Tk()
global microphone_check
global microphone
global device
flag = 0
top.overrideredirect(1)
top.title("Smartphone Voice")
top.wm_iconbitmap('images/voice15.ico')
top.configure(background='white')
image = Image.open('phone.jpg')
image_size = image.size
width = image_size[0]
height = image_size[1]
set_width = width - 125
top.resizable(width=FALSE, height=FALSE)
ws = top.winfo_screenwidth() # width of the screen
hs = top.winfo_screenheight() # height of the screen
x = (ws/1.07) - (width/2)
y = (hs/1.50) - (height/2)
top.geometry('%dx%d+%d+%d' % (width+10, height+120, x, y))
''' SHOW EXIT ICON '''
exit_image = ImageTk.PhotoImage(file="images/exit.png")
exit_button = Tkinter.Button(top, image =exit_image, command = onClosing, background = "white", bd = 0)
exit_button.pack(anchor = "se")
''' SHOW SMARTPHONE '''
image = Image.open('phone.jpg')
image_size = image.size
photoImage = ImageTk.PhotoImage(image)
label = Label(image=photoImage, background = 'white')
label.image = photoImage
label.pack(fill="x")
''' SHOW TEXT '''
connect_to_string = "Connected to " + device + ":"
connect_to = Label(text=connect_to_string, background = 'white', font=tkFont.Font(family="Helvetica", size=10))
if len(device) <= 9:
connect_to = Label(text=connect_to_string, background = 'white', font=tkFont.Font(family="Helvetica", size=10))
else:
connect_to_string = "Connected to " + "\n" + device + ":"
connect_to = Label(text=connect_to_string, background = 'white', font=tkFont.Font(family="Helvetica", size=9))
connect_to.text = connect_to_string
connect_to.pack(fill="x")
''' SHOW/UPDATE BUTTON '''
microphone_image = ImageTk.PhotoImage(file="images/1.png")
microphone = Tkinter.Button(top, image =microphone_image, command = microphoneAction, background = "white", bd = 0)
microphone.pack(fill="x")
top.protocol("WM_DELETE_WINDOW", onClosing)
top.mainloop()
def main():
global device
device = adb.get_device_model()
url = "http://www.gsmarena.com/results.php3?sQuickSearch=yes&sName=" + device
scraped_page = requests.get(url).text
model_name = scraped_page.split("specs-phone-name-title")[1].split("h1")[0].split(">")[1].split("<")[0]
device = model_name
scraped_page = scraped_page.split("http://cdn2.gsmarena.com/vv/bigpic/")[1].split("alt=")[0].split(";")[0]
scraped_gsm_image = scraped_page[:-1]
global microphone_check
microphone_check = 0
urllib.urlretrieve("http://cdn2.gsmarena.com/vv/bigpic/%s" % scraped_gsm_image, "phone.jpg")
system_tray_thread = threading.Thread(target=startSystemTray)
system_tray_thread.daemon = True
system_tray_thread.start()
gui()
if __name__ == '__main__':
subprocess.Popen(["python", 'calls_background.py'])
subprocess.Popen(["python", 'sms_background.py'])
main()