-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
193 lines (146 loc) · 5.24 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
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
# -*- coding: utf-8 -*-
# ===============MAIN FILE===============
# == initializations
# ==== view
# ==== leap_controller
# ==== configuration
# ==== win32
# == threads
# basic modules imports
import sys
import threading
import time
import os
# aux modules imports
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QApplication, QSplashScreen, QProgressBar
# from win32api import GetSystemMetrics
# own package imports
from models.ConfigurationFromFile import ConfFromFile
from models.PCRecognizer import PCRecognizer
from models.PointCloud import PointCloud
from views.gui_qtdesigner import *
import views.gui as gui
from controllers.leap_controller import *
from controllers.utils import *
from controllers.configuration_controller import Controller
def init_thread():
""" inits gesture recognition thread"""
thread = threading.Thread(target=thread_handler)
thread.setDaemon(True)
thread.start()
def thread_handler():
""" this function handles the thread which allows to make "G" + "G" by putting two hands
on frame (python .py -thread)
Enables stroke gesture recognition (two hands on frame)
"""
print("thread_handler_init")
while True:
try:
if listener.can_record and not listener.capture_frame:
listener.recording = True
time.sleep(.4)
print("recording")
while listener.hand_vel < 250:
pass
listener.capture_frame = True
elif not listener.can_record and \
listener.capture_frame:
print("recording and recognizing captured")
listener.capture_frame = False # end of Leap capture
points = listener.gesture[1] # this allows "F" to work with mouse and hand stroke
if len(points) > 20:
try:
pc = Point_cloud("f1", listener.gesture[1]) # pc containing our new gesture
pc.draw_on_canvas() # drawing pc on canvas to see the shape
except:
print("some point_cloud error...")
try:
result = recognize_stroke(points)
gesture_match(result.name, conf)
except:
print("u have to redo the gesture")
listener.clear_variables()
listener.recording = False
except:
pass
def console_args(args):
""" handles console arguments input
:param args: array of arguments
"""
# shell arguments
for arg in args:
if arg == "-thread": # no keys gesture recognition enabled
thread = threading.Thread(target=thread_handler)
thread.setDaemon(True)
thread.start()
def show_splash_screen():
""" displays splash screen before loading main window"""
splash_pix = QPixmap("res/logo.png")
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
splash.setMask(splash_pix.mask())
progress_bar = QProgressBar(splash)
progress_bar.setMaximum(20)
progress_bar.setGeometry(130,
splash_pix.height() - 50,
splash_pix.width() - 240,
20)
progress_bar.setStyleSheet("""
QProgressBar {
border: 1px solid #252323;
border-radius: 6px;
text-align: center;
position: center;
background-color: #252323;
font-size: 1px;
}
QProgressBar::chunk {
background-color: #04B97F;
border-radius: 9px;
margin-right: 23px;
width: 20px;
}""")
splash.show()
timer = QElapsedTimer()
timer.start()
time.sleep(1)
for c in range(20):
progress_bar.setValue(c)
t = time.time()
while time.time() < t + 0.3:
app.processEvents()
time.sleep(1)
splash.close()
# MAIN BLOCK
if __name__ == "__main__":
# Configuration
conf = ConfFromFile()
conf.startup_path = str(os.path.expanduser("~"))+"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
conf.check()
# GUI setting up
app = QApplication([])
screen_resolution = app.desktop().screenGeometry()
# GUI style
stylesheet = open("res/MaterialDark.qss").read()
stylesheet = stylesheet.replace("color_hover", "#04B97F")
stylesheet = stylesheet.replace("color_main", "#252323")
stylesheet = stylesheet.replace("color_label", "#EDEBE1")
app.setStyleSheet(stylesheet)
# MVC setup
listener = leap_listener()
listener.configuration = conf
leap_controller = Leap.Controller()
leap_controller.add_listener(listener)
leap_controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES) # keeping Leap Motion working from background
show_splash_screen()
main_window = gui.MainWindow()
main_window.listener = listener
controller = Controller(main_window, listener, conf)
main_window.initUI()
listener.view = main_window
gv.pcr = PCRecognizer()
init_thread()
main_window._print("SYSTEM started")
main_window._print("sys platform: " + str(sys.platform))
app.exec_()