-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
168 lines (133 loc) · 6.27 KB
/
interface.py
File metadata and controls
168 lines (133 loc) · 6.27 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
163
164
165
166
167
168
import datetime
import os
import time
import tkinter
from tkinter import Label, Tk, Button
import cv2
from PIL import Image, ImageTk
import capture
import config
import custom_ui
import main
import vlc_handler
WIN_WIDTH = 1240
WIN_HEIGHT = 600
BG = "#202331"
ACCENT = "#303754"
ui = None
conf = config.load_config()
rec_sec = conf["rec_sec"]
sensibility = conf["sensibility"]
s_map = {"Low": 20, "Medium": 10, "High": 2}
class Interface:
def create_window(self):
self.win = Tk()
self.win.geometry(f"{WIN_WIDTH}x{WIN_HEIGHT}")
self.win.config(bg=BG)
self.win.resizable(False, False)
self.win.title("Security Camera Interface")
self.win.protocol("WM_DELETE_WINDOW", self.stop_capture)
capture.main_ui = self
def stop_capture(self):
capture.set_stop_thread_event()
time.sleep(0.2)
if capture.thread is not None:
capture.thread.join()
self.win.destroy()
def schedule_frame_update(self):
if self.frame_buffer:
self.update_frame(self.frame_buffer[0])
self.frame_buffer = []
self.win.after(33, self.schedule_frame_update)
def toggle_stream(self):
self.is_paused = not self.is_paused
if self.is_paused is True:
self.pause_stream_button.config(text="Resume")
else:
self.pause_stream_button.config(text="Pause")
def update_frame(self, im=None):
if self.frame_label is not None and im is not None:
self.image_file = ImageTk.PhotoImage(Image.fromarray(cv2.cvtColor(im, cv2.COLOR_BGR2RGB)))
self.frame_label.config(image=self.image_file)
def __init__(self):
self.win = None
self.frame_buffer = []
self.is_paused = False
self.create_window()
self.frame_container = custom_ui.CustomLabelFrame(self.win, width=900, height=WIN_HEIGHT - 30, bg=BG,
fill=ACCENT)
self.frame_container.canvas.place(x=15, y=15)
self.frame_label = Label(self.frame_container.canvas, bg=ACCENT, fg="white",
text="Loading camera feed...", font=custom_ui.JET_FONT)
self.frame_label.place(x=10, y=10)
self.pause_stream_button = Button(self.frame_container.canvas, text="Pause", bg=ACCENT, fg="white", width=15,
command=self.toggle_stream)
self.pause_stream_button.place(x=20, y=500)
global ui
ui = self
self.create_rec_sec_dropdown()
self.create_precision_dropdown()
self.create_history()
# capture.run_capture_on_thread()
self.win.after(32, self.schedule_frame_update)
self.win.mainloop()
def create_rec_sec_dropdown(self):
options = ["2", "5", "10"]
selected_option = tkinter.StringVar()
selected_option.set(str(rec_sec))
def on_option_change(selection):
global rec_sec
if int(selection) != rec_sec:
rec_sec = int(selection)
config.save_config(config.Settings(rec_sec=rec_sec, sensibility=sensibility))
self.rec_sec_option_menu = tkinter.OptionMenu(self.frame_container.canvas, selected_option, *options,
command=on_option_change)
self.rec_sec_option_menu.config(width=2, highlightbackground=BG)
self.rec_sec_option_menu.place(x=870 - self.rec_sec_option_menu.winfo_reqwidth() - 20, y=15)
self.rec_sec_label = Label(self.frame_container.canvas, text="Recording seconds:", bg=ACCENT, fg="white",
justify="left")
self.rec_sec_label.place(x=670, y=18)
def create_precision_dropdown(self):
options = ["Low", "Medium", "High"]
selected_option = tkinter.StringVar()
selected_option.set([key for key, value in s_map.items() if value == sensibility])
def on_option_change(selection):
global sensibility
if selection != sensibility:
sensibility = s_map[selection]
config.save_config(config.Settings(rec_sec=rec_sec, sensibility=sensibility))
self.sensibility_option_menu = tkinter.OptionMenu(self.frame_container.canvas, selected_option, *options,
command=on_option_change)
self.sensibility_option_menu.config(width=8, highlightbackground=BG)
self.sensibility_option_menu.place(x=870 - self.rec_sec_option_menu.winfo_reqwidth() - 20, y=55)
self.sensibility_label = Label(self.frame_container.canvas, text="Sensibility:", bg=ACCENT, fg="white",
justify="left")
self.sensibility_label.place(x=670, y=58)
def create_history(self):
self.history_container = custom_ui.CustomLabelFrame(self.win, width=300, height=WIN_HEIGHT - 30, bg=BG,
fill=ACCENT, text="History")
self.history_container.canvas.place(x=925, y=15)
self.folders, self.folder_files = capture.get_history_list()
self.folder_labels_list = []
for i in range(len(self.folders)):
if self.folder_files[i] is not None:
# print("\n", self.folders[i])
self.folder_labels_list.append(
Label(self.history_container.canvas, text=str(self.folders[i]), bg=ACCENT, fg="white"))
full_files_path = [
f"{os.path.abspath(capture.output_path)}\\{self.folders[i]}\\{file}" for file
in
self.folder_files[i]]
print(full_files_path)
self.folder_labels_list[-1].bind("<Button-1>",
lambda event, files=full_files_path: self.play_vlc_playlist(
files))
# for file in self.folder_files[i]:
# print(f" └{file}")
else:
print(self.folders[i])
for i in range(0, len(self.folder_labels_list)):
self.folder_labels_list[i].place(x=10, y=i * 25 + 30)
print(str(i * 20 + 30))
def play_vlc_playlist(self, playlist):
vlc_handler.open_video(playlist)