-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_Manager.py
More file actions
163 lines (146 loc) · 7.31 KB
/
GUI_Manager.py
File metadata and controls
163 lines (146 loc) · 7.31 KB
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
import cv2
import time
import os
import subprocess
import glob
import webbrowser
from PreventionDetectors import PreventionDetectors
class GUI_Manager:
@staticmethod
def buttons_listener(video, window, values, event, log_name_file, sound_enabled, input_choice_backup, initialization_time):
# INPUT BUTTONS
if event == 'sv':
window['invalid_url_text'].hide_row()
window['invalid_url_text'].Update(visible=False)
window['sv'].Update(disabled=True)
window['wc'].Update(disabled=True)
window['ip'].Update(disabled=True)
video = cv2.VideoCapture('resources/Initialization.mp4')
input_choice_backup = 'sv'
initialization_time = time.time()
elif event == 'wc':
window['invalid_url_text'].hide_row()
window['invalid_url_text'].Update(visible=False)
window['sv'].Update(disabled=True)
window['wc'].Update(disabled=True)
window['ip'].Update(disabled=True)
video = cv2.VideoCapture('resources/Initialization.mp4')
input_choice_backup = 'wc'
initialization_time = time.time()
elif event == 'ip':
window['invalid_url_text'].hide_row()
window['invalid_url_text'].Update(visible=False)
window['sv'].Update(disabled=True)
window['wc'].Update(disabled=True)
window['ip'].Update(disabled=True)
window['text_url_stream'].unhide_row()
window['url_stream'].unhide_row()
window['ok'].unhide_row()
window['text_url_stream'].Update(visible=True)
window['url_stream'].Update(visible=True)
window['ok'].Update(visible=True)
elif event == 'ok':
window['sv'].Update(disabled=True)
window['wc'].Update(disabled=True)
window['ip'].Update(disabled=True)
window['text_url_stream'].Update(visible=False)
window['url_stream'].Update(visible=False)
window['ok'].Update(visible=False)
window['text_url_stream'].hide_row()
window['url_stream'].hide_row()
window['ok'].hide_row()
video = cv2.VideoCapture('resources/Initialization.mp4')
input_choice_backup = 'ok'
initialization_time = time.time()
if initialization_time != None and time.time() - initialization_time >= 5:
window['sv'].Update(disabled=False)
window['wc'].Update(disabled=False)
window['ip'].Update(disabled=False)
PreventionDetectors.reset()
if input_choice_backup == 'sv':
video = cv2.VideoCapture('video/test_video2.mp4')
log_name_file = time.ctime()
file = open("output/" + log_name_file + ".txt", "w+")
file.write("INPUT TYPE: Sample video\n\n")
file.close()
elif input_choice_backup == 'wc':
video = cv2.VideoCapture(0)
log_name_file = time.ctime()
file = open("output/" + log_name_file + ".txt", "w+")
file.write("INPUT TYPE: WebCam\n\n")
file.close()
elif input_choice_backup == 'ok':
video = cv2.VideoCapture(values['url_stream'])
if not video.isOpened():
window['invalid_url_text'].unhide_row()
window['invalid_url_text'].Update(visible=True)
video = cv2.VideoCapture('resources/TryAgain.mp4')
else:
log_name_file = time.ctime()
file = open("output/" + log_name_file + ".txt", "w+")
file.write("INPUT TYPE: IPCam (URL: " + values['url_stream'] + ")\n\n")
file.close()
initialization_time = None
# LOG BUTTONS
if event == 'open_logs_folder':
try:
os.startfile('output/') # To open a directory in Windows systems
except:
subprocess.Popen(['xdg-open', 'output/']) # To open a directory in Unix systems
elif event == 'clear_logs_folder':
files = glob.glob('output/*')
for f in files:
os.remove(f)
# SOUND BUTTON
if event == 'sound_button' and sound_enabled:
window['sound_button'].Update(image_filename='resources/sound_off_60x60.png', image_size=(60, 60), image_subsample=1)
sound_enabled = False
elif event == 'sound_button' and not sound_enabled:
window['sound_button'].Update(image_filename='resources/sound_on_60x60.png', image_size=(60, 60), image_subsample=1)
sound_enabled = True
# GITHUB BUTTON
if event == 'github_button':
webbrowser.open('https://github.com/DavidG33k/')
return video, log_name_file, sound_enabled, input_choice_backup, initialization_time
@staticmethod
def responsive_gui(window, values, event):
if event == 'detect_people':
if values['detect_people']:
window['show_people_ID'].Update(disabled=False)
window['shows_confidence_percentage'].Update(disabled=False)
window['show_tracking_line'].Update(disabled=False)
window['MIN_CONFIDENCE'].Update(disabled=False)
window['detect_gathering'].Update(disabled=False)
window['detect_social_distancing'].Update(disabled=False)
window['report_people_limit'].Update(disabled=False)
if values['detect_gathering'] or values['detect_social_distancing']:
window['MIN_DISTANCE'].Update(disabled=False)
if values['report_people_limit']:
window['MAX_PERSONS'].Widget['state'] = 'normal'
if values['detect_gathering']:
window['TIME_LIMIT'].Widget['state'] = 'normal'
else:
window['show_people_ID'].Update(disabled=True)
window['shows_confidence_percentage'].Update(disabled=True)
window['show_tracking_line'].Update(disabled=True)
window['MIN_CONFIDENCE'].Update(disabled=True)
window['detect_gathering'].Update(disabled=True)
window['detect_social_distancing'].Update(disabled=True)
window['report_people_limit'].Update(disabled=True)
window['MIN_DISTANCE'].Update(disabled=True)
window['MAX_PERSONS'].Widget['state'] = 'disabled'
window['TIME_LIMIT'].Widget['state'] = 'disabled'
elif event == 'report_people_limit':
if values['report_people_limit']:
window['MAX_PERSONS'].Widget['state'] = 'normal'
elif not values['report_people_limit']:
window['MAX_PERSONS'].Widget['state'] = 'disabled'
elif event == 'detect_gathering' or event == 'detect_social_distancing':
if values['detect_gathering']:
window['TIME_LIMIT'].Widget['state'] = 'normal'
else:
window['TIME_LIMIT'].Widget['state'] = 'disabled'
if values['detect_gathering'] or values['detect_social_distancing']:
window['MIN_DISTANCE'].Update(disabled=False)
else:
window['MIN_DISTANCE'].Update(disabled=True)