-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.py
More file actions
80 lines (69 loc) · 2.9 KB
/
frontend.py
File metadata and controls
80 lines (69 loc) · 2.9 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
from tkinter import ttk
import subprocess
import time
class ScrcpyApp:
def __init__(self,master):
self.master = master
master.title("Scrcpy WebCam Controller")
master.geometry("560x390")
master.protocol("WM_DELETE_WINDOW", self.on_close)
self.create_window()
self.process = None
def create_window(self):
main_frame = ttk.Frame(self.master)
main_frame.pack(expand=True, fill='both')
status_frame = ttk.Frame(main_frame)
status_frame.pack(side='top', fill='x', padx=10, pady=10)
self.status_label = ttk.Label(status_frame, text="Status: Idle", font=("Arial", 12))
self.status_label.pack(side='left')
button_frame = ttk.Frame(main_frame)
button_frame.pack(side='bottom', fill='both', expand=True)
button_frame.columnconfigure((0, 1), weight=1)
button_frame.rowconfigure((0, 1), weight=1)
self.front_camera_btn = ttk.Button(button_frame, text="Front Camera", command=self.front_camera,style="Camera.TButton")
self.back_camera_btn = ttk.Button(button_frame, text="Back Camera", command=self.back_camera,style="Camera.TButton")
self.stop_btn = ttk.Button(button_frame, text="Stop", command=self.stop_camera,style="Camera.TButton")
style = ttk.Style()
style.configure("Camera.TButton", font=("Arial", 18, "bold"))
self.front_camera_btn.grid(row=0, column=0, sticky='nsew', padx=3, pady=3)
self.back_camera_btn.grid(row=0, column=1, sticky='nsew', padx=3, pady=3)
self.stop_btn.grid(row=1, column=0, columnspan=2, sticky='nsew', padx=3, pady=3)
def run_scrcpy(self, camera):
self.stop_camera()
command = [
"scrcpy",
"--video-source=camera",
"--no-window",
"--no-audio",
f"--camera-facing={camera}",
"--v4l2-sink=/dev/video5",
"--video-codec=h264",
"--max-size=1280",
]
self.process = subprocess.Popen(command)
self.current_camera = camera
self.update_status(f"{camera.capitalize()} Camera Active")
def front_camera(self):
print("Front Camera activated")
self.run_scrcpy("front")
def back_camera(self):
print("Back Camera activated")
self.run_scrcpy("back")
def stop_camera(self):
if self.process:
try:
self.process.terminate()
print("Camera stopped")
except subprocess.TimeoutExpired:
self.process.kill()
finally:
self.process = None
self.current_camera = None
self.update_status("Idle")
def update_status(self, status):
self.status_label.config(text=f"Status: {status}")
def on_close(self):
self.update_status("Closing...")
self.stop_camera()
time.sleep(0.5)
self.master.destroy()