-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
79 lines (64 loc) · 2.69 KB
/
controller.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
import tkinter as tk
from tkinter import messagebox
from hand_control import HandTrackingController
from keyboard_control import KeyboardController
import popup_box
import sys
# Import Custom Functions
import find_ip
# Bot's IP
esp_ip = None
class ControlGUI:
def __init__(self, esp_ip):
self.root = tk.Tk()
self.root.title("Bot Control")
self.hand_tracking_controller = HandTrackingController(esp_ip)
self.keyboard_controller = KeyboardController(esp_ip)
self.create_widgets()
def create_widgets(self):
# Frame for buttons
button_frame = tk.Frame(self.root)
button_frame.pack(pady=10)
self.root.geometry("350x150")
# Create a frame inside the root window
self.main_frame = tk.Frame(self.root)
self.main_frame.pack(fill=tk.BOTH, expand=True)
# Hand Gesture Control Button
hand_icon = tk.PhotoImage(file="Assets/gesturecontrol.png")
hand_icon = hand_icon.subsample(2)
self.hand_control_button = tk.Button(button_frame, image=hand_icon, command=self.start_hand_control, borderwidth=2, relief="solid")
self.hand_control_button.image = hand_icon
self.hand_control_button.pack(side=tk.LEFT, padx=5)
# Keyboard Control Button
keyboard_icon = tk.PhotoImage(file="Assets/keyboard.png")
keyboard_icon = keyboard_icon.subsample(2)
self.keyboard_control_button = tk.Button(button_frame, image=keyboard_icon, command=self.start_keyboard_control, borderwidth=2, relief="solid")
self.keyboard_control_button.image = keyboard_icon
self.keyboard_control_button.pack(side=tk.LEFT, padx=5)
# Quit Button
self.quit_button = tk.Button(self.root, text="Quit", command=self.quit_program)
self.quit_button.pack(pady=5)
def start_hand_control(self):
self.hand_tracking_controller.run(True)
self.keyboard_controller.run(False)
def start_keyboard_control(self):
self.hand_tracking_controller.run(False)
self.keyboard_controller.run(True)
def quit_program(self):
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.hand_tracking_controller.stop_gesture_tracking()
self.root.destroy()
if __name__ == "__main__":
# If Arguments given
if len(sys.argv) > 1:
esp_ip = sys.argv[1]
else:
# IF bot is connected to the laptops Hotspot, Automatic Search
esp_ip = find_ip.find_device_ip("48:55:19:f6:57:34")
if esp_ip is None:
print("Bot was not found. Exiting ....")
exit()
# ESP address
popup_box.popup()
app = ControlGUI(f"ws://{esp_ip}:8080/")
app.root.mainloop()