-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
60 lines (51 loc) · 2.07 KB
/
Copy pathjarvis.py
File metadata and controls
60 lines (51 loc) · 2.07 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
from ui import start_ui
import threading
import sys
from internet_check import is_Online
from Alert import Alert
from Data.DLG_Data import online_dlg,offline_dlg
import random
from co_brain import Jarvis
from TextToSpeech.Fast_DF_TTS import speak
from Automation.Battery import check_plug
from Time_Operations.throw_alert import check_schedule,check_Alam
from os import getcwd
Alam_path = f"{getcwd()}\\Alam_data.txt"
file_path = f'{getcwd()}\\schedule.txt'
ran_online_dlg = random.choice(online_dlg)
ran_offline_dlg = random.choice(offline_dlg)
def main():
if is_Online():
try:
# Initialize all threads
t1 = threading.Thread(target=speak, args=(ran_online_dlg,), name="SpeechThread")
t3 = threading.Thread(target=check_plug, name="BatteryThread")
t4 = threading.Thread(target=check_schedule, args=(file_path,), name="ScheduleThread")
t5 = threading.Thread(target=Jarvis, name="JarvisThread")
t6 = threading.Thread(target=check_Alam, args=(Alam_path,), name="AlarmThread")
# Start all threads
threads = [t1, t3, t4, t5, t6]
for t in threads:
t.daemon = True # Make threads daemon so they exit when main program exits
print(f"Starting thread: {t.name}")
t.start()
# Optional: Wait for speech to complete before continuing
t1.join()
# Let other threads run independently
# Only join non-daemon threads if you need to wait for them
# for t in [t3, t4, t5, t6]:
# t.join()
except Exception as e:
print(f"Error in main thread: {e}")
else:
Alert(ran_offline_dlg)
if __name__ == "__main__":
try:
app, ui = start_ui()
# Run the main Jarvis function in a separate thread
main_thread = threading.Thread(target=main, daemon=True, name="MainThread")
main_thread.start()
# Start the UI event loop
sys.exit(app.exec_())
except Exception as e:
print(f"Error starting application: {e}")