-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (43 loc) · 1.57 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
#!/usr/bin/env python
import Tkinter as Tk
from app import DetectApp
import detectors
import signal
import pynput
import json
keyboard = pynput.keyboard.Controller()
def left_key_press():
keyboard.press(pynput.keyboard.Key.left)
keyboard.release(pynput.keyboard.Key.left)
print('Heard "previous slide" - executing left key press')
def right_key_press():
keyboard.press(pynput.keyboard.Key.right)
keyboard.release(pynput.keyboard.Key.right)
print('Heard "next slide" - executing right key press')
def signal_handler(signal_received, frame):
print("Signal handler - SIGINT")
root.destroy()
signal.signal(signal.SIGINT, signal_handler)
# Initialize thread to run detectors
with open("config.json", "r") as json_data:
detection_data = json.load(json_data)
models = detection_data["models"]
sensitivity = detection_data["sensitivity"]
resource = detection_data["resource"]
callbacks = [right_key_press, left_key_press]
recognition = detectors.ThreadedDetector(models, sensitivity=sensitivity, resource=resource)
recognition.start()
# Set up GUI
root = Tk.Tk()
root.resizable(0, 0) # Prevents resizing of GUI
root.title("Hands-Free Presentation")
app = DetectApp(root, models, sensitivity, recognition, callbacks)
root.mainloop() # Blocks until GUI is terminated
# End recognition and its thread
print("Closing application...")
recognition.terminate()
# Save configurations to config.json
detection_data["models"] = app.models
detection_data["sensitivity"] = app.sensitivity
with open("config.json", "w") as json_file:
json.dump(detection_data, json_file)