-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
359 lines (308 loc) · 16.7 KB
/
Copy pathapp.py
File metadata and controls
359 lines (308 loc) · 16.7 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
356
357
358
359
"""
Laptop Control Assistant — Modern Dark UI
Run: python app.py
"""
import tkinter as tk
from tkinter import ttk
import threading
import time
import main as engine # import the backend
# ═══════════════════════════════════════════════════════
# COLORS & THEME
# ═══════════════════════════════════════════════════════
BG = "#1a1a2e"
BG_DARK = "#16213e"
BG_CARD = "#0f3460"
BG_INPUT = "#1f2940"
ACCENT = "#e94560"
ACCENT_HOVER= "#ff6b81"
TEXT = "#eaeaea"
TEXT_DIM = "#8899aa"
TEXT_USER = "#53d8fb"
TEXT_BOT = "#a8e6cf"
TEXT_ERR = "#ff6b6b"
BORDER = "#2a3a5c"
SUCCESS = "#00d26a"
FONT = ("Segoe UI", 11)
FONT_BOLD = ("Segoe UI", 11, "bold")
FONT_TITLE = ("Segoe UI", 16, "bold")
FONT_SMALL = ("Segoe UI", 9)
FONT_CHAT = ("Consolas", 11)
FONT_BTN = ("Segoe UI", 9, "bold")
class LaptopAssistantApp:
def __init__(self, root):
self.root = root
self.root.title("Laptop Control Assistant")
self.root.geometry("1050x720")
self.root.minsize(800, 550)
self.root.configure(bg=BG)
# Try to set icon (ignore if fails)
try:
self.root.iconbitmap(default="")
except:
pass
self.model_loaded = False
self._build_ui()
self._add_welcome()
# Load model in background
threading.Thread(target=self._load_model_bg, daemon=True).start()
# ───────────────────────────────────────────────
# BUILD UI
# ───────────────────────────────────────────────
def _build_ui(self):
# ── Title bar ──
title_frame = tk.Frame(self.root, bg=BG_DARK, height=50)
title_frame.pack(fill=tk.X)
title_frame.pack_propagate(False)
tk.Label(title_frame, text="⚡", font=("Segoe UI", 20), bg=BG_DARK, fg=ACCENT).pack(side=tk.LEFT, padx=(15, 5))
tk.Label(title_frame, text="Laptop Control Assistant", font=FONT_TITLE, bg=BG_DARK, fg=TEXT).pack(side=tk.LEFT)
self.status_label = tk.Label(title_frame, text="⏳ Loading AI model...", font=FONT_SMALL, bg=BG_DARK, fg=TEXT_DIM)
self.status_label.pack(side=tk.RIGHT, padx=15)
# ── Main area (chat + sidebar) ──
main_frame = tk.Frame(self.root, bg=BG)
main_frame.pack(fill=tk.BOTH, expand=True, padx=0, pady=0)
# ── Sidebar (quick actions) — scrollable ──
sidebar_outer = tk.Frame(main_frame, bg=BG_DARK, width=210)
sidebar_outer.pack(side=tk.RIGHT, fill=tk.Y, padx=(1, 0))
sidebar_outer.pack_propagate(False)
tk.Label(sidebar_outer, text="Quick Actions", font=FONT_BOLD, bg=BG_DARK, fg=TEXT).pack(pady=(10, 4))
# Scrollable canvas for sidebar buttons
sidebar_canvas = tk.Canvas(sidebar_outer, bg=BG_DARK, highlightthickness=0, width=195)
sidebar_scroll = ttk.Scrollbar(sidebar_outer, orient=tk.VERTICAL, command=sidebar_canvas.yview)
sidebar_inner = tk.Frame(sidebar_canvas, bg=BG_DARK)
sidebar_inner.bind("<Configure>", lambda e: sidebar_canvas.configure(scrollregion=sidebar_canvas.bbox("all")))
sidebar_canvas.create_window((0, 0), window=sidebar_inner, anchor="nw")
sidebar_canvas.configure(yscrollcommand=sidebar_scroll.set)
sidebar_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
sidebar_scroll.pack(side=tk.RIGHT, fill=tk.Y)
# Mouse wheel scrolling
def _on_sidebar_mousewheel(event):
sidebar_canvas.yview_scroll(int(-1*(event.delta/120)), "units")
sidebar_canvas.bind_all("<MouseWheel>", _on_sidebar_mousewheel)
# Quick action buttons — organized by category
quick_actions = [
("⚡ Connectivity", None, True),
("Bluetooth ON", "turn on bluetooth"),
("Bluetooth OFF", "turn off bluetooth"),
("WiFi ON", "turn on wifi"),
("WiFi OFF", "turn off wifi"),
("Hotspot", "open hotspot settings"),
("Airplane Mode", "open airplane settings"),
("🔊 Audio & Media", None, True),
("Mute / Unmute", "mute"),
("Volume 50%", "set volume to 50"),
("Volume 100%", "set volume to 100"),
("⏯ Play/Pause", "play pause"),
("⏭ Next Track", "next track"),
("⏮ Prev Track", "previous track"),
("💡 Display", None, True),
("Brightness 30%", "brightness to 30"),
("Brightness 70%", "brightness to 70"),
("Dark Mode", "turn on dark mode"),
("Light Mode", "turn on light mode"),
("Night Light", "turn on night light"),
("🪟 Windows", None, True),
("Minimize All", "minimize all windows"),
("Restore All", "restore all windows"),
("Snap Left", "snap window left"),
("Snap Right", "snap window right"),
("New Desktop", "new virtual desktop"),
("Task View", "task view"),
("🖥️ System", None, True),
("Screenshot", "take a screenshot"),
("Lock Screen", "lock my laptop"),
("Sleep", "sleep my laptop"),
("Restart", "restart my laptop"),
("Cancel Shutdown", "cancel shutdown"),
("📊 Info", None, True),
("Battery Level", "battery level"),
("System Info", "system info"),
("CPU Usage", "cpu usage"),
("RAM Usage", "ram usage"),
("Disk Space", "disk space"),
("My IP Address", "my ip address"),
("Uptime", "uptime"),
("🔒 Security", None, True),
("Quick Virus Scan", "quick virus scan"),
("Windows Update", "check for updates"),
("Clear Temp Files", "clear temp files"),
("Disk Cleanup", "disk cleanup"),
("Empty Recycle Bin","empty recycle bin"),
("📂 Folders", None, True),
("Downloads", "open downloads"),
("Documents", "open documents"),
("Desktop", "open desktop"),
("File Explorer", "open file explorer"),
("🛠️ Tools", None, True),
("Task Manager", "open task manager"),
("Running Apps", "list running apps"),
("Emoji Panel", "open emoji panel"),
("On-Screen KB", "on-screen keyboard"),
("Speed Test", "speed test"),
("Date & Time", "what time is it"),
("Open Settings", "open settings"),
("⚡ Power", None, True),
("High Performance", "power plan high performance"),
("Power Saver", "power plan power saver"),
("Balanced", "power plan balanced"),
]
for item in quick_actions:
if len(item) == 3:
# Section header
tk.Label(sidebar_inner, text=item[0], font=FONT_SMALL, bg=BG_DARK, fg=TEXT_DIM).pack(
anchor=tk.W, padx=10, pady=(8, 2))
else:
label, cmd = item
btn = tk.Button(
sidebar_inner, text=label, font=FONT_BTN,
bg=BG_CARD, fg=TEXT, activebackground=ACCENT, activeforeground="white",
bd=0, relief=tk.FLAT, cursor="hand2", padx=8, pady=3,
command=lambda c=cmd: self._send_command(c)
)
btn.pack(fill=tk.X, padx=8, pady=1)
btn.bind("<Enter>", lambda e, b=btn: b.config(bg=ACCENT))
btn.bind("<Leave>", lambda e, b=btn: b.config(bg=BG_CARD))
# ── Chat area ──
chat_frame = tk.Frame(main_frame, bg=BG)
chat_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Chat display
self.chat_display = tk.Text(
chat_frame, wrap=tk.WORD, font=FONT_CHAT,
bg=BG, fg=TEXT, bd=0, padx=15, pady=10,
insertbackground=TEXT, selectbackground=ACCENT,
state=tk.DISABLED, cursor="arrow", spacing3=4
)
self.chat_display.pack(fill=tk.BOTH, expand=True, padx=(5, 0))
# Scrollbar
scrollbar = ttk.Scrollbar(self.chat_display, orient=tk.VERTICAL, command=self.chat_display.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.chat_display.config(yscrollcommand=scrollbar.set)
# Chat tags
self.chat_display.tag_config("user", foreground=TEXT_USER, font=("Consolas", 11, "bold"))
self.chat_display.tag_config("bot", foreground=TEXT_BOT)
self.chat_display.tag_config("action", foreground=SUCCESS)
self.chat_display.tag_config("error", foreground=TEXT_ERR)
self.chat_display.tag_config("dim", foreground=TEXT_DIM, font=("Consolas", 9))
self.chat_display.tag_config("welcome", foreground=TEXT_DIM, font=("Consolas", 10))
# ── Input area ──
input_frame = tk.Frame(self.root, bg=BG_DARK, height=55)
input_frame.pack(fill=tk.X, side=tk.BOTTOM)
input_frame.pack_propagate(False)
inner = tk.Frame(input_frame, bg=BG_DARK)
inner.pack(fill=tk.BOTH, expand=True, padx=12, pady=10)
self.input_var = tk.StringVar()
self.input_entry = tk.Entry(
inner, textvariable=self.input_var,
font=FONT, bg=BG_INPUT, fg=TEXT, bd=0,
insertbackground=TEXT, selectbackground=ACCENT,
relief=tk.FLAT
)
self.input_entry.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, ipady=6, padx=(5, 8))
self.input_entry.bind("<Return>", lambda e: self._on_send())
self.send_btn = tk.Button(
inner, text=" Send ▶ ", font=FONT_BOLD,
bg=ACCENT, fg="white", activebackground=ACCENT_HOVER,
bd=0, relief=tk.FLAT, cursor="hand2", padx=15,
command=self._on_send
)
self.send_btn.pack(side=tk.RIGHT)
self.send_btn.bind("<Enter>", lambda e: self.send_btn.config(bg=ACCENT_HOVER))
self.send_btn.bind("<Leave>", lambda e: self.send_btn.config(bg=ACCENT))
# Focus input
self.input_entry.focus_set()
# ───────────────────────────────────────────────
# WELCOME MESSAGE
# ───────────────────────────────────────────────
def _add_welcome(self):
self._append_chat(" ⚡ Laptop Control Assistant\n", "user")
self._append_chat(
" Control EVERYTHING on your laptop with plain English!\n\n"
" ⚡ Connectivity \"turn on bluetooth\" \"turn off wifi\" \"open hotspot\"\n"
" 🔊 Audio \"volume to 70\" \"mute\" \"next track\" \"play/pause\"\n"
" 💡 Display \"brightness 50\" \"dark mode\" \"night light\"\n"
" 🪟 Windows \"minimize all\" \"snap left\" \"new desktop\" \"task view\"\n"
" 🖥️ System \"screenshot\" \"lock\" \"sleep\" \"shutdown\" \"restart\"\n"
" 📊 Info \"battery level\" \"cpu usage\" \"ram usage\" \"disk space\"\n"
" 🌐 Network \"my ip\" \"speed test\" \"flush dns\" \"wifi password\"\n"
" 📂 Files \"open downloads\" \"empty recycle bin\" \"create folder\"\n"
" 🔒 Security \"virus scan\" \"update windows\" \"clear temp\"\n"
" 🛠️ Apps \"open chrome\" \"close notepad\" \"running apps\"\n"
" 🔍 Web \"search for AI news\" \"open youtube.com\"\n"
" ⚡ Power \"high performance\" \"power saver\" \"hibernate\"\n\n"
" Type anything or use the Quick Action buttons on the right →\n\n",
"welcome"
)
# ───────────────────────────────────────────────
# MODEL LOADING
# ───────────────────────────────────────────────
def _load_model_bg(self):
try:
engine.load_model()
self.model_loaded = True
self.root.after(0, lambda: self.status_label.config(text="✅ AI model ready", fg=SUCCESS))
except Exception as e:
self.root.after(0, lambda: self.status_label.config(text=f"⚠️ Model error: {e}", fg=TEXT_ERR))
# ───────────────────────────────────────────────
# SEND COMMAND
# ───────────────────────────────────────────────
def _on_send(self):
text = self.input_var.get().strip()
if not text:
return
self._send_command(text)
def _send_command(self, text):
self.input_var.set("")
self._append_chat(f" You ▶ {text}\n", "user")
self.input_entry.config(state=tk.DISABLED)
self.send_btn.config(state=tk.DISABLED, text=" ⏳... ")
self.status_label.config(text="⏳ Processing...", fg=TEXT_DIM)
# Run in background thread
threading.Thread(target=self._execute_bg, args=(text,), daemon=True).start()
def _execute_bg(self, text):
try:
responses = engine.process_command(text)
self.root.after(0, lambda: self._show_responses(responses))
except Exception as e:
self.root.after(0, lambda: self._show_responses([f" ❌ Error: {e}"]))
def _show_responses(self, responses):
for resp in responses:
if "->" in resp:
self._append_chat(f" ✅ {resp.strip()}\n", "action")
elif "[AI" in resp or "Thinking" in resp:
self._append_chat(f" {resp.strip()}\n", "dim")
elif "Error" in resp or "Unknown" in resp:
self._append_chat(f" {resp.strip()}\n", "error")
else:
self._append_chat(f" {resp.strip()}\n", "bot")
if not responses:
self._append_chat(" ⚠️ No response\n", "error")
self._append_chat("\n", "dim")
self.input_entry.config(state=tk.NORMAL)
self.send_btn.config(state=tk.NORMAL, text=" Send ▶ ")
self.status_label.config(text="✅ AI model ready" if self.model_loaded else "⏳ Loading AI model...",
fg=SUCCESS if self.model_loaded else TEXT_DIM)
self.input_entry.focus_set()
# ───────────────────────────────────────────────
# CHAT DISPLAY
# ───────────────────────────────────────────────
def _append_chat(self, text, tag=None):
self.chat_display.config(state=tk.NORMAL)
if tag:
self.chat_display.insert(tk.END, text, tag)
else:
self.chat_display.insert(tk.END, text)
self.chat_display.config(state=tk.DISABLED)
self.chat_display.see(tk.END)
# ═══════════════════════════════════════════════════════
# MAIN
# ═══════════════════════════════════════════════════════
if __name__ == "__main__":
root = tk.Tk()
# Style the scrollbar
style = ttk.Style()
style.theme_use("clam")
style.configure("Vertical.TScrollbar",
background=BG_CARD, troughcolor=BG,
bordercolor=BG, arrowcolor=TEXT_DIM)
app = LaptopAssistantApp(root)
root.mainloop()