-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
355 lines (284 loc) · 11.5 KB
/
main.py
File metadata and controls
355 lines (284 loc) · 11.5 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
import customtkinter
import json
import uuid
import socket
import pymongo
from dotenv import load_dotenv
import os
from script.gesture_control import GestureControl
import threading
from script.modules.GestureAnimation import GestureAnimation
load_dotenv()
def get_unique_id():
mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
hostname = socket.gethostname()
return f"{mac}-{hostname}"
ges_con = GestureControl(True)
ges_con_thread = threading.Thread(target=ges_con.run)
unique_id = get_unique_id()
print(unique_id)
client = pymongo.MongoClient(os.getenv("MONGODB.URI"))
db = client["hci"]
collection = db["user-config"]
customGestureJson = collection.find_one({"_id": unique_id})
f = open("resources\\appList.json", "r")
data = json.load(f)
f = open("resources\\anim_data.json", "r")
anim_data = json.load(f)
if customGestureJson == None:
collection.insert_one(
{
"_id": unique_id,
"name": socket.gethostname(),
"userDefinedControls": {
"index": "null",
"index and middle": "null",
"index, middle and ring": "null",
"index, middle, ring and little": "null",
"thumb": "null",
},
}
)
customGestureJson = collection.find_one({"_id": unique_id})
with open("./script/modules/user_defined_data.json", "w") as f:
json.dump(customGestureJson, f)
app = customtkinter.CTk()
app.title("Gesture Navigator")
app.geometry("600x500")
app.iconbitmap("resources\\dark.ico")
# system mode
customtkinter.set_appearance_mode("system")
# Create two frames for the screens
menuFrame = customtkinter.CTkFrame(app, corner_radius=25, border_width=5)
customiseFrame = customtkinter.CTkFrame(app)
tutorialFrame = customtkinter.CTkFrame(app)
def getAppNames():
# read a file appList.json and fetch names
# return the list of app names
ls = ["Select"]
for i in data:
ls.append(i["displayName"])
return ls
# Function to switch to the second screen
def goToCustomise():
menuFrame.pack_forget()
customiseFrame.pack(fill="both", expand=True)
# Function to switch to the third screen
def goToTutorial():
menuFrame.pack_forget()
tutorialFrame.pack(fill="both", expand=True)
# Function to run python script
def launchGestureControl():
if not ges_con_thread.is_alive():
ges_con.runFlag = True
ges_con_thread.start()
else :
print("The program is already running. Please wait")
# Function to switch back to the first screen
def backToMenuFrame():
customiseFrame.pack_forget()
tutorialFrame.pack_forget()
menuFrame.pack(fill="both", expand=True, pady=60, padx=90)
# Function to print "Hello, World!"
def print_hello_world(varName):
print("Hello, World!", varName)
def saveGestures(data):
userDefinedControls = {}
userDefinedControls["index"] = (
gesture1_dropdown.get() if gesture1_dropdown.get() != "Select" else "null"
)
userDefinedControls["index and middle"] = (
gesture2_dropdown.get() if gesture2_dropdown.get() != "Select" else "null"
)
userDefinedControls["index, middle and ring"] = (
gesture3_dropdown.get() if gesture3_dropdown.get() != "Select" else "null"
)
userDefinedControls["index, middle, ring and little"] = (
gesture4_dropdown.get() if gesture4_dropdown.get() != "Select" else "null"
)
userDefinedControls["thumb"] = (
gesture5_dropdown.get() if gesture5_dropdown.get() != "Select" else "null"
)
for i in data:
if i["displayName"] == userDefinedControls["index"]:
userDefinedControls["index"] = i["shellName"]
if i["displayName"] == userDefinedControls["index and middle"]:
userDefinedControls["index and middle"] = i["shellName"]
if i["displayName"] == userDefinedControls["index, middle and ring"]:
userDefinedControls["index, middle and ring"] = i["shellName"]
if i["displayName"] == userDefinedControls["index, middle, ring and little"]:
userDefinedControls["index, middle, ring and little"] = i["shellName"]
if i["displayName"] == userDefinedControls["thumb"]:
userDefinedControls["thumb"] = i["shellName"]
if customGestureJson is not None:
customGestureJson["userDefinedControls"] = userDefinedControls
collection.update_one({"_id": unique_id}, {"$set": customGestureJson})
with open("./script/modules/user_defined_data.json", "w") as f:
json.dump(customGestureJson, f)
############################################################################################################
# First screen
menuFrame.pack(fill="both", expand=True, pady=60, padx=90)
launchButton = customtkinter.CTkButton(
menuFrame,
text="Launch program",
command=lambda: launchGestureControl(),
)
launchButton.pack(pady=50)
customiseButton = customtkinter.CTkButton(
menuFrame, text="Customise gestures", command=lambda: threading.Thread(target=goToCustomise).start()
)
customiseButton.pack(pady=30)
tutorialButton = customtkinter.CTkButton(
menuFrame, text="Tutorial", command=lambda: goToTutorial()
)
tutorialButton.pack(pady=50)
############################################################################################################
# Second screen
customiseDesc = customtkinter.CTkLabel(
customiseFrame, text="Customise your gestures here"
)
customiseDesc.pack(pady=5)
customiseDesc2 = customtkinter.CTkLabel(
customiseFrame,
text="You have five available gestures to customise which\ncan launch an app from the given list of apps.",
)
customiseDesc2.pack(pady=5)
# Five drop down lists should be there
# Gesture 1
gesture1_frame = customtkinter.CTkFrame(customiseFrame)
gesture1_frame.pack(fill="both", pady=5, ipadx=80, padx=50, ipady=10)
gesture1_label = customtkinter.CTkLabel(gesture1_frame, text="Gesture 1")
gesture1_label.pack(side="left", pady=5, padx=80)
gesture1_dropdown = customtkinter.CTkComboBox(gesture1_frame, values=getAppNames())
gesture1_dropdown.pack(side="left", pady=5, padx=30)
if customGestureJson is not None:
for i in data:
if i["shellName"] == customGestureJson["userDefinedControls"]["index"]:
gesture1_dropdown.set(i["displayName"])
gesture1_frame.pack_configure(anchor="center")
# Gesture 2
gesture2_frame = customtkinter.CTkFrame(customiseFrame)
gesture2_frame.pack(fill="both", pady=5, ipadx=80, padx=50, ipady=10)
gesture2_label = customtkinter.CTkLabel(gesture2_frame, text="Gesture 2")
gesture2_label.pack(side="left", pady=5, padx=80)
gesture2_dropdown = customtkinter.CTkComboBox(gesture2_frame, values=getAppNames())
gesture2_dropdown.pack(side="left", pady=5, padx=30)
if customGestureJson is not None:
for i in data:
if (
i["shellName"]
== customGestureJson["userDefinedControls"]["index and middle"]
):
gesture2_dropdown.set(i["displayName"])
gesture2_frame.pack_configure(anchor="center")
# Gesture 3
gesture3_frame = customtkinter.CTkFrame(customiseFrame)
gesture3_frame.pack(fill="both", pady=5, ipadx=80, padx=50, ipady=10)
gesture3_label = customtkinter.CTkLabel(gesture3_frame, text="Gesture 3")
gesture3_label.pack(side="left", pady=5, padx=80)
gesture3_dropdown = customtkinter.CTkComboBox(gesture3_frame, values=getAppNames())
gesture3_dropdown.pack(side="left", pady=5, padx=30)
if customGestureJson is not None:
for i in data:
if (
i["shellName"]
== customGestureJson["userDefinedControls"]["index, middle and ring"]
):
gesture3_dropdown.set(i["displayName"])
gesture3_frame.pack_configure(anchor="center")
# Gesture 4
gesture4_frame = customtkinter.CTkFrame(customiseFrame)
gesture4_frame.pack(fill="both", pady=5, ipadx=80, padx=50, ipady=10)
gesture4_label = customtkinter.CTkLabel(gesture4_frame, text="Gesture 4")
gesture4_label.pack(side="left", pady=5, padx=80)
gesture4_dropdown = customtkinter.CTkComboBox(gesture4_frame, values=getAppNames())
gesture4_dropdown.pack(side="left", pady=5, padx=30)
if customGestureJson is not None:
for i in data:
if (
i["shellName"]
== customGestureJson["userDefinedControls"][
"index, middle, ring and little"
]
):
gesture4_dropdown.set(i["displayName"])
gesture4_frame.pack_configure(anchor="center")
# Gesture 5
gesture5_frame = customtkinter.CTkFrame(customiseFrame)
gesture5_frame.pack(fill="both", pady=5, ipadx=80, padx=50, ipady=10)
gesture5_label = customtkinter.CTkLabel(gesture5_frame, text="Gesture 5")
gesture5_label.pack(side="left", pady=5, padx=80)
gesture5_dropdown = customtkinter.CTkComboBox(gesture5_frame, values=getAppNames())
gesture5_dropdown.pack(side="left", pady=5, padx=30)
if customGestureJson is not None:
for i in data:
if i["shellName"] == customGestureJson["userDefinedControls"]["thumb"]:
gesture5_dropdown.set(i["displayName"])
gesture5_frame.pack_configure(anchor="center")
# button to save gestures
saveButton = customtkinter.CTkButton(
customiseFrame, text="Save", command=lambda: saveGestures(data)
)
saveButton.pack_configure(anchor="center", pady=20)
backToMainMenu = customtkinter.CTkButton(
customiseFrame, text="Back", command=lambda: backToMenuFrame()
)
backToMainMenu.pack_configure(anchor="center", pady=0)
############################################################################################################
# Third Screen
# Third screen is for the user to view tutorial
# Create a dropdown list
options = list(anim_data.keys())
selected_option = customtkinter.StringVar()
dropdown = customtkinter.CTkComboBox(
tutorialFrame, values=options, variable=selected_option
)
dropdown.set(options[0])
dropdown.pack(pady=20)
# Create a frame for the GIFs
gif_frame = customtkinter.CTkFrame(tutorialFrame)
gif_frame.pack(ipady=20, ipadx=20)
# Specify the hands for the GIFs, these should be displayed side by side above the GIFs
left_hand = customtkinter.CTkLabel(gif_frame, text="Left Hand")
left_hand.grid(row=0, column=0, padx=30, pady=10)
right_hand = customtkinter.CTkLabel(gif_frame, text="Right Hand")
right_hand.grid(row=0, column=1, pady=10)
# Create labels for the GIFs
left_gif_label = GestureAnimation(gif_frame, "left", "animations\\1.gif")
right_gif_label = GestureAnimation(gif_frame, "right", "animations\\2.gif")
# Create a frame for the heading and description
description_frame = customtkinter.CTkFrame(
tutorialFrame, width=400, height=200, corner_radius=25, border_width=5
)
description_frame.pack(ipady=5, pady=10)
# Create the heading
heading = customtkinter.CTkLabel(
description_frame, text="Description", font=("Arial", 16, "bold")
)
heading.pack(pady=10)
# Create the description text
description_label = customtkinter.CTkLabel(
description_frame, text=anim_data[options[0]]["description"], wraplength=500
)
description_label.pack(pady=5, padx=20)
# Function to update the GIFs based on the selected option
def update_gifs(*_):
try:
option = selected_option.get()
description_label.configure(text=anim_data[option]["description"])
left_gif_label.update_gif(anim_data[option]["left"])
right_gif_label.update_gif(anim_data[option]["right"])
except Exception as e:
pass
# Bind the update_gifs function to the dropdown selection
selected_option.trace_add("write", update_gifs)
# Create a button to go back to the main menu
back_button = customtkinter.CTkButton(
tutorialFrame, text="Back", command=backToMenuFrame
)
back_button.pack()
app.mainloop()
# To be executed when the app is closed
ges_con.runFlag = False
ges_con_thread.join()
client.close()